<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - __builtin_isinf[_sign] yield incorrect results on X86 when using x87 math"
   href="https://bugs.llvm.org/show_bug.cgi?id=38833">38833</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__builtin_isinf[_sign] yield incorrect results on X86 when using x87 math
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>andres@anarazel.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi,

(thanks to Andrew Gierth for the test program and help in narrowing this down)

$ cat ~/tmp/flttst.c

#include <stdio.h>
#include <math.h>

int main(int argc, char **argv)
{
    double d1 = (argc ? 1e180 : 0);
    double d2 = (argv ? 1e200 : 0);
    int r2 = __builtin_isinf_sign(d1 * d2);
    int r1 = isinf(d1 * d2);
    printf("r1 = %d, r2 = %d\n", r1, r2);
    return 0;
}

$ clang-8 -std=c99 -march=i386 -O2 -m32 ~/tmp/flttst.c -o ~/tmp/flttst && 
~/tmp/flttst
r1 = 1, r2 = 0

$ clang-8 -std=c99 -march=pentium4 -O2 -m32 ~/tmp/flttst.c -o ~/tmp/flttst &&
~/tmp/flttst
r1 = 1, r2 = 1

The issue appears to be that the use of x87 math, with its 80bit registers,
avoids the overflow.   This appears to be a C99 violation - note that gcc
enables its -fexcess-precision=standard automatically in C99 mode.


We only noticed this because clang on freebsd (and other bsds) defaults to
targetting 486, whereas linux targets pentium4 (which has non x87 math). That
caused postgres' tests to fail on 32bit x86 freebsd, after starting to use the
intrinsic, whereas linux was fine.

Regards,

Andres Freund</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>