[LLVMbugs] [Bug 22105] New: NAN generated by legitimate long double code

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jan 6 07:57:51 PST 2015


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

            Bug ID: 22105
           Summary: NAN generated by legitimate long double code
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: carlo.milanesi at tiscali.it
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The command line:
  clang++ -O -I../ bug.cpp -obug.exe && ./bug.exe && echo FAIL
prints:
    FAIL
when the `bug.cpp` file has the following contents:

    #include <cmath>
    int main(int, char**)
    {
        typedef long double const type;
        type d = std::sqrt(26.L);
        type u = 1 * d;
        type v = -5 * d;
        type w = 0 * d;
        type angle = 0.6;
        type cos_a = 0.8;
        type sin_a = std::sin(angle);
        type xx = 3 * (u * u) - (7 * v + 5 * w) + 7 * sin_a;
        type yy = (7 - 3 * u * v) * cos_a + 5 * sin_a;
        type zz = (5 * (1 - w * w) - u * w) * cos_a + 3 * v * sin_a;
        return xx + yy + zz < 0 || xx + yy + zz > 0;
    }

Removing `const` has no apparent effect.
If at the beginning it is inserted the line:
    #include <iostream>
and the `return` statement is replaced by the line:
        std::cout << xx << yy << zz << std::endl;
the output is:
    -nan-nan-nan
    FAIL
If the command line is:
  g++-4.7 -O bug.cpp -obug.exe && ./bug.exe && echo FAIL
or
  clang++ bug.cpp -obug.exe && ./bug.exe && echo FAIL
The first program has no output, and the second one prints:
    260.418320.423-39.1868
    FAIL
(Although it prints FAIL, it is correct).

The command:
    clang --version
prints:
    Ubuntu clang version 3.4-1ubuntu3~precise2 (tags/RELEASE_34/final)
    (based on LLVM 3.4)
    Target: i386-pc-linux-gnu
    Thread model: posix

The original defect was in a much more complex code, that I simplified.
At any simplification I try to the above code, the defect disappears.
It appears to be a defect in the optimization of `long double` computations.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150106/1c6477ee/attachment.html>


More information about the llvm-bugs mailing list