[LLVMbugs] [Bug 11393] New: Wrong code produced by -O or -O2 optimization

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Nov 16 10:31:31 PST 2011


http://llvm.org/bugs/show_bug.cgi?id=11393

             Bug #: 11393
           Summary: Wrong code produced by -O or -O2 optimization
           Product: clang
           Version: trunk
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: michael at jarvis.net
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 7620
  --> http://llvm.org/bugs/attachment.cgi?id=7620
Code exhibiting bug.

I have come across a very strange bug in clang++ where it produces wrong code
when compiled with -O or -O2, but gets the right answer for -O0, -O1 or -O3.

See the attached code for a small test case exhibiting the problem.  I think
the bug happens in the line RT d = REAL(a)*REAL(b) - NORM(c);  It seems to do
something strange with the a and b variables at that point.

I've marked a number of changes to the code that manage to avoid the problem
with comments marked // NB...

Command line to reproduce bug:

$ /Users/Mike/clang/build/Release+Asserts/bin/clang++ -O2 clangbug.cpp -o cb;
cb
Done: a,b,c,d => (0.1875,0),(0.1875,0),(0.3125,0),-16
Correct answers are (0.0967742,0),(-0.0645161,-0),(0.16129,0),-31

Expected output achieved if -O2 is omitted or replaced by -O0, -O1, or -O3:

$ /Users/Mike/clang/build/Release+Asserts/bin/clang++ clangbug.cpp -o cb; cb
Done: a,b,c,d => (0.0967742,0),(-0.0645161,-0),(0.16129,0),-31
Correct answers are (0.0967742,0),(-0.0645161,-0),(0.16129,0),-31



System details:

MacOsX 10.6.8, 2.66 GHz Intel Core i7

$ /Users/Mike/clang/build/Release+Asserts/bin/clang++ --version
clang version 3.1 (trunk 144613)
Target: x86_64-apple-darwin10.8.0
Thread model: posix

(The bug happens with a Debug+Asserts build of clang++ as well.)

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list