Fix PR3468: a crash when constant folding a bitcast of
authorDuncan Sands <baldrick@free.fr>
Wed, 4 Feb 2009 10:17:14 +0000 (10:17 +0000)
committerDuncan Sands <baldrick@free.fr>
Wed, 4 Feb 2009 10:17:14 +0000 (10:17 +0000)
i80 to x86 long double (this was presumably generated
by sroa).

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

lib/VMCore/ConstantFold.cpp
test/Transforms/InstCombine/2009-02-04-FPBitcast.ll [new file with mode: 0644]

index 5c1578f74b02b898250b5fda285b1937f1726168..5f7cbcd0b60b5cd50a664a1db2b47247372c66a6 100644 (file)
@@ -153,12 +153,11 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy) {
       // Integral -> Integral. This is a no-op because the bit widths must
       // be the same. Consequently, we just fold to V.
       return V;
-    
-    if (DestTy->isFloatingPoint()) {
-      assert((DestTy == Type::DoubleTy || DestTy == Type::FloatTy) && 
-             "Unknown FP type!");
-      return ConstantFP::get(APFloat(CI->getValue()));
-    }
+
+    if (DestTy->isFloatingPoint())
+      return ConstantFP::get(APFloat(CI->getValue(),
+                                     DestTy != Type::PPC_FP128Ty));
+
     // Otherwise, can't fold this (vector?)
     return 0;
   }
diff --git a/test/Transforms/InstCombine/2009-02-04-FPBitcast.ll b/test/Transforms/InstCombine/2009-02-04-FPBitcast.ll
new file mode 100644 (file)
index 0000000..4d7b70a
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: llvm-as < %s | opt -instcombine
+; PR3468
+
+define x86_fp80 @cast() {
+       %tmp = bitcast i80 0 to x86_fp80                ; <x86_fp80> [#uses=1]
+       ret x86_fp80 %tmp
+}