From: Chandler Carruth Date: Mon, 4 Jan 2016 07:23:12 +0000 (+0000) Subject: Fix a horrible infloop in value tracking in the face of dead code. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=ab99ec2ce71849d1976ac7497f671375a1900e97 Fix a horrible infloop in value tracking in the face of dead code. Amazingly, we just never triggered this without: 1) Moving code around for MetadataTracking so that a certain *different* amount of inlining occurs in the per-TU compile step. 2) Then you LTO opt or clang with a bootstrap, and get inlining, loop opts, and GVN line up everything *just* right. I don't really know how we didn't hit this before. We really need to be fuzz testing stuff, it shouldn't be hard to trigger. I'm working on crafting a reduced nice test case, and will submit that when I have it, but I want to get LTO build bots going again. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256735 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index d6a78411388..7e56f1ebe60 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -2830,7 +2830,12 @@ Value *llvm::GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL) { unsigned BitWidth = DL.getPointerTypeSizeInBits(Ptr->getType()); APInt ByteOffset(BitWidth, 0); - while (1) { + + // We walk up the defs but use a visited set to handle unreachable code. In + // that case, we stop after accumulating the cycle once (not that it + // matters). + SmallPtrSet Visited; + while (Visited.insert(Ptr).second) { if (Ptr->getType()->isVectorTy()) break;