llvm.org GIT mirror llvm / 3b637f6
Handle ConstantExpr correctly in SelectionDAGBuilder This change fixes a bug in SelectionDAGBuilder::visitInsertValue and SelectionDAGBuilder::visitExtractValue where constant expressions (InsertValueConstantExpr and ExtractValueConstantExpr) would be treated as non-constant instructions (InsertValueInst and ExtractValueInst). This bug resulted in an incorrect memory access, which manifested as an assertion failure in SDValue::SDValue. Fixes PR#33094. Submitted on behalf of @Praetonus (Benoit Vey) Differential Revision: https://reviews.llvm.org/D34538 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307502 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Pilgrim 3 years ago
3 changed file(s) with 36 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
32193219 setValue(&I, DAG.getBuildVector(VT, DL, Ops));
32203220 }
32213221
3222 void SelectionDAGBuilder::visitInsertValue(const InsertValueInst &I) {
3222 void SelectionDAGBuilder::visitInsertValue(const User &I) {
3223 ArrayRef Indices;
3224 if (const InsertValueInst *IV = dyn_cast(&I))
3225 Indices = IV->getIndices();
3226 else
3227 Indices = cast(&I)->getIndices();
3228
32233229 const Value *Op0 = I.getOperand(0);
32243230 const Value *Op1 = I.getOperand(1);
32253231 Type *AggTy = I.getType();
32273233 bool IntoUndef = isa(Op0);
32283234 bool FromUndef = isa(Op1);
32293235
3230 unsigned LinearIndex = ComputeLinearIndex(AggTy, I.getIndices());
3236 unsigned LinearIndex = ComputeLinearIndex(AggTy, Indices);
32313237
32323238 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
32333239 SmallVector AggValueVTs;
32673273 DAG.getVTList(AggValueVTs), Values));
32683274 }
32693275
3270 void SelectionDAGBuilder::visitExtractValue(const ExtractValueInst &I) {
3276 void SelectionDAGBuilder::visitExtractValue(const User &I) {
3277 ArrayRef Indices;
3278 if (const ExtractValueInst *EV = dyn_cast(&I))
3279 Indices = EV->getIndices();
3280 else
3281 Indices = cast(&I)->getIndices();
3282
32713283 const Value *Op0 = I.getOperand(0);
32723284 Type *AggTy = Op0->getType();
32733285 Type *ValTy = I.getType();
32743286 bool OutOfUndef = isa(Op0);
32753287
3276 unsigned LinearIndex = ComputeLinearIndex(AggTy, I.getIndices());
3288 unsigned LinearIndex = ComputeLinearIndex(AggTy, Indices);
32773289
32783290 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
32793291 SmallVector ValValueVTs;
3737 class CallInst;
3838 class DbgValueInst;
3939 class ExtractElementInst;
40 class ExtractValueInst;
4140 class FCmpInst;
4241 class FPExtInst;
4342 class FPToSIInst;
5251 class IndirectBrInst;
5352 class InvokeInst;
5453 class InsertElementInst;
55 class InsertValueInst;
5654 class Instruction;
5755 class LoadInst;
5856 class MachineBasicBlock;
858856 void visitInsertElement(const User &I);
859857 void visitShuffleVector(const User &I);
860858
861 void visitExtractValue(const ExtractValueInst &I);
862 void visitInsertValue(const InsertValueInst &I);
859 void visitExtractValue(const User &I);
860 void visitInsertValue(const User &I);
863861 void visitLandingPad(const LandingPadInst &I);
864862
865863 void visitGetElementPtr(const User &I);
0 ; RUN: llc < %s
1
2 ; PR33094
3 ; Make sure that a constant extractvalue doesn't cause a crash in
4 ; SelectionDAGBuilder::visitExtractValue.
5
6 %A = type {}
7 %B = type {}
8 %Tuple = type { i64 }
9
10 @A_Inst = global %A zeroinitializer
11 @B_Inst = global %B zeroinitializer
12
13 define i64 @foo() {
14 ret i64 extractvalue (%Tuple select (i1 icmp eq
15 (%B* bitcast (%A* @A_Inst to %B*), %B* @B_Inst),
16 %Tuple { i64 33 }, %Tuple { i64 42 }), 0)
17 }