VS2012 C++ optimizing bug when using inline and char return type (x86 target only) - by erni

Status : 

 


8
0
Sign in
to vote
ID 777533 Comments
Status Closed Workarounds
Type Bug Repros 2
Opened 1/25/2013 12:41:27 PM
Access Restriction Public

Description

The following code gives wrong result when compiled with /02 on x86 target.
The code is similar in WebKit (wtf) which is used in Qt.
{code}
// cl /Zi /O2 test.cpp compile to wrong assembly with in x86 compiler

#include <stdio.h>
inline char toASCIILower(char c) { return c | ((c >= 'A' && c <= 'Z') << 5); }     // WRONG OPTIMIZED
// inline int toASCIILower(char c) { return c | ((c >= 'A' && c <= 'Z') << 5); }     // RESULT CORRECT
//inline char toASCIILower(char c) { return c | ((c >= 'A' && c <= 'Z') ? 0x20 : 0); } // WRONG OPTIMIZED
//inline char toASCIILower(char c) { return (c >= 'A' && c <= 'Z') ? c + 0x20 : c; }   // RESULT CORRECT

static bool equal(const char* s1, const char* s2)
{
 char c1;
 char c2;
 do {
  c1 = *s1++;
  c2 = *s2++;
  if (toASCIILower(c1) != toASCIILower(c2))
   return false;
 } while (c1 && c2);
 return !c1 && !c2;
}

#define VERIFY(a) printf ("%s\t%s\n", #a, a?"ok":"FAILED")
int main (int argc, char *argv[])
{
 VERIFY(equal("win-1234-1", "win-1234-1"));
 VERIFY(equal("ISO-8859-1", "ISO-8859-1"));
}
{code}
Sign in to post a comment.
Posted by jturcotte on 3/8/2013 at 5:49 AM
I just tested VS2012 Update2 CTP4 and this bug has only been partially fixed.

I just attached two test case cpp files.
The first one (mainU1.cpp) fails with Update1 but is now working correctly with Update2 CTP4, thanks.
The second one (mainU2.cpp), a bit more complex, still fails with Update2 CTP4 (I didn't try this one with Update1).

Please re-open this bug.
Posted by Microsoft on 2/13/2013 at 4:37 PM
Thanks for reporting the issue. We have confirmed it's a bug in compiler. And we have already fixed it for the next release.
Posted by Microsoft on 1/27/2013 at 6:09 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 Mike Danes on 1/26/2013 at 2:01 AM
This looks very similar to https://connect.microsoft.com/VisualStudio/feedback/details/768459/miscompilation-of-char-string-manipulation-on-ox
Posted by Microsoft on 1/25/2013 at 12:50 PM
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)