Visual C++ compiler bug with optimizations enabled; loop condition incorrectly optimized away - by wtbw

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 552249 Comments
Status Resolved Workarounds
Type Bug Repros 1
Opened 4/18/2010 12:13:03 PM
Access Restriction Public


When any form of optimization is enabled, assembly is incorrectly generated from the example C++ code, causing incorrect program behaviour (and in this case, a crash).

It appears that the compiler thinks that checking the loop condition is unnecessary.

With the printf included, you can clearly see that the loop is reentered with nc.pNode equal to 0, contradicting the condition in the line right above it!

Snipped sample of broken assembly:

push    esi                                    
push    offset format   ; "0x%lX\n"            
call    _printf   
mov     eax, [esi+4]                           
mov     esi, [esi+8]                           
add     esp, 8                                 
mov     [esp+18h+nc.a], eax                    
jmp     short loc_401010

Snipped sample of working assembly (built with optimizations disabled):
cmp     [ebp+var_4], 0
jz      short loc_40103B

mov     ecx, [ebp+var_4]
push    ecx
push    offset a0xLx    ; "0x%lX\n"
call    _printf

add     esp, 8
mov     edx, [ebp+var_4]
mov     eax, [edx+4]
mov     ecx, [edx+8]
mov     [ebp+var_8], eax
mov     [ebp+var_4], ecx
jmp     short loc_401013
Sign in to post a comment.
Posted by Microsoft on 5/6/2010 at 2:17 PM
Thank you for reporting this bug. We were already aware of it and the issue is fixed for the VS 2010 RTM release. I was able to verify that this issue is fixed in VS 2010 RTM contrary to phaeron's report.

Please respond back if you can provide a repro for VS 2010.


Visual C++ Codegen and Tools Team
Posted by Microsoft on 4/23/2010 at 3:46 PM
Thank you for your feedback. We are investigating the issue, and will consider to fix it in a future release.
Posted by Microsoft on 4/19/2010 at 2:00 AM

Thanks for your feedback.

We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.
These specialized experts will follow-up with your issue.
Posted by Avery Lee on 4/18/2010 at 1:24 PM
This also reproduces in VC10 (compiler version 16.00.30319.01).