FIX: Optimization Bug Using Shift Operators and outp()

Last reviewed: September 18, 1997
Article ID: Q119871
1.00 WINDOWS NT kbtool kbfixlist kbbuglist

The information in this article applies to:

  • The C/C++ Compiler (CL.EXE), included with

        - Microsoft Visual C++, 32-bit Edition, version 1.0
    

SYMPTOMS

Optimizing the shift operators may generate incorrect code when used in conjunction with outp(). In the sample code in the "MORE INFORMATION" section, below, no code is generated for the line "addr >>= 8;".

RESOLUTION

Disable optimization, or perform the shift operation directly in the argument list of the function outp().

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed above. This problem was corrected in Visual C++, 32-bit Edition, version 2.0.

MORE INFORMATION

When compiled with /Ox, the following sample does not generate code for the line "addr >>= 8;"

NOTE: When the line of code marked "3" replaces the lines marked "1" and "2", "mov al,ah" is no longer incorrectly optimized out of the assembler listing produced by /Fc.

Sample Code

// Compile options needed: /c /Ox /Fc

   unsigned long test(char * baseport, unsigned long addr)
   {
       unsigned long   offset;

       offset = ((addr >> 3) & 0x00003fff);

       addr >>= 8;                     //Line 1
       outp(baseport + 4, addr);       //Line 2

// Replacing the above two lines of code with the line below
// fixes the problem.

//       outp(baseport + 4, addr >> 8);  //Line 3--okay with /Ox.

       return offset;
   }


Additional reference words: 1.00 8.00
KBCategory: kbtool kbfixlist kbbuglist
KBSubCategory: CLIss
Keywords : kbbuglist kbfixlist kbtool
Version : 1.00
Platform : NT WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.