summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/PruneEH.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-02-08 21:15:59 +0000
committerChris Lattner <sabre@nondot.org>2004-02-08 21:15:59 +0000
commite0def04e430d741daa48f69b05cfe132adb6db11 (patch)
tree1cb1d68a32d8eb166eb6c0cb7eb2d1203f2c34a3 /lib/Transforms/IPO/PruneEH.cpp
parentedb1cf0c19dc0d155a2c0d35c099dd63a182fcc2 (diff)
downloadllvm-e0def04e430d741daa48f69b05cfe132adb6db11.tar.gz
llvm-e0def04e430d741daa48f69b05cfe132adb6db11.tar.bz2
llvm-e0def04e430d741daa48f69b05cfe132adb6db11.tar.xz
Fix PR225: [pruneeh] -pruneeh pass removes invoke instructions it shouldn't
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11200 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/PruneEH.cpp')
-rw-r--r--lib/Transforms/IPO/PruneEH.cpp42
1 files changed, 32 insertions, 10 deletions
diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp
index 70d0204b55..7c0a73e19b 100644
--- a/lib/Transforms/IPO/PruneEH.cpp
+++ b/lib/Transforms/IPO/PruneEH.cpp
@@ -51,19 +51,41 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
// obviously the SCC might throw.
//
bool SCCMightThrow = false;
- for (unsigned i = 0, e = SCC.size(); i != e; ++i)
- if (!DoesNotThrow.count(SCC[i]) && // Calls maybe throwing fn
- // Make sure this is not one of the fn's in the SCC.
- std::find(SCC.begin(), SCC.end(), SCC[i]) == SCC.end()) {
- SCCMightThrow = true; break;
- } else if (Function *F = SCC[i]->getFunction())
+ for (unsigned i = 0, e = SCC.size(); !SCCMightThrow && i != e; ++i)
+ if (Function *F = SCC[i]->getFunction())
if (F->isExternal()) {
- SCCMightThrow = true; break;
+ SCCMightThrow = true;
} else {
- for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
- if (isa<UnwindInst>(I->getTerminator())) { // Uses unwind!
- SCCMightThrow = true; break;
+ // Check to see if this function performs an unwind or calls an
+ // unwinding function.
+ for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
+ if (isa<UnwindInst>(BB->getTerminator())) { // Uses unwind!
+ SCCMightThrow = true;
+ break;
}
+
+ // Invoke instructions don't allow unwinding to continue, so we are
+ // only interested in call instructions.
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+ if (CallInst *CI = dyn_cast<CallInst>(I)) {
+ if (Function *Callee = CI->getCalledFunction()) {
+ CallGraphNode *CalleeNode = CG[Callee];
+ // If the callee is outside our current SCC, or if it is not
+ // known to throw, then we might throw also.
+ if (std::find(SCC.begin(), SCC.end(), CalleeNode) == SCC.end()&&
+ !DoesNotThrow.count(CalleeNode)) {
+ SCCMightThrow = true;
+ break;
+ }
+
+ } else {
+ // Indirect call, it might throw.
+ SCCMightThrow = true;
+ break;
+ }
+ }
+ if (SCCMightThrow) break;
+ }
}
bool MadeChange = false;