diff options
author | Justin Lebar <jlebar@google.com> | 2016-11-29 21:49:02 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2016-11-29 21:49:02 +0000 |
commit | 96e29155749c920cdc17219cd57e0d3f08dcc923 (patch) | |
tree | 84ba7f7844d7b0c2e53544a140e2d1d649cb3510 /llvm/lib | |
parent | f9d60f00e516358a33dc1b0e65a7ce6dd94cc188 (diff) | |
download | bcm5719-llvm-96e29155749c920cdc17219cd57e0d3f08dcc923.tar.gz bcm5719-llvm-96e29155749c920cdc17219cd57e0d3f08dcc923.zip |
[StructurizeCFG] Fix infinite loop in rebuildSSA.
Michel Dänzer reported that r288051, "[StructurizeCFG] Use range-based
for loops", introduced a bug into rebuildSSA, wherein we were iterating
over an instruction's use list while modifying it, without taking care
to do this correctly.
llvm-svn: 288200
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/StructurizeCFG.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp index ca9b0b85cc5..fa2235e8439 100644 --- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp +++ b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp @@ -834,7 +834,10 @@ void StructurizeCFG::rebuildSSA() { for (BasicBlock *BB : ParentRegion->blocks()) for (Instruction &I : *BB) { bool Initialized = false; - for (Use &U : I.uses()) { + // We may modify the use list as we iterate over it, so be careful to + // compute the next element in the use list at the top of the loop. + for (auto UI = I.use_begin(), E = I.use_end(); UI != E;) { + Use &U = *UI++; Instruction *User = cast<Instruction>(U.getUser()); if (User->getParent() == BB) { continue; |