[LLVMbugs] [Bug 22873] New: X86_64 cast double to unsigned long long gets FPE FE_INVALID in cvttsd2si for values > 2^63

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Mar 10 17:19:48 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=22873

            Bug ID: 22873
           Summary: X86_64 cast double to unsigned long long gets FPE
                    FE_INVALID in cvttsd2si for values > 2^63
           Product: new-bugs
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: gyllenllvm at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 14026
  --> https://llvm.org/bugs/attachment.cgi?id=14026&action=edit
Small reproducer for FPE during cast fpe9.cc

With floating point exception handling enabled for FE_INVALID, casts of doubles
to unsigned long long with values between 2^64 and 2^63 generate a FPE when
compiled with clang++ 3.4 on x86_64 RedHat EL6 in cvttsd2si.   Testcase runs
when compiled with g++ and icpc.   G++ also uses cvttsd2si (Convert Scalar
Double-Precision Floating-Point Value to Signed Doubleword Integer with
Truncation) but does checks to detect numbers in that range and modifies them
before executing cvttsd2si.

These are the three key lines of the short attached testcase fpe9.cc:
      feenableexcept(FE_INVALID);
      volatile double x = 1.8e19;
      unsigned long long llval = static_cast<unsigned long long>(x);

Here is how I reproduced with clang++ 3.4 on x86_64:
clang++ fpe9.cc
./a.out
About to do static_cast (cvttsd2si) that gets FPE FE_INVALID on x86_64
Floating exception (core dumped)

-- 
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/20150311/8b5d68cc/attachment.html>


More information about the llvm-bugs mailing list