Microsoft KB Archive/115702

From BetaArchive Wiki

BUG: /Oc Optimization Can Corrupt Stack With Inline Assembly

Q115702

6.00 6.00a 7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist ---------------------------------------------------------------------- The information in this article applies to: - The Microsoft C/C++ Compiler (CL.EXE), included with: - Microsoft C for MS-DOS, versions 6.0, 6.0a, and 6.0ax - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 ---------------------------------------------------------------------- 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
Issue type : kbbug
Technology : kbVCsearch kbAudDeveloper kbCVCComp


Last Reviewed: May 5, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.