[Loads] Properly populate the visited set in isDereferenceableAndAlignedPointer
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 31 Aug 2016 03:22:32 +0000 (03:22 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 31 Aug 2016 03:22:32 +0000 (03:22 +0000)
There were paths where we wouldn't populate the visited set, causing us
to recurse forever if an SSA variable was defined in terms of itself.

This fixes PR30210.

llvm-svn: 280191

llvm/lib/Analysis/Loads.cpp

index 4837ccf..af7ccb9 100644 (file)
@@ -55,6 +55,10 @@ static bool isDereferenceableAndAlignedPointer(
     const Value *V, unsigned Align, const APInt &Size, const DataLayout &DL,
     const Instruction *CtxI, const DominatorTree *DT,
     SmallPtrSetImpl<const Value *> &Visited) {
+  // Already visited?  Bail out, we've likely hit unreachable code.
+  if (!Visited.insert(V).second)
+    return false;
+
   // Note that it is not safe to speculate into a malloc'd region because
   // malloc may return null.
 
@@ -87,8 +91,7 @@ static bool isDereferenceableAndAlignedPointer(
     // then the GEP (== Base + Offset == k_0 * Align + k_1 * Align) is also
     // aligned to Align bytes.
 
-    return Visited.insert(Base).second &&
-           isDereferenceableAndAlignedPointer(Base, Align, Offset + Size, DL,
+    return isDereferenceableAndAlignedPointer(Base, Align, Offset + Size, DL,
                                               CtxI, DT, Visited);
   }