mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
Fix the folding of floating-point math library calls, like sin(infinity),
so that it detects errors on platforms where libm doesn't set errno. It's still subject to host libm details though. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114148 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include <cerrno>
|
||||
#include <cmath>
|
||||
#include <fenv.h>
|
||||
using namespace llvm;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -1039,9 +1040,12 @@ llvm::canConstantFoldCallTo(const Function *F) {
|
||||
|
||||
static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
|
||||
const Type *Ty) {
|
||||
feclearexcept(FE_ALL_EXCEPT);
|
||||
errno = 0;
|
||||
V = NativeFP(V);
|
||||
if (errno != 0) {
|
||||
if (errno != 0 ||
|
||||
fetestexcept(FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)) {
|
||||
feclearexcept(FE_ALL_EXCEPT);
|
||||
errno = 0;
|
||||
return 0;
|
||||
}
|
||||
@@ -1056,9 +1060,12 @@ static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
|
||||
|
||||
static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
|
||||
double V, double W, const Type *Ty) {
|
||||
feclearexcept(FE_ALL_EXCEPT);
|
||||
errno = 0;
|
||||
V = NativeFP(V, W);
|
||||
if (errno != 0) {
|
||||
if (errno != 0 ||
|
||||
fetestexcept(FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)) {
|
||||
feclearexcept(FE_ALL_EXCEPT);
|
||||
errno = 0;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user