Skip to content

Commit

Permalink
[Loads] Properly populate the visited set in isDereferenceableAndAlig…
Browse files Browse the repository at this point in the history
…nedPointer

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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280191 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
majnemer committed Aug 31, 2016
1 parent 982b9c9 commit 8b6ce01
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/Analysis/Loads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 8b6ce01

Please sign in to comment.