<html>
    <head>
      <base href="http://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 --- - add domain warnings for math functions"
   href="http://llvm.org/bugs/show_bug.cgi?id=21093">21093</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>add domain warnings for math functions
          </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>All
          </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>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.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>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:
<a href="http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140609/220598.html">http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140609/220598.html</a>

And again here:
<a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-September/077168.html">http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-September/077168.html</a></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>