[llvm] r271278 - Do not modify a std::vector while looping it.
Yaron Keren via llvm-commits
llvm-commits at lists.llvm.org
Tue May 31 06:45:08 PDT 2016
Author: yrnkrn
Date: Tue May 31 08:45:05 2016
New Revision: 271278
URL: http://llvm.org/viewvc/llvm-project?rev=271278&view=rev
Log:
Do not modify a std::vector while looping it.
Introduced in r271244, this is probably undefined behaviour and asserts when
compiled with Visual C++ debug mode.
On further note, the loop is quadratic with regard to the number of successors
since removeSuccessor is linear and could probably be modified to linear time.
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=271278&r1=271277&r2=271278&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Tue May 31 08:45:05 2016
@@ -23841,8 +23841,12 @@ X86TargetLowering::EmitSjLjDispatchBlock
Subtarget.getRegisterInfo()->getCalleeSavedRegs(MF);
for (MachineBasicBlock *MBB : InvokeBBs) {
// Remove the landing pad successor from the invoke block and replace it
- // with the new dispatch block
- for (auto MBBS : make_range(MBB->succ_rbegin(), MBB->succ_rend())) {
+ // with the new dispatch block.
+ // Keep a copy of Successors since it's modified inside the loop.
+ SmallVector<MachineBasicBlock *, 8> Successors(MBB->succ_rbegin(),
+ MBB->succ_rend());
+ // FIXME: Avoid quadratic complexity.
+ for (auto MBBS : Successors) {
if (MBBS->isEHPad()) {
MBB->removeSuccessor(MBBS);
MBBLPads.push_back(MBBS);
More information about the llvm-commits
mailing list