summaryrefslogtreecommitdiff
path: root/lib/CodeGen/GlobalMerge.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2016-10-19 19:56:22 +0000
committerReid Kleckner <rnk@google.com>2016-10-19 19:56:22 +0000
commit3fd59c99d0bf811bdb1b7862073b594504d07c87 (patch)
tree8b746faa7acfdc92fbc0629613495b93939ad69a /lib/CodeGen/GlobalMerge.cpp
parent86fff1f8179606f2b9ec3996e539dd5d170e525b (diff)
[GlobalMerge] Handle non-landingpad EH pads
This code crashed on funclet-style EH instructions such as catchpad, catchswitch, and cleanuppad. Just treat all EH pad instructions equivalently and avoid merging the globals they reference through any use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284633 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/GlobalMerge.cpp')
-rw-r--r--lib/CodeGen/GlobalMerge.cpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/lib/CodeGen/GlobalMerge.cpp b/lib/CodeGen/GlobalMerge.cpp
index c7609e9a4aa..2d9e0938fea 100644
--- a/lib/CodeGen/GlobalMerge.cpp
+++ b/lib/CodeGen/GlobalMerge.cpp
@@ -502,22 +502,18 @@ void GlobalMerge::collectUsedGlobalVariables(Module &M) {
void GlobalMerge::setMustKeepGlobalVariables(Module &M) {
collectUsedGlobalVariables(M);
- for (Module::iterator IFn = M.begin(), IEndFn = M.end(); IFn != IEndFn;
- ++IFn) {
- for (Function::iterator IBB = IFn->begin(), IEndBB = IFn->end();
- IBB != IEndBB; ++IBB) {
- // Follow the invoke link to find the landing pad instruction
- const InvokeInst *II = dyn_cast<InvokeInst>(IBB->getTerminator());
- if (!II) continue;
-
- const LandingPadInst *LPInst = II->getUnwindDest()->getLandingPadInst();
- // Look for globals in the clauses of the landing pad instruction
- for (unsigned Idx = 0, NumClauses = LPInst->getNumClauses();
- Idx != NumClauses; ++Idx)
+ for (Function &F : M) {
+ for (BasicBlock &BB : F) {
+ Instruction *Pad = BB.getFirstNonPHI();
+ if (!Pad->isEHPad())
+ continue;
+
+ // Keep globals used by landingpads and catchpads.
+ for (const Use &U : Pad->operands()) {
if (const GlobalVariable *GV =
- dyn_cast<GlobalVariable>(LPInst->getClause(Idx)
- ->stripPointerCasts()))
+ dyn_cast<GlobalVariable>(U->stripPointerCasts()))
MustKeepGlobalVariables.insert(GV);
+ }
}
}
}