Microsoft KB Archive/113677

{|
 * width="100%"|

FIX: Bad Code Generated for 'loop' When Using Optimizations

 * }

Q113677

1.00 WINDOWS kbtool kbfixlist kbbuglist -- The information in this article applies to: - The Microsoft C/C++ Compiler (CL.EXE), included with: - Microsoft Visual C++ for Windows, version 1.0 -- SYMPTOMS ======== When you use the loop instruction in inline assembly and are enabling optimizations, the C/C++ compiler will generate incorrect code. When the code is run it will produce random run-time errors or possibly hang the machine. This problem can be reproduced by compiling and running the sample code shown below. RESOLUTION ========== To work around the problem, do one of the following: - Do not use optimization switches when compiling the module that contains the loop instruction. - Use the #pragma optimize directive around the function containing the loop instruction, as indicated in the sample code. - Remove the loop instruction and replace it with equivalent instructions, as indicated in the sample code. STATUS ====== Microsoft has confirmed this to be a problem in the Microsoft products listed above. This problem was corrected in Visual C++ version 1.5. Sample Code --- /* Compile options needed: any /O options (excluding /Od and /Oo-) */ #include #define COUNT 2 /* Uncomment this #pragma to turn off optimizations and correct the problem: #pragma optimize( "", off ) */ void main { __asm mov cx, COUNT mylabel: __asm { ; ; various assembly instructions ; loop mylabel ; remove the loop instruction above and uncomment ; the lines below to correct the problem ;dec cx ;jnz mylabel } printf( "Test was successful if no run-time error messages\n" ); printf( "were displayed!\n" ); } /* Uncomment this #pragma to turn optimizations back on: #pragma optimize( "", on ) */ Additional reference words: M6111 R6001 8.00 1.00 KBCategory: kbtool kbfixlist kbbuglist KBSubcategory: CLIss

Keywords : kb16bitonly kbCompiler

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCVCComp