summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-01-13 23:54:42 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-01-14 20:38:10 +0100
commit652cd7c1007aa5a13ad9864fadc939c5710c5199 (patch)
tree1d37766aea8c5632e572fe80001087a52a63fd77 /llvm/lib/Transforms
parentfa632340938cc02e03262e1318cb06b34c32f5fe (diff)
downloadbcm5719-llvm-652cd7c1007aa5a13ad9864fadc939c5710c5199.tar.gz
bcm5719-llvm-652cd7c1007aa5a13ad9864fadc939c5710c5199.zip
[InstCombine] Fix user iterator invalidation in bitcast of phi transform
This fixes the issue encountered in D71164. Instead of using a range-based for, manually iterate over the users and advance the iterator beforehand, so we do not skip any users due to iterator invalidation. Differential Revision: https://reviews.llvm.org/D72657
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 3ba56bbe53e..f6c7bb5d447 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2344,7 +2344,10 @@ Instruction *InstCombiner::optimizeBitCastFromPhi(CastInst &CI, PHINode *PN) {
Instruction *RetVal = nullptr;
for (auto *OldPN : OldPhiNodes) {
PHINode *NewPN = NewPNodes[OldPN];
- for (User *V : OldPN->users()) {
+ for (auto It = OldPN->user_begin(), End = OldPN->user_end(); It != End; ) {
+ User *V = *It;
+ // We may remove this user, advance to avoid iterator invalidation.
+ ++It;
if (auto *SI = dyn_cast<StoreInst>(V)) {
assert(SI->isSimple() && SI->getOperand(0) == OldPN);
Builder.SetInsertPoint(SI);
OpenPOWER on IntegriCloud