diff options
author | Hal Finkel <hfinkel@anl.gov> | 2013-07-10 22:51:01 +0000 |
---|---|---|
committer | Hal Finkel <hfinkel@anl.gov> | 2013-07-10 22:51:01 +0000 |
commit | b31366da8272e2e2149e5d044b0af1c01d81786f (patch) | |
tree | d849fda004df08e2d0dea61d8f9cd1fcbec06fa7 | |
parent | 555aa899c63e4b6b854dc5fa71808b6a400191fc (diff) | |
download | bcm5719-llvm-b31366da8272e2e2149e5d044b0af1c01d81786f.tar.gz bcm5719-llvm-b31366da8272e2e2149e5d044b0af1c01d81786f.zip |
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.
llvm-svn: 186044
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 29 | ||||
-rw-r--r-- | llvm/test/Other/nonconst-static-ev.ll | 8 | ||||
-rw-r--r-- | llvm/test/Other/nonconst-static-iv.ll | 8 |
3 files changed, 37 insertions, 8 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index e04be1f59d5..9067b343122 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -1954,14 +1954,22 @@ Constant *ConstantExpr::getShuffleVector(Constant *V1, Constant *V2, 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(Constant *Agg, 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) { diff --git a/llvm/test/Other/nonconst-static-ev.ll b/llvm/test/Other/nonconst-static-ev.ll new file mode 100644 index 00000000000..3e4b7bde5ef --- /dev/null +++ b/llvm/test/Other/nonconst-static-ev.ll @@ -0,0 +1,8 @@ +; RUN: not llc < %s 2> %t +; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s + +@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) +@1 = external global i32 + +; CHECK-ERRORS: Unsupported expression in static initializer: extractvalue + diff --git a/llvm/test/Other/nonconst-static-iv.ll b/llvm/test/Other/nonconst-static-iv.ll new file mode 100644 index 00000000000..14db94c9a87 --- /dev/null +++ b/llvm/test/Other/nonconst-static-iv.ll @@ -0,0 +1,8 @@ +; RUN: not llc < %s 2> %t +; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s + +@0 = global i8 insertvalue( { i8 } select (i1 ptrtoint (i32* @1 to i1), { i8 } { i8 1 }, { i8 } { i8 2 }), i8 0, 0) +@1 = external global i32 + +; CHECK-ERRORS: Unsupported expression in static initializer: insertvalue + |