[llvm] r191644 - ObjectSizeOffsetEvaluator: Don't run into infinite recursion if we have a cyclic GEP.

Benjamin Kramer benny.kra at googlemail.com
Sun Sep 29 12:39:13 PDT 2013


Author: d0k
Date: Sun Sep 29 14:39:13 2013
New Revision: 191644

URL: http://llvm.org/viewvc/llvm-project?rev=191644&view=rev
Log:
ObjectSizeOffsetEvaluator: Don't run into infinite recursion if we have a cyclic GEP.

Those can occur in dead code. PR17402.

Modified:
    llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
    llvm/trunk/test/Instrumentation/BoundsChecking/simple.ll

Modified: llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryBuiltins.cpp?rev=191644&r1=191643&r2=191644&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryBuiltins.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryBuiltins.cpp Sun Sep 29 14:39:13 2013
@@ -634,13 +634,15 @@ SizeOffsetEvalType ObjectSizeOffsetEvalu
   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);

Modified: llvm/trunk/test/Instrumentation/BoundsChecking/simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/BoundsChecking/simple.ll?rev=191644&r1=191643&r2=191644&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/BoundsChecking/simple.ll (original)
+++ llvm/trunk/test/Instrumentation/BoundsChecking/simple.ll Sun Sep 29 14:39:13 2013
@@ -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
+}





More information about the llvm-commits mailing list