aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-11-06 19:18:49 +0000
committerChris Lattner <sabre@nondot.org>2003-11-06 19:18:49 +0000
commitd7222ec801618a1e22285832e7101de3dbc126d0 (patch)
tree2d3e118c7bee155895d90040e3e628efe108b88a
parent6d7aad1dd57b7928c3ffde779bf958ded3145d2a (diff)
downloadexternal_llvm-d7222ec801618a1e22285832e7101de3dbc126d0.zip
external_llvm-d7222ec801618a1e22285832e7101de3dbc126d0.tar.gz
external_llvm-d7222ec801618a1e22285832e7101de3dbc126d0.tar.bz2
Fix bug: PR93
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9752 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/LowerSetJmp.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp
index 01ff046..abbc2c9 100644
--- a/lib/Transforms/IPO/LowerSetJmp.cpp
+++ b/lib/Transforms/IPO/LowerSetJmp.cpp
@@ -41,6 +41,7 @@
#include "llvm/Pass.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/InstVisitor.h"
+#include "llvm/Transforms/Utils/DemoteRegToStack.h"
#include "Support/DepthFirstIterator.h"
#include "Support/Statistic.h"
#include "Support/StringExtras.h"
@@ -377,6 +378,34 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
SetJmpIDMap[Func]++), 0),
"", Inst);
+ // We are guaranteed that there are no values live across basic blocks
+ // (because we are "not in SSA form" yet), but there can still be values live
+ // in basic blocks. Because of this, splitting the setjmp block can cause
+ // values above the setjmp to not dominate uses which are after the setjmp
+ // call. For all of these occasions, we must spill the value to the stack.
+ //
+ std::set<Instruction*> InstrsAfterCall;
+
+ // The call is probably very close to the end of the basic block, for the
+ // common usage pattern of: 'if (setjmp(...))', so keep track of the
+ // instructions after the call.
+ for (BasicBlock::iterator I = ++BasicBlock::iterator(Inst), E = ABlock->end();
+ I != E; ++I)
+ InstrsAfterCall.insert(I);
+
+ for (BasicBlock::iterator II = ABlock->begin();
+ II != BasicBlock::iterator(Inst); ++II)
+ // Loop over all of the uses of instruction. If any of them are after the
+ // call, "spill" the value to the stack.
+ for (Value::use_iterator UI = II->use_begin(), E = II->use_end();
+ UI != E; ++UI)
+ if (cast<Instruction>(*UI)->getParent() != ABlock ||
+ InstrsAfterCall.count(cast<Instruction>(*UI))) {
+ DemoteRegToStack(*II);
+ break;
+ }
+ InstrsAfterCall.clear();
+
// Change the setjmp call into a branch statement. We'll remove the
// setjmp call in a little bit. No worries.
BasicBlock* SetJmpContBlock = ABlock->splitBasicBlock(Inst);