[llvm] r186044 - Don't assert if we can't constant fold extract/insertvalue
Hal Finkel
hfinkel at anl.gov
Wed Jul 10 15:51:01 PDT 2013
Author: hfinkel
Date: Wed Jul 10 17:51:01 2013
New Revision: 186044
URL: http://llvm.org/viewvc/llvm-project?rev=186044&view=rev
Log:
Don't assert if we can't constant fold extract/insertvalue
A non-constant-foldable static initializer expression containing insertvalue or
extractvalue had been causing an assert:
Constants.cpp:1971: Assertion `FC && "ExtractValue constant expr couldn't be
folded!"' failed.
Now we report a more-sensible "Unsupported expression in static initializer"
error instead.
Fixes PR15417.
Added:
llvm/trunk/test/Other/nonconst-static-ev.ll
llvm/trunk/test/Other/nonconst-static-iv.ll
Modified:
llvm/trunk/lib/IR/Constants.cpp
Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=186044&r1=186043&r2=186044&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Wed Jul 10 17:51:01 2013
@@ -1954,14 +1954,22 @@ Constant *ConstantExpr::getShuffleVector
Constant *ConstantExpr::getInsertValue(Constant *Agg, Constant *Val,
ArrayRef<unsigned> Idxs) {
+ assert(Agg->getType()->isFirstClassType() &&
+ "Non-first-class type for constant insertvalue expression");
+
assert(ExtractValueInst::getIndexedType(Agg->getType(),
Idxs) == Val->getType() &&
"insertvalue indices invalid!");
- assert(Agg->getType()->isFirstClassType() &&
- "Non-first-class type for constant insertvalue expression");
- Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs);
- assert(FC && "insertvalue constant expr couldn't be folded!");
- return FC;
+ Type *ReqTy = Val->getType();
+
+ if (Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs))
+ return FC;
+
+ Constant *ArgVec[] = { Agg, Val };
+ const ExprMapKeyType Key(Instruction::InsertValue, ArgVec, 0, 0, Idxs);
+
+ LLVMContextImpl *pImpl = Agg->getContext().pImpl;
+ return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
}
Constant *ConstantExpr::getExtractValue(Constant *Agg,
@@ -1975,9 +1983,14 @@ Constant *ConstantExpr::getExtractValue(
assert(Agg->getType()->isFirstClassType() &&
"Non-first-class type for constant extractvalue expression");
- Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs);
- assert(FC && "ExtractValue constant expr couldn't be folded!");
- return FC;
+ if (Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs))
+ return FC;
+
+ Constant *ArgVec[] = { Agg };
+ const ExprMapKeyType Key(Instruction::ExtractValue, ArgVec, 0, 0, Idxs);
+
+ LLVMContextImpl *pImpl = Agg->getContext().pImpl;
+ return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
}
Constant *ConstantExpr::getNeg(Constant *C, bool HasNUW, bool HasNSW) {
Added: llvm/trunk/test/Other/nonconst-static-ev.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/nonconst-static-ev.ll?rev=186044&view=auto
==============================================================================
--- llvm/trunk/test/Other/nonconst-static-ev.ll (added)
+++ llvm/trunk/test/Other/nonconst-static-ev.ll Wed Jul 10 17:51:01 2013
@@ -0,0 +1,8 @@
+; RUN: not llc < %s 2> %t
+; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s
+
+ at 0 = global i8 extractvalue ([1 x i8] select (i1 ptrtoint (i32* @1 to i1), [1 x i8] [ i8 1 ], [1 x i8] [ i8 2 ]), 0)
+ at 1 = external global i32
+
+; CHECK-ERRORS: Unsupported expression in static initializer: extractvalue
+
Added: llvm/trunk/test/Other/nonconst-static-iv.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/nonconst-static-iv.ll?rev=186044&view=auto
==============================================================================
--- llvm/trunk/test/Other/nonconst-static-iv.ll (added)
+++ llvm/trunk/test/Other/nonconst-static-iv.ll Wed Jul 10 17:51:01 2013
@@ -0,0 +1,8 @@
+; RUN: not llc < %s 2> %t
+; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s
+
+ at 0 = global i8 insertvalue( { i8 } select (i1 ptrtoint (i32* @1 to i1), { i8 } { i8 1 }, { i8 } { i8 2 }), i8 0, 0)
+ at 1 = external global i32
+
+; CHECK-ERRORS: Unsupported expression in static initializer: insertvalue
+
More information about the llvm-commits
mailing list