VS2012 - Incorrect code generation - by ludde_

Status : 


Sign in
to vote
ID 786097 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 5/2/2013 4:14:10 AM
Access Restriction Public


Incorrect code is generated for certain branchless operations with the 'char' type.
In this case: 
bb |= (bb >= 'A' && bb <= 'Z') ? 32 : 0;

The compiler generates:
mov         eax,19h  
cmp         ah,al       <-- wtf is this, eax is a constant!?
sbb         eax,eax 
and         ecx,0FFFFFFE0h  
add         ecx,20h  
or          cl,dl  

which is clearly broken.
Sign in to post a comment.
Posted by Eric [MSFT] on 5/7/2013 at 9:15 AM
Hi, thanks for the report. This is a bug in the compiler optimizer. This will be fixed in a future release.

If you need a source code workaround you can disable optimizations around the function you showed has the bad codegen.
#pragma optimize("", off)
static bool Equals(const char *a, const char *b) {
#pragma optimize("", on)

If this issue is severe, causing critical business situations or blocking your product development or deployment, please go to http://support.microsoft.com or call 1-800-MICROSOFT for assistance.
For Microsoft premier customers, please contact your administrator, your Technical Account Manager, or your Microsoft premier account representative.

I am closing this MSConnect item. Feel free to respond if you need anything else.

Eric Brumer - Microsoft Visual C++
Posted by Microsoft on 5/2/2013 at 10:00 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Macy [MSFT] on 5/2/2013 at 4:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)