BUG: /Oc Optimization Can Corrupt Stack With Inline Assembly

ID: Q115702

6.00 6.00a 7.00 | 1.00 1.50

MS-DOS           | WINDOWS
kbtool kbbuglist

The information in this article applies to:

SYMPTOMS

The use of the /Oc optimization (Enable Block-Common Subexpression Optimization) on inline assembly code which uses the stack may corrupt the stack. The source code below can be used to illustrate this problem.

RESOLUTION

There are two workarounds to this problem:

1. Use the fast compiler option /f if you are using the C/C++ version 7.0

   or later, or else use the /qc option if using earlier versions.

   -or-

2. Disable optimization during the function by using the optimize pragma:

      #pragma optimize("",off)

      void bad_function(void)
      {
      /* ... */ 
      }

      #pragma optimize("",on)

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed above. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

This is not a problem in Visual C++, 32-bit Edition.

MORE INFORMATION

The following code can be used to demonstrate this problem.

Sample Code

/* Compile options needed: /c /Oc
*/ 

void _cdecl b(int c,int d);

void    a(void)
{
_asm pushf _asm cli

       b(1,2);

_asm popf
        return;
}

Additional reference words: 6.00 6.00a 7.00 8.00 8.00c 1.00 1.50 KBCategory: kbtool kbbuglist KBSubcategory: CLIss Keywords : kb16bitonly

Last Reviewed: July 23, 1997