aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-02-13 18:34:44 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-02-13 18:34:44 -0800
commit68dd4be42198fae720e6c7a343e4704124bf87d5 (patch)
treec09663df4875ea47974049729545ecff68c3a81f
parent51b1fee13ef85ff7d0c5d73ea902b8e0d6c000e3 (diff)
erase more carefully in setjmp lowering
-rw-r--r--lib/Transforms/NaCl/LowerEmSetjmp.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Transforms/NaCl/LowerEmSetjmp.cpp b/lib/Transforms/NaCl/LowerEmSetjmp.cpp
index a3a0c8dc9a..469bf02daf 100644
--- a/lib/Transforms/NaCl/LowerEmSetjmp.cpp
+++ b/lib/Transforms/NaCl/LowerEmSetjmp.cpp
@@ -199,6 +199,7 @@ bool LowerEmSetjmp::runOnModule(Module &M) {
typedef std::vector<PHINode*> Phis;
typedef std::map<Function*, Phis> FunctionPhisMap;
FunctionPhisMap SetjmpOutputPhis;
+ std::vector<Instruction*> ToErase;
if (Setjmp) {
for (Instruction::use_iterator UI = Setjmp->use_begin(), UE = Setjmp->use_end(); UI != UE; ++UI) {
@@ -221,7 +222,7 @@ bool LowerEmSetjmp::runOnModule(Module &M) {
Args.push_back(CI->getArgOperand(0));
Args.push_back(ConstantInt::get(i32, P.size())); // our index in the function is our place in the array + 1
CallInst::Create(EmSetjmp, Args, "", CI);
- CI->eraseFromParent();
+ ToErase.push_back(CI);
} else {
errs() << **UI << "\n";
report_fatal_error("bad use of setjmp, should only call it");
@@ -282,7 +283,7 @@ bool LowerEmSetjmp::runOnModule(Module &M) {
SI->addCase(cast<ConstantInt>(ConstantInt::get(i32, i+1)), P[i]->getParent());
P[i]->addIncoming(LongjmpResult, BB);
}
- TI->eraseFromParent(); // new terminator is now the switch
+ ToErase.push_back(TI); // new terminator is now the switch
// we are splitting the block here, and must continue to find other calls in the block - which is now split. so continue
// to traverse in the Tail
@@ -296,6 +297,10 @@ bool LowerEmSetjmp::runOnModule(Module &M) {
}
}
+ for (int i = 0; i < ToErase.size(); i++) {
+ ToErase[i]->eraseFromParent();
+ }
+
// Finally, our modifications to the cfg can break dominance of SSA variables. For example,
// if (x()) { .. setjmp() .. }
// if (y()) { .. longjmp() .. }