diff options
author | Reid Kleckner <rnk@google.com> | 2016-10-19 19:56:22 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2016-10-19 19:56:22 +0000 |
commit | f8d1d12fef56d99542ea1766812b2cfe45583c0c (patch) | |
tree | 92b29ddfc35199b5a2f9fb8b200c566bf7371a1a /llvm/lib/CodeGen | |
parent | 5c6ef754851b891ecfc685e9f1394d98569b5c8b (diff) | |
download | bcm5719-llvm-f8d1d12fef56d99542ea1766812b2cfe45583c0c.tar.gz bcm5719-llvm-f8d1d12fef56d99542ea1766812b2cfe45583c0c.zip |
[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.
llvm-svn: 284633
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/GlobalMerge.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp index c7609e9a4aa..2d9e0938fea 100644 --- a/llvm/lib/CodeGen/GlobalMerge.cpp +++ b/llvm/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); + } } } } |