summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-09-17 01:38:06 +0000
committerDan Gohman <gohman@apple.com>2010-09-17 01:38:06 +0000
commit18fa17cf3db3ae4d947c4920e3b05666be1e4661 (patch)
treee10c658982df713fc325d2de06ef2b3717482e7b /llvm/lib/Analysis/ConstantFolding.cpp
parent3f7796fc223db72945c1209f71625f1acab87f57 (diff)
downloadbcm5719-llvm-18fa17cf3db3ae4d947c4920e3b05666be1e4661.tar.gz
bcm5719-llvm-18fa17cf3db3ae4d947c4920e3b05666be1e4661.zip
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. llvm-svn: 114148
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 0bf7967e83b..69581ba5ecd 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -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;
}
OpenPOWER on IntegriCloud