diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-01-27 16:58:33 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-01-27 16:58:47 -0800 |
commit | d633d6226fafbc3f8491a36a6b90a3ef0b229d7e (patch) | |
tree | 8e02fbee1f58299388a31658ddacb79d0a9ccfe8 | |
parent | f2d68ac5c26a6f6cd97c28c8f9b2a24ea94f44c2 (diff) |
coordinate exception handling with setjmp - if exception handling code generate a pre|postinvoke, use those for setjmp as well
-rw-r--r-- | lib/Transforms/NaCl/LowerEmSetjmp.cpp | 17 | ||||
-rw-r--r-- | lib/Transforms/NaCl/PNaClABISimplify.cpp | 2 |
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/Transforms/NaCl/LowerEmSetjmp.cpp b/lib/Transforms/NaCl/LowerEmSetjmp.cpp index 495170ecf9..77d770d11c 100644 --- a/lib/Transforms/NaCl/LowerEmSetjmp.cpp +++ b/lib/Transforms/NaCl/LowerEmSetjmp.cpp @@ -168,12 +168,21 @@ bool LowerEmSetjmp::runOnModule(Module &M) { if (V == PrepSetjmp || V == EmSetjmp || V == CheckLongjmp || V == GetLongjmpResult || V == PreInvoke || V == PostInvoke) continue; if (Function *CF = dyn_cast<Function>(V)) if (CF->isIntrinsic()) continue; // TODO: proper analysis of what can actually longjmp. Currently we assume anything but setjmp can. - // This may longjmp, so we need to check if it did. Split at that point. + // This may longjmp, so we need to check if it did. Split at that point, and + // envelop the call in pre/post invoke, if we need to + CallInst *After; + Instruction *Check = NULL; + if (Iter != E && (After = dyn_cast<CallInst>(Iter)) && After->getCalledValue() == PostInvoke) { + // use the pre|postinvoke that exceptions lowering already made + Check = Iter++; + } BasicBlock *Tail = SplitBlock(BB, Iter, this); // Iter already points to the next instruction, as we need - // envelop the call in pre/post invoke - CallInst::Create(PreInvoke, "", CI); TerminatorInst *TI = BB->getTerminator(); - CallInst *Check = CallInst::Create(PostInvoke, "", TI); // CI is at the end of the block + if (!Check) { + // no existing pre|postinvoke, create our own + CallInst::Create(PreInvoke, "", CI); + Check = CallInst::Create(PostInvoke, "", TI); // CI is at the end of the block + } // We need to replace the terminator in Tail - SplitBlock makes BB go straight to Tail, we need to check if a longjmp occurred, and // go to the right setjmp-tail if so diff --git a/lib/Transforms/NaCl/PNaClABISimplify.cpp b/lib/Transforms/NaCl/PNaClABISimplify.cpp index 6a0aeae700..5689556f21 100644 --- a/lib/Transforms/NaCl/PNaClABISimplify.cpp +++ b/lib/Transforms/NaCl/PNaClABISimplify.cpp @@ -49,7 +49,7 @@ void llvm::PNaClABISimplifyAddPreOptPasses(PassManager &PM) { PM.add(createCFGSimplificationPass()); } - PM.add(createLowerEmSetjmpPass()); // XXX EMSCRIPTEN . Note, only if no exceptions + PM.add(createLowerEmSetjmpPass()); // XXX EMSCRIPTEN #if 0 // EMSCRIPTEN: we allow arbitrary symbols to be preserved // Internalize all symbols in the module except _start, which is the only |