[LLVMbugs] [Bug 21093] New: add domain warnings for math functions

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Sep 29 08:42:21 PDT 2014


            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: unassignedclangbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvmbugs at cs.uiuc.edu
    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:

And again here:

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/20140929/56b3969b/attachment.html>

More information about the llvm-bugs mailing list