llvm.org GIT mirror llvm / 2f08433
ObjectSizeOffsetEvaluator: Don't run into infinite recursion if we have a cyclic GEP. Those can occur in dead code. PR17402. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191644 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 7 years ago
2 changed file(s) with 24 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
633633 if (Instruction *I = dyn_cast(V))
634634 Builder.SetInsertPoint(I);
635635
636 // record the pointers that were handled in this run, so that they can be
637 // cleaned later if something fails
638 SeenVals.insert(V);
639
640636 // now compute the size and offset
641637 SizeOffsetEvalType Result;
642 if (GEPOperator *GEP = dyn_cast(V)) {
638
639 // Record the pointers that were handled in this run, so that they can be
640 // cleaned later if something fails. We also use this set to break cycles that
641 // can occur in dead code.
642 if (!SeenVals.insert(V)) {
643 Result = unknown();
644 } else if (GEPOperator *GEP = dyn_cast(V)) {
643645 Result = visitGEPOperator(*GEP);
644646 } else if (Instruction *I = dyn_cast(V)) {
645647 Result = visit(*I);
125125 %4 = load i64* %3, align 8
126126 ret i64 %4
127127 }
128
129 ; PR17402
130 ; CHECK-LABEL: @f13
131 define void @f13() nounwind {
132 entry:
133 br label %alive
134
135 dead:
136 ; Self-refential GEPs can occur in dead code.
137 %incdec.ptr = getelementptr inbounds i32* %incdec.ptr, i64 1
138 ; CHECK: %incdec.ptr = getelementptr inbounds i32* %incdec.ptr
139 %l = load i32* %incdec.ptr
140 br label %alive
141
142 alive:
143 ret void
144 }