From a90e51e10682e6c425364fea4ae9c154292ecf7b Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 31 Aug 2016 03:22:32 +0000 Subject: [PATCH] [Loads] Properly populate the visited set in isDereferenceableAndAlignedPointer 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp index 4837ccf..af7ccb9 100644 --- a/llvm/lib/Analysis/Loads.cpp +++ b/llvm/lib/Analysis/Loads.cpp @@ -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 &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); } -- 2.7.4