fix PR8867: a crash handling fp128. Thanks to Nick for the testcase.
llvm-svn: 122613
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index 5c284b7..2767656 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/lib/VMCore/ConstantFold.cpp
@@ -637,7 +637,7 @@
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);
diff --git a/llvm/unittests/VMCore/ConstantsTest.cpp b/llvm/unittests/VMCore/ConstantsTest.cpp
index 8f28407..8277584 100644
--- a/llvm/unittests/VMCore/ConstantsTest.cpp
+++ b/llvm/unittests/VMCore/ConstantsTest.cpp
@@ -109,5 +109,14 @@
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