https://bugs.llvm.org/show_bug.cgi?id=49326

            Bug ID: 49326
           Summary: <math.h> wrapper functions break <fenv.h>
                    functionality
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: richard-l...@metafoo.co.uk
                CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com
        Depends on: 49325

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:

https://godbolt.org/z/zr4bdY

#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.


Referenced Bugs:

https://bugs.llvm.org/show_bug.cgi?id=49325
[Bug 49325] changing the floating point environment interacts badly with
interprocedural optimizations
-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to