[llvm-bugs] [Bug 38833] New: __builtin_isinf[_sign] yield incorrect results on X86 when using x87 math
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Sep 4 15:57:56 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38833
Bug ID: 38833
Summary: __builtin_isinf[_sign] yield incorrect results on X86
when using x87 math
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: andres at anarazel.de
CC: llvm-bugs at lists.llvm.org
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
--
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/20180904/3a7c632b/attachment.html>
More information about the llvm-bugs
mailing list