fix PR8867: a crash handling fp128. Thanks to Nick for the testcase.
authorChris Lattner <sabre@nondot.org>
Wed, 29 Dec 2010 01:33:36 +0000 (01:33 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 29 Dec 2010 01:33:36 +0000 (01:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122613 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp
unittests/VMCore/ConstantsTest.cpp

index 5c284b746de605b5a49d0e5a0987aa2f3d3e504d..27676562d4dcacb7b448e34d22289ca06bc1f9d4 100644 (file)
@@ -637,7 +637,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
   case Instruction::SIToFP:
     if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
       APInt api = CI->getValue();
-      APFloat apf(APInt::getNullValue(DestTy->getPrimitiveSizeInBits()));
+      APFloat apf(APInt::getNullValue(DestTy->getPrimitiveSizeInBits()), true);
       (void)apf.convertFromAPInt(api, 
                                  opc==Instruction::SIToFP,
                                  APFloat::rmNearestTiesToEven);
index 8f28407b8dec332f64a1e9687de5812bccd7fc74..8277584ba24dd5c3c086be57b7b3e3ec7a8f3577 100644 (file)
@@ -109,5 +109,14 @@ TEST(ConstantsTest, IntSigns) {
   EXPECT_EQ(0x3b, ConstantInt::get(Int8Ty, 0x13b)->getSExtValue());
 }
 
+TEST(ConstantsTest, FP128Test) {
+  const Type *FP128Ty = Type::getFP128Ty(getGlobalContext());
+
+  const IntegerType *Int128Ty = Type::getIntNTy(getGlobalContext(), 128);
+  Constant *Zero128 = Constant::getNullValue(Int128Ty);
+  Constant *X = ConstantExpr::getUIToFP(Zero128, FP128Ty);
+  EXPECT_TRUE(isa<ConstantFP>(X));
+}
+
 }  // end anonymous namespace
 }  // end namespace llvm