diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-01-21 13:54:51 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-01-21 13:54:51 -0800 |
commit | 572bba39dcadf613afa586320d83aa3fc48a3cf8 (patch) | |
tree | 02a6ca36459cdc7455b52f4e5f105b9cd0a72519 /lib/Transforms | |
parent | baa51c9f0de42aa1194a5b93400b82f3b071bca1 (diff) |
support building projects with both setjmp and c++ exceptions, by avoiding modifying setjmp|longjmp in the exceptions lowering code
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/NaCl/LowerEmExceptionsPass.cpp | 20 | ||||
-rw-r--r-- | lib/Transforms/NaCl/PNaClABISimplify.cpp | 4 |
2 files changed, 8 insertions, 16 deletions
diff --git a/lib/Transforms/NaCl/LowerEmExceptionsPass.cpp b/lib/Transforms/NaCl/LowerEmExceptionsPass.cpp index 27d9004bd1..e0ff54d0d0 100644 --- a/lib/Transforms/NaCl/LowerEmExceptionsPass.cpp +++ b/lib/Transforms/NaCl/LowerEmExceptionsPass.cpp @@ -84,7 +84,10 @@ INITIALIZE_PASS(LowerEmExceptions, "loweremexceptions", bool canThrow(Value *V) { if (Function *F = dyn_cast<Function>(V)) { // intrinsics and some emscripten builtins cannot throw - if (F->isIntrinsic() || F->getName().startswith("emscripten_asm_")) return false; + if (F->isIntrinsic()) return false; + StringRef Name = F->getName(); + if (Name.startswith("emscripten_asm_")) return false; + if (Name == "setjmp" || Name == "longjmp") return false; // leave setjmp and longjmp (mostly) alone, we process them properly later return true; } return true; // not a function, so an indirect call - can throw, we can't tell @@ -93,15 +96,6 @@ bool canThrow(Value *V) { bool LowerEmExceptions::runOnModule(Module &M) { TheModule = &M; - // Checks - - Function *Setjmp = TheModule->getFunction("setjmp"); - if (Setjmp) { - for (Instruction::use_iterator UI = Setjmp->use_begin(), UE = Setjmp->use_end(); UI != UE; ++UI) { - assert(0 && "emscripten fastcomp does not support c++ exceptions and setjmp/longjmp together yet. disable exceptions (-s DISABLE_EXCEPTION_CATCHING=1) or remove setjmp from your code, for now, or use the original emscripten compiler instead of fastcomp."); - } - } - // Add functions Type *i32 = Type::getInt32Ty(M.getContext()); @@ -145,6 +139,8 @@ bool LowerEmExceptions::runOnModule(Module &M) { for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { // check terminator for invokes if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) { + LandingPads.insert(II->getLandingPadInst()); + bool NeedInvoke = canThrow(II->getCalledValue()); if (NeedInvoke) { @@ -166,8 +162,6 @@ bool LowerEmExceptions::runOnModule(Module &M) { // Insert a branch based on the postInvoke BranchInst::Create(II->getUnwindDest(), II->getNormalDest(), Post1, II); - - LandingPads.insert(II->getLandingPadInst()); } else { // This can't throw, and we don't need this invoke, just replace it with a call+branch SmallVector<Value*,16> CallArgs(II->op_begin(), II->op_end() - 3); @@ -184,8 +178,6 @@ bool LowerEmExceptions::runOnModule(Module &M) { // Remove any PHI node entries from the exception destination. II->getUnwindDest()->removePredecessor(BB); - - LandingPads.insert(II->getLandingPadInst()); } Changed = true; diff --git a/lib/Transforms/NaCl/PNaClABISimplify.cpp b/lib/Transforms/NaCl/PNaClABISimplify.cpp index f73d6c1784..6a0aeae700 100644 --- a/lib/Transforms/NaCl/PNaClABISimplify.cpp +++ b/lib/Transforms/NaCl/PNaClABISimplify.cpp @@ -47,10 +47,10 @@ void llvm::PNaClABISimplifyAddPreOptPasses(PassManager &PM) { PM.add(createLowerInvokePass()); // Remove landingpad blocks made unreachable by LowerInvoke. PM.add(createCFGSimplificationPass()); - - PM.add(createLowerEmSetjmpPass()); // XXX EMSCRIPTEN . Note, only if no exceptions } + PM.add(createLowerEmSetjmpPass()); // XXX EMSCRIPTEN . Note, only if no exceptions + #if 0 // EMSCRIPTEN: we allow arbitrary symbols to be preserved // Internalize all symbols in the module except _start, which is the only // symbol a stable PNaCl pexe is allowed to export. |