http://llvm.org/bugs/show_bug.cgi?id=21093
Bug ID: 21093
Summary: add domain warnings for math functions
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Classification: Unclassified
When using '-ffinite-math-only' (or any other flag that implicitly turns on
"no-nans-fp-math"), the following code causes undefined behavior that is
detectable at compile-time, so clang should emit a warning:
$ cat bad_math.c
#include <math.h>
double bad_sqrt() { return sqrt(-2.0); }
$ ./clang bad_math.c -O1 -ffinite-math-only -c
The square root of a negative number is implementation-defined behavior for
C/C++. Most hardware and software (IEEE-754, POSIX, etc.) implementations
return NaN for this case. But with -ffinite-math-only, the user has guaranteed
not to use NaNs...so UB.
For completeness, domain checking should be added for several of the standard
math calls, not just 'sqrt'.
This was discussed here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140609/220598.html
And again here:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-September/077168.html
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs