/// \brief Returns true if this personality function catches asynchronous
/// exceptions.
- bool isAsynchronousEHPersonality(EHPersonality Pers);
+ inline bool isAsynchronousEHPersonality(EHPersonality Pers) {
+ // The two SEH personality functions can catch asynch exceptions. We assume
+ // unknown personalities don't catch asynch exceptions.
+ switch (Pers) {
+ case EHPersonality::MSVC_X86SEH:
+ case EHPersonality::MSVC_Win64SEH:
+ return true;
+ default: return false;
+ }
+ llvm_unreachable("invalid enum");
+ }
+
+ /// \brief Returns true if this is an MSVC personality function.
+ inline bool isMSVCEHPersonality(EHPersonality Pers) {
+ // The two SEH personality functions can catch asynch exceptions. We assume
+ // unknown personalities don't catch asynch exceptions.
+ switch (Pers) {
+ case EHPersonality::MSVC_CXX:
+ case EHPersonality::MSVC_X86SEH:
+ case EHPersonality::MSVC_Win64SEH:
+ return true;
+ default: return false;
+ }
+ llvm_unreachable("invalid enum");
+ }
bool canSimplifyInvokeNoUnwind(const InvokeInst *II);
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/CFG.h"
+#include "llvm/Analysis/LibCallSemantics.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
bool DwarfEHPrepare::InsertUnwindResumeCalls(Function &Fn) {
SmallVector<ResumeInst*, 16> Resumes;
SmallVector<LandingPadInst*, 16> CleanupLPads;
+ bool FoundLP = false;
for (BasicBlock &BB : Fn) {
if (auto *RI = dyn_cast<ResumeInst>(BB.getTerminator()))
Resumes.push_back(RI);
- if (auto *LP = BB.getLandingPadInst())
+ if (auto *LP = BB.getLandingPadInst()) {
if (LP->isCleanup())
CleanupLPads.push_back(LP);
+ // Check the personality on the first landingpad. Don't do anything if
+ // it's for MSVC.
+ if (!FoundLP) {
+ FoundLP = true;
+ EHPersonality Pers = classifyEHPersonality(LP->getPersonalityFn());
+ if (isMSVCEHPersonality(Pers))
+ return false;
+ }
+ }
}
if (Resumes.empty())
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/Analysis/LibCallSemantics.h"
-#include "llvm/Analysis/TargetTransformInfo.h"
-#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
typedef DenseMap<const BasicBlock *, CleanupHandler *> CleanupHandlerMapTy;
class WinEHPrepare : public FunctionPass {
- std::unique_ptr<FunctionPass> DwarfPrepare;
-
public:
static char ID; // Pass identification, replacement for typeid.
WinEHPrepare(const TargetMachine *TM = nullptr)
- : FunctionPass(ID), DwarfPrepare(createDwarfEHPass(TM)) {}
+ : FunctionPass(ID) {}
bool runOnFunction(Function &Fn) override;
} // end anonymous namespace
char WinEHPrepare::ID = 0;
-INITIALIZE_TM_PASS_BEGIN(WinEHPrepare, "winehprepare",
- "Prepare Windows exceptions", false, false)
-INITIALIZE_PASS_DEPENDENCY(DwarfEHPrepare)
-INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
-INITIALIZE_TM_PASS_END(WinEHPrepare, "winehprepare",
- "Prepare Windows exceptions", false, false)
+INITIALIZE_TM_PASS(WinEHPrepare, "winehprepare", "Prepare Windows exceptions",
+ false, false)
FunctionPass *llvm::createWinEHPass(const TargetMachine *TM) {
return new WinEHPrepare(TM);
}
-static bool isMSVCPersonality(EHPersonality Pers) {
- return Pers == EHPersonality::MSVC_Win64SEH ||
- Pers == EHPersonality::MSVC_CXX;
-}
-
bool WinEHPrepare::runOnFunction(Function &Fn) {
SmallVector<LandingPadInst *, 4> LPads;
SmallVector<ResumeInst *, 4> Resumes;
// Classify the personality to see what kind of preparation we need.
EHPersonality Pers = classifyEHPersonality(LPads.back()->getPersonalityFn());
- // Delegate through to the DWARF pass if this is unrecognized.
- if (!isMSVCPersonality(Pers)) {
- if (!DwarfPrepare->getResolver()) {
- // Build an AnalysisResolver with the analyses needed by DwarfEHPrepare.
- // It will take ownership of the AnalysisResolver.
- assert(getResolver());
- auto *AR = new AnalysisResolver(getResolver()->getPMDataManager());
- AR->addAnalysisImplsPair(
- &TargetTransformInfoWrapperPass::ID,
- getResolver()->findImplPass(&TargetTransformInfoWrapperPass::ID));
- AR->addAnalysisImplsPair(
- &DominatorTreeWrapperPass::ID,
- getResolver()->findImplPass(&DominatorTreeWrapperPass::ID));
- DwarfPrepare->setResolver(AR);
- }
-
- return DwarfPrepare->runOnFunction(Fn);
- }
+ // Do nothing if this is not an MSVC personality.
+ if (!isMSVCEHPersonality(Pers))
+ return false;
// FIXME: This only returns true if the C++ EH handlers were outlined.
// When that code is complete, it should always return whatever
}
bool WinEHPrepare::doFinalization(Module &M) {
- return DwarfPrepare->doFinalization(M);
+ return false;
}
-void WinEHPrepare::getAnalysisUsage(AnalysisUsage &AU) const {
- DwarfPrepare->getAnalysisUsage(AU);
-}
+void WinEHPrepare::getAnalysisUsage(AnalysisUsage &AU) const {}
bool WinEHPrepare::prepareCPPEHHandlers(
Function &F, SmallVectorImpl<LandingPadInst *> &LPads) {