<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - X86_64 cast double to unsigned long long gets FPE FE_INVALID in cvttsd2si for values > 2^63"
   href="https://llvm.org/bugs/show_bug.cgi?id=22873">22873</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>X86_64 cast double to unsigned long long gets FPE FE_INVALID in cvttsd2si for values > 2^63
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.4
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>gyllenllvm@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=14026" name="attach_14026" title="Small reproducer for FPE during cast fpe9.cc">attachment 14026</a> <a href="attachment.cgi?id=14026&action=edit" title="Small reproducer for FPE during cast fpe9.cc">[details]</a></span>
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)</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>