llvm.org GIT mirror llvm / 10050d1
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186044 91177308-0d34-0410-b5e6-96231b3b80d8 Hal Finkel 6 years ago
3 changed file(s) with 37 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
19531953
19541954 Constant *ConstantExpr::getInsertValue(Constant *Agg, Constant *Val,
19551955 ArrayRef Idxs) {
1956 assert(Agg->getType()->isFirstClassType() &&
1957 "Non-first-class type for constant insertvalue expression");
1958
19561959 assert(ExtractValueInst::getIndexedType(Agg->getType(),
19571960 Idxs) == Val->getType() &&
19581961 "insertvalue indices invalid!");
1959 assert(Agg->getType()->isFirstClassType() &&
1960 "Non-first-class type for constant insertvalue expression");
1961 Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs);
1962 assert(FC && "insertvalue constant expr couldn't be folded!");
1963 return FC;
1962 Type *ReqTy = Val->getType();
1963
1964 if (Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs))
1965 return FC;
1966
1967 Constant *ArgVec[] = { Agg, Val };
1968 const ExprMapKeyType Key(Instruction::InsertValue, ArgVec, 0, 0, Idxs);
1969
1970 LLVMContextImpl *pImpl = Agg->getContext().pImpl;
1971 return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
19641972 }
19651973
19661974 Constant *ConstantExpr::getExtractValue(Constant *Agg,
19741982
19751983 assert(Agg->getType()->isFirstClassType() &&
19761984 "Non-first-class type for constant extractvalue expression");
1977 Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs);
1978 assert(FC && "ExtractValue constant expr couldn't be folded!");
1979 return FC;
1985 if (Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs))
1986 return FC;
1987
1988 Constant *ArgVec[] = { Agg };
1989 const ExprMapKeyType Key(Instruction::ExtractValue, ArgVec, 0, 0, Idxs);
1990
1991 LLVMContextImpl *pImpl = Agg->getContext().pImpl;
1992 return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
19801993 }
19811994
19821995 Constant *ConstantExpr::getNeg(Constant *C, bool HasNUW, bool HasNSW) {
0 ; RUN: not llc < %s 2> %t
1 ; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s
2
3 @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)
4 @1 = external global i32
5
6 ; CHECK-ERRORS: Unsupported expression in static initializer: extractvalue
7
0 ; RUN: not llc < %s 2> %t
1 ; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s
2
3 @0 = global i8 insertvalue( { i8 } select (i1 ptrtoint (i32* @1 to i1), { i8 } { i8 1 }, { i8 } { i8 2 }), i8 0, 0)
4 @1 = external global i32
5
6 ; CHECK-ERRORS: Unsupported expression in static initializer: insertvalue
7