aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-01-19 19:21:16 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-01-19 19:21:16 -0800
commit3c965ad08d26d1245d23ea918183f2c2e62e8e9b (patch)
tree5c20569e9ca71caba5c3a6ce2b9dc075de036f5f /lib/Transforms
parente467883cf9af64d65b5aa13d02293a457ff08642 (diff)
setjmp fixes
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/NaCl/LowerEmSetjmp.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/Transforms/NaCl/LowerEmSetjmp.cpp b/lib/Transforms/NaCl/LowerEmSetjmp.cpp
index 21532f4efb..1f0bf75cd0 100644
--- a/lib/Transforms/NaCl/LowerEmSetjmp.cpp
+++ b/lib/Transforms/NaCl/LowerEmSetjmp.cpp
@@ -77,6 +77,7 @@ bool LowerEmSetjmp::runOnModule(Module &M) {
assert(Setjmp && Longjmp); // must see setjmp *and* longjmp if one of them is present
Type *i32 = Type::getInt32Ty(M.getContext());
+ Type *Void = Type::getVoidTy(M.getContext());
// Add functions
@@ -92,6 +93,9 @@ bool LowerEmSetjmp::runOnModule(Module &M) {
Function *CheckLongjmp = Function::Create(IntFunc, GlobalValue::ExternalLinkage, "emscripten_check_longjmp", TheModule);
Function *GetLongjmpResult = Function::Create(IntFunc, GlobalValue::ExternalLinkage, "emscripten_get_longjmp_result", TheModule);
+ FunctionType *VoidFunc = FunctionType::get(Void, false);
+ Function *PrepSetjmp = Function::Create(VoidFunc, GlobalValue::ExternalLinkage, "emscripten_prep_setjmp", TheModule);
+
// Process all callers of setjmp and longjmp. Start with setjmp.
typedef std::vector<PHINode*> Phis;
@@ -138,7 +142,7 @@ bool LowerEmSetjmp::runOnModule(Module &M) {
Function *F = I->first;
Phis& P = I->second;
- // FIXME: add prelude
+ CallInst::Create(PrepSetjmp, "", F->begin()->begin()); // FIXME: adding after other allocas might be better
// Add a basic block to "rethrow" a longjmp, that we caught but is not for us
// XXX we should call longjmp here, with proper params! return only works if the caller checks for longjmping
@@ -154,7 +158,7 @@ bool LowerEmSetjmp::runOnModule(Module &M) {
CallInst *CI;
if ((CI = dyn_cast<CallInst>(I))) {
Value *V = CI->getCalledValue();
- if (V == EmSetjmp || V == CheckLongjmp || V == GetLongjmpResult) continue;
+ if (V == PrepSetjmp || V == EmSetjmp || V == CheckLongjmp || V == GetLongjmpResult) 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.