Guard MemoryBuiltins against self-looping GEPs, which can occur in unreachable code due to constant propagation.
Fixes PR13621. llvm-svn: 162098
This commit is contained in:
parent
2f47a3fb07
commit
4901f0d2a2
|
@ -473,6 +473,10 @@ ObjectSizeOffsetVisitor::visitExtractValueInst(ExtractValueInst&) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SizeOffsetType ObjectSizeOffsetVisitor::visitGEPOperator(GEPOperator &GEP) {
|
SizeOffsetType ObjectSizeOffsetVisitor::visitGEPOperator(GEPOperator &GEP) {
|
||||||
|
// Ignore self-referencing GEPs, they can occur in unreachable code.
|
||||||
|
if (&GEP == GEP.getPointerOperand())
|
||||||
|
return unknown();
|
||||||
|
|
||||||
SizeOffsetType PtrData = compute(GEP.getPointerOperand());
|
SizeOffsetType PtrData = compute(GEP.getPointerOperand());
|
||||||
if (!bothKnown(PtrData) || !GEP.hasAllConstantIndices())
|
if (!bothKnown(PtrData) || !GEP.hasAllConstantIndices())
|
||||||
return unknown();
|
return unknown();
|
||||||
|
|
|
@ -238,3 +238,20 @@ xpto:
|
||||||
return:
|
return:
|
||||||
ret i32 42
|
ret i32 42
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; CHECK: @PR13621
|
||||||
|
define i32 @PR13621(i1 %bool) nounwind {
|
||||||
|
entry:
|
||||||
|
%cond = or i1 %bool, true
|
||||||
|
br i1 %cond, label %return, label %xpto
|
||||||
|
|
||||||
|
; technically reachable, but this malformed IR may appear as a result of constant propagation
|
||||||
|
xpto:
|
||||||
|
%gep = getelementptr i8* %gep, i32 1
|
||||||
|
%o = call i32 @llvm.objectsize.i32(i8* %gep, i1 true)
|
||||||
|
; CHECK: ret i32 undef
|
||||||
|
ret i32 %o
|
||||||
|
|
||||||
|
return:
|
||||||
|
ret i32 7
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue