SimplifyCFG: Avoid dereferencing end()
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 16 Aug 2016 23:57:56 +0000 (23:57 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 16 Aug 2016 23:57:56 +0000 (23:57 +0000)
When comparing a User* to a BasicBlock::iterator in
passingValueIsAlwaysUndefined, don't dereference the iterator in case it
is end().

llvm-svn: 278872

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

index e88d7eb..0120adc 100644 (file)
@@ -5499,7 +5499,10 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I) {
 
     // Now make sure that there are no instructions in between that can alter
     // control flow (eg. calls)
-    for (BasicBlock::iterator i = ++BasicBlock::iterator(I); &*i != Use; ++i)
+    for (BasicBlock::iterator
+             i = ++BasicBlock::iterator(I),
+             UI = BasicBlock::iterator(dyn_cast<Instruction>(Use));
+         i != UI; ++i)
       if (i == I->getParent()->end() || i->mayHaveSideEffects())
         return false;