Fix PR409:
authorReid Spencer <rspencer@reidspencer.com>
Thu, 22 Dec 2005 21:07:29 +0000 (21:07 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Thu, 22 Dec 2005 21:07:29 +0000 (21:07 +0000)
Implement the suggested check to ensure that out-of-range float constants
don't get accepted by LLVM accidentally. Adjust the supporting test cases
as well.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24963 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Constants.cpp
test/Assembler/2004-01-22-FloatNormalization.ll [deleted file]
test/Assembler/2004-12-06-ConstantFloatRange.ll
test/Verifier/2004-01-22-FloatNormalization.ll [new file with mode: 0644]

index 080baf8d63bd84bb40ec62360e92a55546edf04b..c1324b6b265d769c0c9691b367e69954fed1b5b5 100644 (file)
@@ -482,6 +482,9 @@ 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:
+    float FV = float(Val);
+    double DV = double(FV);
+    return  IsNAN(Val) || Val == DV;
   case Type::DoubleTyID:
     return true;          // This is the largest type...
   }
diff --git a/test/Assembler/2004-01-22-FloatNormalization.ll b/test/Assembler/2004-01-22-FloatNormalization.ll
deleted file mode 100644 (file)
index 5eae402..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-; RUN: llvm-as < %s -o /dev/null -f
-
-; make sure that 'float' values have their value properly truncated.
-
-global float 0x1 
index 30d103c57289a34c7ea5bf86a4096af226a7cca8..61f2b77b3f9d2bf96864d385ff9f12e2b77ae862 100644 (file)
@@ -1,5 +1,4 @@
 ; RUN: llvm-as %s -o /dev/null 2>&1 | grep "constant invalid for type"
-; XFAIL: *
 
 ;; This is a testcase for PR409
 
diff --git a/test/Verifier/2004-01-22-FloatNormalization.ll b/test/Verifier/2004-01-22-FloatNormalization.ll
new file mode 100644 (file)
index 0000000..8fbfe19
--- /dev/null
@@ -0,0 +1,6 @@
+; RUN: llvm-as < %s -o /dev/null -f
+; XFAIL: *
+
+; make sure that invalid 'float' values are caught.
+
+global float 0x1