<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 - <math.h> wrapper functions break <fenv.h> functionality"
   href="https://bugs.llvm.org/show_bug.cgi?id=49326">49326</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td><math.h> wrapper functions break <fenv.h> functionality
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Depends on</th>
          <td>49325
          </td>
        </tr></table>
      <p>
        <div>
        <pre>libc++'s <math.h> wrapper functions are built in FENV_ACCESS OFF mode. This
means that LLVM will generate code for them assuming that they can only be
called in the default rounding mode. This causes calls to them in non-default
rounding modes to not work:

<a href="https://godbolt.org/z/zr4bdY">https://godbolt.org/z/zr4bdY</a>

#include <cfenv>
#include <cmath>
#include <cstdio>

#pragma STDC FENV_ACCESS ON

int main(void) {
    auto default_rounding = std::fegetround();
    std::fesetround(FE_UPWARD);
    std::printf("%+4.1f", std::rint(10.5f));
    std::fesetround(default_rounding);
}

... incorrectly prints '+10.0' when compiled with '-O2 -stdlib=libc++'.

Presumably we should define the wrapper functions in an FENV_ACCESS ON region.

In order for this to not introduce a performance regression, we'll presumably
need part (3) of #49325 fixed first.</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - changing the floating point environment interacts badly with interprocedural optimizations"
   href="https://bugs.llvm.org/show_bug.cgi?id=49325">Bug 49325</a>] changing the floating point environment interacts badly with interprocedural optimizations
              </li>
          </ul>
        </div>
        <br>

      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>