diff options
author | Dan Gohman <dan433584@gmail.com> | 2016-01-06 18:29:35 +0000 |
---|---|---|
committer | Dan Gohman <dan433584@gmail.com> | 2016-01-06 18:29:35 +0000 |
commit | 8f59cf756f3903586b7ab549b0ab3c377cffe33d (patch) | |
tree | 564854f105d1d799a938f0493904a3ed18200921 /llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp | |
parent | eac06368053bd1e7082b5ab7efcd6f9c7014d589 (diff) | |
download | llvm-8f59cf756f3903586b7ab549b0ab3c377cffe33d.zip llvm-8f59cf756f3903586b7ab549b0ab3c377cffe33d.tar.gz llvm-8f59cf756f3903586b7ab549b0ab3c377cffe33d.tar.bz2 |
[WebAssembly] Don't use range-based loop for a list that's being modified
The first instruction in a block is what the rend() iterator points to, so
if it moves, we need to re-evaluate rend() so that we continue to iterate
through the rest of the instructions.
llvm-svn: 256953
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp index 89ef5cd..537c147 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp @@ -147,8 +147,10 @@ bool WebAssemblyRegStackify::runOnMachineFunction(MachineFunction &MF) { // block boundaries, and the blocks aren't ordered so the block visitation // order isn't significant, but we may want to change this in the future. for (MachineBasicBlock &MBB : MF) { - for (MachineInstr &MI : reverse(MBB)) { - MachineInstr *Insert = &MI; + // Don't use a range-based for loop, because we modify the list as we're + // iterating over it and the end iterator may change. + for (auto MII = MBB.rbegin(); MII != MBB.rend(); ++MII) { + MachineInstr *Insert = &*MII; // Don't nest anything inside a phi. if (Insert->getOpcode() == TargetOpcode::PHI) break; @@ -221,7 +223,7 @@ bool WebAssemblyRegStackify::runOnMachineFunction(MachineFunction &MF) { Insert = Def; } if (AnyStackified) - ImposeStackOrdering(&MI); + ImposeStackOrdering(&*MII); } } |