ObjectSizeOffsetEvaluator: Don't run into infinite recursion if we have a cyclic...
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 29 Sep 2013 19:39:13 +0000 (19:39 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 29 Sep 2013 19:39:13 +0000 (19:39 +0000)
Those can occur in dead code. PR17402.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191644 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/MemoryBuiltins.cpp
test/Instrumentation/BoundsChecking/simple.ll

index e710a998bf18801c1dc45a4fd5250d4a9f64a66c..8e89aa98486a6f145a8b678556ac3e3ea93fa8c4 100644 (file)
@@ -634,13 +634,15 @@ SizeOffsetEvalType ObjectSizeOffsetEvaluator::compute_(Value *V) {
   if (Instruction *I = dyn_cast<Instruction>(V))
     Builder.SetInsertPoint(I);
 
-  // record the pointers that were handled in this run, so that they can be
-  // cleaned later if something fails
-  SeenVals.insert(V);
-
   // now compute the size and offset
   SizeOffsetEvalType Result;
-  if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
+
+  // Record the pointers that were handled in this run, so that they can be
+  // cleaned later if something fails. We also use this set to break cycles that
+  // can occur in dead code.
+  if (!SeenVals.insert(V)) {
+    Result = unknown();
+  } else if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
     Result = visitGEPOperator(*GEP);
   } else if (Instruction *I = dyn_cast<Instruction>(V)) {
     Result = visit(*I);
index 16870c78a87535a54d57d7d618593571e2356e79..72b58f4b0a323a252d72bef98e540f0e69d0cb8e 100644 (file)
@@ -126,3 +126,20 @@ define i64 @f12(i64 %x, i64 %y) nounwind {
   %4 = load i64* %3, align 8
   ret i64 %4
 }
+
+; PR17402
+; CHECK-LABEL: @f13
+define void @f13() nounwind {
+entry:
+  br label %alive
+
+dead:
+  ; Self-refential GEPs can occur in dead code.
+  %incdec.ptr = getelementptr inbounds i32* %incdec.ptr, i64 1
+  ; CHECK: %incdec.ptr = getelementptr inbounds i32* %incdec.ptr
+  %l = load i32* %incdec.ptr
+  br label %alive
+
+alive:
+  ret void
+}