<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 - incorrect optimization with signaling NaN and implicit conversion in fabs: missing exception"
   href="https://bugs.llvm.org/show_bug.cgi?id=39112">39112</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>incorrect optimization with signaling NaN and implicit conversion in fabs: missing exception
          </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>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>vincent-llvm@vinc17.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>With a code that does something like

  float f = fabs (double_snan)

one does not get the FE_INVALID exception with -O.

Details:

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

typedef union { float f; uint32_t i; } ieee_float_t;

int main (void)
{
  volatile ieee_float_t x, y;
  volatile double d;

  x.i = 0x7f800001;
  printf ("0. %x (%g)\n", x.i, x.f);

  feclearexcept (FE_INVALID);
  y.f = fabs (x.f);
  if (fetestexcept (FE_INVALID))
    printf ("2. FE_INVALID\n");
  printf ("2. %x (%g)\n", y.i, y.f);

  return 0;
}

yields:

cventin% clang-8 snan.c -o snan -lm
cventin% ./snan
0. 7f800001 (nan)
2. FE_INVALID
2. 7fc00001 (nan)

which is correct (due to the float-to-double conversion of sNaN), but

cventin% clang-8 snan.c -o snan -lm -O
cventin% ./snan                       
0. 7f800001 (nan)
2. 7f800001 (nan)

The FE_INVALID exception is missing, and the result is a signaling NaN instead
of a quiet NaN.

Tested with the clang-8 1:8~svn342638-1 Debian package (x86_64 architecture).</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>