aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-12-06 22:18:37 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-12-06 22:18:37 +0000
commitb9ce8b3f1b34bace8a5201fb78a4f7f9fcbf079e (patch)
tree61d8a8ac23c1ce025ca8ea54d25a4938696fd99b
parent9f9b3acfce893ccfedd89573f24bd363dd15a6ce (diff)
downloadexternal_llvm-b9ce8b3f1b34bace8a5201fb78a4f7f9fcbf079e.zip
external_llvm-b9ce8b3f1b34bace8a5201fb78a4f7f9fcbf079e.tar.gz
external_llvm-b9ce8b3f1b34bace8a5201fb78a4f7f9fcbf079e.tar.bz2
For PR409: \
Test the range of float constants to ensure we are not attempting to create a \ float constant using a double value that is out of range for a float git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18585 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/VMCore/Constants.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 97e4fa5..c97d9fc 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -21,6 +21,7 @@
#include "llvm/ADT/StringExtras.h"
#include <algorithm>
#include <iostream>
+#include <limits>
using namespace llvm;
ConstantBool *ConstantBool::True = new ConstantBool(true);
@@ -442,6 +443,16 @@ bool ConstantFP::isValueValidForType(const Type *Ty, double Val) {
// TODO: Figure out how to test if a double can be cast to a float!
case Type::FloatTyID:
+ return
+ (std::numeric_limits<double>::has_infinity &&
+ std::numeric_limits<float>::has_infinity &&
+ Val == std::numeric_limits<double>::infinity()) ||
+ (std::numeric_limits<double>::has_quiet_NaN &&
+ std::numeric_limits<float>::has_quiet_NaN &&
+ Val == std::numeric_limits<double>::quiet_NaN()) ||
+ (Val >= -std::numeric_limits<float>::max() &&
+ Val <= std::numeric_limits<float>::max());
+
case Type::DoubleTyID:
return true; // This is the largest type...
}