forked from OSchip/llvm-project
parent
8551d25fa9
commit
4dd0304e34
|
@ -1,391 +1,391 @@
|
||||||
//===-- WinEHPrepare - Prepare exception handling for code generation ---===//
|
//===-- WinEHPrepare - Prepare exception handling for code generation ---===//
|
||||||
//
|
//
|
||||||
// The LLVM Compiler Infrastructure
|
// The LLVM Compiler Infrastructure
|
||||||
//
|
//
|
||||||
// This file is distributed under the University of Illinois Open Source
|
// This file is distributed under the University of Illinois Open Source
|
||||||
// License. See LICENSE.TXT for details.
|
// License. See LICENSE.TXT for details.
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//
|
//
|
||||||
// This pass lowers LLVM IR exception handling into something closer to what the
|
// This pass lowers LLVM IR exception handling into something closer to what the
|
||||||
// backend wants. It snifs the personality function to see which kind of
|
// backend wants. It snifs the personality function to see which kind of
|
||||||
// preparation is necessary. If the personality function uses the Itanium LSDA,
|
// preparation is necessary. If the personality function uses the Itanium LSDA,
|
||||||
// this pass delegates to the DWARF EH preparation pass.
|
// this pass delegates to the DWARF EH preparation pass.
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/CodeGen/Passes.h"
|
#include "llvm/CodeGen/Passes.h"
|
||||||
#include "llvm/Analysis/LibCallSemantics.h"
|
#include "llvm/Analysis/LibCallSemantics.h"
|
||||||
#include "llvm/IR/Function.h"
|
#include "llvm/IR/Function.h"
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/Instructions.h"
|
#include "llvm/IR/Instructions.h"
|
||||||
#include "llvm/IR/IntrinsicInst.h"
|
#include "llvm/IR/IntrinsicInst.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/IR/PatternMatch.h"
|
#include "llvm/IR/PatternMatch.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Transforms/Utils/Cloning.h"
|
#include "llvm/Transforms/Utils/Cloning.h"
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace llvm::PatternMatch;
|
using namespace llvm::PatternMatch;
|
||||||
|
|
||||||
#define DEBUG_TYPE "winehprepare"
|
#define DEBUG_TYPE "winehprepare"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class WinEHPrepare : public FunctionPass {
|
class WinEHPrepare : public FunctionPass {
|
||||||
std::unique_ptr<FunctionPass> DwarfPrepare;
|
std::unique_ptr<FunctionPass> DwarfPrepare;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID; // Pass identification, replacement for typeid.
|
static char ID; // Pass identification, replacement for typeid.
|
||||||
WinEHPrepare(const TargetMachine *TM = nullptr)
|
WinEHPrepare(const TargetMachine *TM = nullptr)
|
||||||
: FunctionPass(ID), DwarfPrepare(createDwarfEHPass(TM)) {}
|
: FunctionPass(ID), DwarfPrepare(createDwarfEHPass(TM)) {}
|
||||||
|
|
||||||
bool runOnFunction(Function &Fn) override;
|
bool runOnFunction(Function &Fn) override;
|
||||||
|
|
||||||
bool doFinalization(Module &M) override;
|
bool doFinalization(Module &M) override;
|
||||||
|
|
||||||
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
||||||
|
|
||||||
const char *getPassName() const override {
|
const char *getPassName() const override {
|
||||||
return "Windows exception handling preparation";
|
return "Windows exception handling preparation";
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool prepareCPPEHHandlers(Function &F,
|
bool prepareCPPEHHandlers(Function &F,
|
||||||
SmallVectorImpl<LandingPadInst *> &LPads);
|
SmallVectorImpl<LandingPadInst *> &LPads);
|
||||||
bool outlineCatchHandler(Function *SrcFn, Constant *SelectorType,
|
bool outlineCatchHandler(Function *SrcFn, Constant *SelectorType,
|
||||||
LandingPadInst *LPad, StructType *EHDataStructTy);
|
LandingPadInst *LPad, StructType *EHDataStructTy);
|
||||||
};
|
};
|
||||||
|
|
||||||
class WinEHCatchDirector : public CloningDirector {
|
class WinEHCatchDirector : public CloningDirector {
|
||||||
public:
|
public:
|
||||||
WinEHCatchDirector(LandingPadInst *LPI, Value *Selector, Value *EHObj)
|
WinEHCatchDirector(LandingPadInst *LPI, Value *Selector, Value *EHObj)
|
||||||
: LPI(LPI), CurrentSelector(Selector->stripPointerCasts()), EHObj(EHObj),
|
: LPI(LPI), CurrentSelector(Selector->stripPointerCasts()), EHObj(EHObj),
|
||||||
SelectorIDType(Type::getInt32Ty(LPI->getContext())),
|
SelectorIDType(Type::getInt32Ty(LPI->getContext())),
|
||||||
Int8PtrType(Type::getInt8PtrTy(LPI->getContext())) {}
|
Int8PtrType(Type::getInt8PtrTy(LPI->getContext())) {}
|
||||||
virtual ~WinEHCatchDirector() {}
|
virtual ~WinEHCatchDirector() {}
|
||||||
|
|
||||||
CloningAction handleInstruction(ValueToValueMapTy &VMap,
|
CloningAction handleInstruction(ValueToValueMapTy &VMap,
|
||||||
const Instruction *Inst,
|
const Instruction *Inst,
|
||||||
BasicBlock *NewBB) override;
|
BasicBlock *NewBB) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LandingPadInst *LPI;
|
LandingPadInst *LPI;
|
||||||
Value *CurrentSelector;
|
Value *CurrentSelector;
|
||||||
Value *EHObj;
|
Value *EHObj;
|
||||||
Type *SelectorIDType;
|
Type *SelectorIDType;
|
||||||
Type *Int8PtrType;
|
Type *Int8PtrType;
|
||||||
|
|
||||||
const Value *ExtractedEHPtr;
|
const Value *ExtractedEHPtr;
|
||||||
const Value *ExtractedSelector;
|
const Value *ExtractedSelector;
|
||||||
const Value *EHPtrStoreAddr;
|
const Value *EHPtrStoreAddr;
|
||||||
const Value *SelectorStoreAddr;
|
const Value *SelectorStoreAddr;
|
||||||
};
|
};
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
char WinEHPrepare::ID = 0;
|
char WinEHPrepare::ID = 0;
|
||||||
INITIALIZE_TM_PASS(WinEHPrepare, "winehprepare", "Prepare Windows exceptions",
|
INITIALIZE_TM_PASS(WinEHPrepare, "winehprepare", "Prepare Windows exceptions",
|
||||||
false, false)
|
false, false)
|
||||||
|
|
||||||
FunctionPass *llvm::createWinEHPass(const TargetMachine *TM) {
|
FunctionPass *llvm::createWinEHPass(const TargetMachine *TM) {
|
||||||
return new WinEHPrepare(TM);
|
return new WinEHPrepare(TM);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isMSVCPersonality(EHPersonality Pers) {
|
static bool isMSVCPersonality(EHPersonality Pers) {
|
||||||
return Pers == EHPersonality::MSVC_Win64SEH ||
|
return Pers == EHPersonality::MSVC_Win64SEH ||
|
||||||
Pers == EHPersonality::MSVC_CXX;
|
Pers == EHPersonality::MSVC_CXX;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WinEHPrepare::runOnFunction(Function &Fn) {
|
bool WinEHPrepare::runOnFunction(Function &Fn) {
|
||||||
SmallVector<LandingPadInst *, 4> LPads;
|
SmallVector<LandingPadInst *, 4> LPads;
|
||||||
SmallVector<ResumeInst *, 4> Resumes;
|
SmallVector<ResumeInst *, 4> Resumes;
|
||||||
for (BasicBlock &BB : Fn) {
|
for (BasicBlock &BB : Fn) {
|
||||||
if (auto *LP = BB.getLandingPadInst())
|
if (auto *LP = BB.getLandingPadInst())
|
||||||
LPads.push_back(LP);
|
LPads.push_back(LP);
|
||||||
if (auto *Resume = dyn_cast<ResumeInst>(BB.getTerminator()))
|
if (auto *Resume = dyn_cast<ResumeInst>(BB.getTerminator()))
|
||||||
Resumes.push_back(Resume);
|
Resumes.push_back(Resume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No need to prepare functions that lack landing pads.
|
// No need to prepare functions that lack landing pads.
|
||||||
if (LPads.empty())
|
if (LPads.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Classify the personality to see what kind of preparation we need.
|
// Classify the personality to see what kind of preparation we need.
|
||||||
EHPersonality Pers = classifyEHPersonality(LPads.back()->getPersonalityFn());
|
EHPersonality Pers = classifyEHPersonality(LPads.back()->getPersonalityFn());
|
||||||
|
|
||||||
// Delegate through to the DWARF pass if this is unrecognized.
|
// Delegate through to the DWARF pass if this is unrecognized.
|
||||||
if (!isMSVCPersonality(Pers))
|
if (!isMSVCPersonality(Pers))
|
||||||
return DwarfPrepare->runOnFunction(Fn);
|
return DwarfPrepare->runOnFunction(Fn);
|
||||||
|
|
||||||
// FIXME: This only returns true if the C++ EH handlers were outlined.
|
// FIXME: This only returns true if the C++ EH handlers were outlined.
|
||||||
// When that code is complete, it should always return whatever
|
// When that code is complete, it should always return whatever
|
||||||
// prepareCPPEHHandlers returns.
|
// prepareCPPEHHandlers returns.
|
||||||
if (Pers == EHPersonality::MSVC_CXX && prepareCPPEHHandlers(Fn, LPads))
|
if (Pers == EHPersonality::MSVC_CXX && prepareCPPEHHandlers(Fn, LPads))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// FIXME: SEH Cleanups are unimplemented. Replace them with unreachable.
|
// FIXME: SEH Cleanups are unimplemented. Replace them with unreachable.
|
||||||
if (Resumes.empty())
|
if (Resumes.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (ResumeInst *Resume : Resumes) {
|
for (ResumeInst *Resume : Resumes) {
|
||||||
IRBuilder<>(Resume).CreateUnreachable();
|
IRBuilder<>(Resume).CreateUnreachable();
|
||||||
Resume->eraseFromParent();
|
Resume->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WinEHPrepare::doFinalization(Module &M) {
|
bool WinEHPrepare::doFinalization(Module &M) {
|
||||||
return DwarfPrepare->doFinalization(M);
|
return DwarfPrepare->doFinalization(M);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinEHPrepare::getAnalysisUsage(AnalysisUsage &AU) const {
|
void WinEHPrepare::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
DwarfPrepare->getAnalysisUsage(AU);
|
DwarfPrepare->getAnalysisUsage(AU);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WinEHPrepare::prepareCPPEHHandlers(
|
bool WinEHPrepare::prepareCPPEHHandlers(
|
||||||
Function &F, SmallVectorImpl<LandingPadInst *> &LPads) {
|
Function &F, SmallVectorImpl<LandingPadInst *> &LPads) {
|
||||||
// FIXME: Find all frame variable references in the handlers
|
// FIXME: Find all frame variable references in the handlers
|
||||||
// to populate the structure elements.
|
// to populate the structure elements.
|
||||||
SmallVector<Type *, 2> AllocStructTys;
|
SmallVector<Type *, 2> AllocStructTys;
|
||||||
AllocStructTys.push_back(Type::getInt32Ty(F.getContext())); // EH state
|
AllocStructTys.push_back(Type::getInt32Ty(F.getContext())); // EH state
|
||||||
AllocStructTys.push_back(Type::getInt8PtrTy(F.getContext())); // EH object
|
AllocStructTys.push_back(Type::getInt8PtrTy(F.getContext())); // EH object
|
||||||
StructType *EHDataStructTy =
|
StructType *EHDataStructTy =
|
||||||
StructType::create(F.getContext(), AllocStructTys,
|
StructType::create(F.getContext(), AllocStructTys,
|
||||||
"struct." + F.getName().str() + ".ehdata");
|
"struct." + F.getName().str() + ".ehdata");
|
||||||
bool HandlersOutlined = false;
|
bool HandlersOutlined = false;
|
||||||
|
|
||||||
for (LandingPadInst *LPad : LPads) {
|
for (LandingPadInst *LPad : LPads) {
|
||||||
// Look for evidence that this landingpad has already been processed.
|
// Look for evidence that this landingpad has already been processed.
|
||||||
bool LPadHasActionList = false;
|
bool LPadHasActionList = false;
|
||||||
BasicBlock *LPadBB = LPad->getParent();
|
BasicBlock *LPadBB = LPad->getParent();
|
||||||
for (Instruction &Inst : LPadBB->getInstList()) {
|
for (Instruction &Inst : LPadBB->getInstList()) {
|
||||||
// FIXME: Make this an intrinsic.
|
// FIXME: Make this an intrinsic.
|
||||||
if (auto *Call = dyn_cast<CallInst>(&Inst))
|
if (auto *Call = dyn_cast<CallInst>(&Inst))
|
||||||
if (Call->getCalledFunction()->getName() == "llvm.eh.actions") {
|
if (Call->getCalledFunction()->getName() == "llvm.eh.actions") {
|
||||||
LPadHasActionList = true;
|
LPadHasActionList = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've already outlined the handlers for this landingpad,
|
// If we've already outlined the handlers for this landingpad,
|
||||||
// there's nothing more to do here.
|
// there's nothing more to do here.
|
||||||
if (LPadHasActionList)
|
if (LPadHasActionList)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (unsigned Idx = 0, NumClauses = LPad->getNumClauses(); Idx < NumClauses;
|
for (unsigned Idx = 0, NumClauses = LPad->getNumClauses(); Idx < NumClauses;
|
||||||
++Idx) {
|
++Idx) {
|
||||||
if (LPad->isCatch(Idx))
|
if (LPad->isCatch(Idx))
|
||||||
HandlersOutlined =
|
HandlersOutlined =
|
||||||
outlineCatchHandler(&F, LPad->getClause(Idx), LPad, EHDataStructTy);
|
outlineCatchHandler(&F, LPad->getClause(Idx), LPad, EHDataStructTy);
|
||||||
} // End for each clause
|
} // End for each clause
|
||||||
} // End for each landingpad
|
} // End for each landingpad
|
||||||
|
|
||||||
return HandlersOutlined;
|
return HandlersOutlined;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WinEHPrepare::outlineCatchHandler(Function *SrcFn, Constant *SelectorType,
|
bool WinEHPrepare::outlineCatchHandler(Function *SrcFn, Constant *SelectorType,
|
||||||
LandingPadInst *LPad,
|
LandingPadInst *LPad,
|
||||||
StructType *EHDataStructTy) {
|
StructType *EHDataStructTy) {
|
||||||
Module *M = SrcFn->getParent();
|
Module *M = SrcFn->getParent();
|
||||||
LLVMContext &Context = M->getContext();
|
LLVMContext &Context = M->getContext();
|
||||||
|
|
||||||
// Create a new function to receive the handler contents.
|
// Create a new function to receive the handler contents.
|
||||||
Type *Int8PtrType = Type::getInt8PtrTy(Context);
|
Type *Int8PtrType = Type::getInt8PtrTy(Context);
|
||||||
std::vector<Type *> ArgTys;
|
std::vector<Type *> ArgTys;
|
||||||
ArgTys.push_back(Int8PtrType);
|
ArgTys.push_back(Int8PtrType);
|
||||||
ArgTys.push_back(Int8PtrType);
|
ArgTys.push_back(Int8PtrType);
|
||||||
FunctionType *FnType = FunctionType::get(Int8PtrType, ArgTys, false);
|
FunctionType *FnType = FunctionType::get(Int8PtrType, ArgTys, false);
|
||||||
Function *CatchHandler = Function::Create(
|
Function *CatchHandler = Function::Create(
|
||||||
FnType, GlobalVariable::ExternalLinkage, SrcFn->getName() + ".catch", M);
|
FnType, GlobalVariable::ExternalLinkage, SrcFn->getName() + ".catch", M);
|
||||||
|
|
||||||
// Generate a standard prolog to setup the frame recovery structure.
|
// Generate a standard prolog to setup the frame recovery structure.
|
||||||
IRBuilder<> Builder(Context);
|
IRBuilder<> Builder(Context);
|
||||||
BasicBlock *Entry = BasicBlock::Create(Context, "catch.entry");
|
BasicBlock *Entry = BasicBlock::Create(Context, "catch.entry");
|
||||||
CatchHandler->getBasicBlockList().push_front(Entry);
|
CatchHandler->getBasicBlockList().push_front(Entry);
|
||||||
Builder.SetInsertPoint(Entry);
|
Builder.SetInsertPoint(Entry);
|
||||||
Builder.SetCurrentDebugLocation(LPad->getDebugLoc());
|
Builder.SetCurrentDebugLocation(LPad->getDebugLoc());
|
||||||
|
|
||||||
// The outlined handler will be called with the parent's frame pointer as
|
// The outlined handler will be called with the parent's frame pointer as
|
||||||
// its second argument. To enable the handler to access variables from
|
// its second argument. To enable the handler to access variables from
|
||||||
// the parent frame, we use that pointer to get locate a special block
|
// the parent frame, we use that pointer to get locate a special block
|
||||||
// of memory that was allocated using llvm.eh.allocateframe for this
|
// of memory that was allocated using llvm.eh.allocateframe for this
|
||||||
// purpose. During the outlining process we will determine which frame
|
// purpose. During the outlining process we will determine which frame
|
||||||
// variables are used in handlers and create a structure that maps these
|
// variables are used in handlers and create a structure that maps these
|
||||||
// variables into the frame allocation block.
|
// variables into the frame allocation block.
|
||||||
//
|
//
|
||||||
// The frame allocation block also contains an exception state variable
|
// The frame allocation block also contains an exception state variable
|
||||||
// used by the runtime and a pointer to the exception object pointer
|
// used by the runtime and a pointer to the exception object pointer
|
||||||
// which will be filled in by the runtime for use in the handler.
|
// which will be filled in by the runtime for use in the handler.
|
||||||
Function *RecoverFrameFn =
|
Function *RecoverFrameFn =
|
||||||
Intrinsic::getDeclaration(M, Intrinsic::framerecover);
|
Intrinsic::getDeclaration(M, Intrinsic::framerecover);
|
||||||
Value *RecoverArgs[] = {Builder.CreateBitCast(SrcFn, Int8PtrType, ""),
|
Value *RecoverArgs[] = {Builder.CreateBitCast(SrcFn, Int8PtrType, ""),
|
||||||
&(CatchHandler->getArgumentList().back())};
|
&(CatchHandler->getArgumentList().back())};
|
||||||
CallInst *EHAlloc =
|
CallInst *EHAlloc =
|
||||||
Builder.CreateCall(RecoverFrameFn, RecoverArgs, "eh.alloc");
|
Builder.CreateCall(RecoverFrameFn, RecoverArgs, "eh.alloc");
|
||||||
Value *EHData =
|
Value *EHData =
|
||||||
Builder.CreateBitCast(EHAlloc, EHDataStructTy->getPointerTo(), "ehdata");
|
Builder.CreateBitCast(EHAlloc, EHDataStructTy->getPointerTo(), "ehdata");
|
||||||
Value *EHObjPtr =
|
Value *EHObjPtr =
|
||||||
Builder.CreateConstInBoundsGEP2_32(EHData, 0, 1, "eh.obj.ptr");
|
Builder.CreateConstInBoundsGEP2_32(EHData, 0, 1, "eh.obj.ptr");
|
||||||
|
|
||||||
// This will give us a raw pointer to the exception object, which
|
// This will give us a raw pointer to the exception object, which
|
||||||
// corresponds to the formal parameter of the catch statement. If the
|
// corresponds to the formal parameter of the catch statement. If the
|
||||||
// handler uses this object, we will generate code during the outlining
|
// handler uses this object, we will generate code during the outlining
|
||||||
// process to cast the pointer to the appropriate type and deference it
|
// process to cast the pointer to the appropriate type and deference it
|
||||||
// as necessary. The un-outlined landing pad code represents the
|
// as necessary. The un-outlined landing pad code represents the
|
||||||
// exception object as the result of the llvm.eh.begincatch call.
|
// exception object as the result of the llvm.eh.begincatch call.
|
||||||
Value *EHObj = Builder.CreateLoad(EHObjPtr, false, "eh.obj");
|
Value *EHObj = Builder.CreateLoad(EHObjPtr, false, "eh.obj");
|
||||||
|
|
||||||
ValueToValueMapTy VMap;
|
ValueToValueMapTy VMap;
|
||||||
|
|
||||||
// FIXME: Map other values referenced in the filter handler.
|
// FIXME: Map other values referenced in the filter handler.
|
||||||
|
|
||||||
WinEHCatchDirector Director(LPad, SelectorType, EHObj);
|
WinEHCatchDirector Director(LPad, SelectorType, EHObj);
|
||||||
|
|
||||||
SmallVector<ReturnInst *, 8> Returns;
|
SmallVector<ReturnInst *, 8> Returns;
|
||||||
ClonedCodeInfo InlinedFunctionInfo;
|
ClonedCodeInfo InlinedFunctionInfo;
|
||||||
|
|
||||||
BasicBlock::iterator II = LPad;
|
BasicBlock::iterator II = LPad;
|
||||||
|
|
||||||
CloneAndPruneIntoFromInst(CatchHandler, SrcFn, ++II, VMap,
|
CloneAndPruneIntoFromInst(CatchHandler, SrcFn, ++II, VMap,
|
||||||
/*ModuleLevelChanges=*/false, Returns, "",
|
/*ModuleLevelChanges=*/false, Returns, "",
|
||||||
&InlinedFunctionInfo,
|
&InlinedFunctionInfo,
|
||||||
SrcFn->getParent()->getDataLayout(), &Director);
|
SrcFn->getParent()->getDataLayout(), &Director);
|
||||||
|
|
||||||
// Move all the instructions in the first cloned block into our entry block.
|
// Move all the instructions in the first cloned block into our entry block.
|
||||||
BasicBlock *FirstClonedBB = std::next(Function::iterator(Entry));
|
BasicBlock *FirstClonedBB = std::next(Function::iterator(Entry));
|
||||||
Entry->getInstList().splice(Entry->end(), FirstClonedBB->getInstList());
|
Entry->getInstList().splice(Entry->end(), FirstClonedBB->getInstList());
|
||||||
FirstClonedBB->eraseFromParent();
|
FirstClonedBB->eraseFromParent();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloningDirector::CloningAction WinEHCatchDirector::handleInstruction(
|
CloningDirector::CloningAction WinEHCatchDirector::handleInstruction(
|
||||||
ValueToValueMapTy &VMap, const Instruction *Inst, BasicBlock *NewBB) {
|
ValueToValueMapTy &VMap, const Instruction *Inst, BasicBlock *NewBB) {
|
||||||
// Intercept instructions which extract values from the landing pad aggregate.
|
// Intercept instructions which extract values from the landing pad aggregate.
|
||||||
if (auto *Extract = dyn_cast<ExtractValueInst>(Inst)) {
|
if (auto *Extract = dyn_cast<ExtractValueInst>(Inst)) {
|
||||||
if (Extract->getAggregateOperand() == LPI) {
|
if (Extract->getAggregateOperand() == LPI) {
|
||||||
assert(Extract->getNumIndices() == 1 &&
|
assert(Extract->getNumIndices() == 1 &&
|
||||||
"Unexpected operation: extracting both landing pad values");
|
"Unexpected operation: extracting both landing pad values");
|
||||||
assert((*(Extract->idx_begin()) == 0 || *(Extract->idx_begin()) == 1) &&
|
assert((*(Extract->idx_begin()) == 0 || *(Extract->idx_begin()) == 1) &&
|
||||||
"Unexpected operation: extracting an unknown landing pad element");
|
"Unexpected operation: extracting an unknown landing pad element");
|
||||||
|
|
||||||
if (*(Extract->idx_begin()) == 0) {
|
if (*(Extract->idx_begin()) == 0) {
|
||||||
// Element 0 doesn't directly corresponds to anything in the WinEH scheme.
|
// Element 0 doesn't directly corresponds to anything in the WinEH scheme.
|
||||||
// It will be stored to a memory location, then later loaded and finally
|
// It will be stored to a memory location, then later loaded and finally
|
||||||
// the loaded value will be used as the argument to an llvm.eh.begincatch
|
// the loaded value will be used as the argument to an llvm.eh.begincatch
|
||||||
// call. We're tracking it here so that we can skip the store and load.
|
// call. We're tracking it here so that we can skip the store and load.
|
||||||
ExtractedEHPtr = Inst;
|
ExtractedEHPtr = Inst;
|
||||||
} else {
|
} else {
|
||||||
// Element 1 corresponds to the filter selector. We'll map it to 1 for
|
// Element 1 corresponds to the filter selector. We'll map it to 1 for
|
||||||
// matching purposes, but it will also probably be stored to memory and
|
// matching purposes, but it will also probably be stored to memory and
|
||||||
// reloaded, so we need to track the instuction so that we can map the
|
// reloaded, so we need to track the instuction so that we can map the
|
||||||
// loaded value too.
|
// loaded value too.
|
||||||
VMap[Inst] = ConstantInt::get(SelectorIDType, 1);
|
VMap[Inst] = ConstantInt::get(SelectorIDType, 1);
|
||||||
ExtractedSelector = Inst;
|
ExtractedSelector = Inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell the caller not to clone this instruction.
|
// Tell the caller not to clone this instruction.
|
||||||
return CloningDirector::SkipInstruction;
|
return CloningDirector::SkipInstruction;
|
||||||
}
|
}
|
||||||
// Other extract value instructions just get cloned.
|
// Other extract value instructions just get cloned.
|
||||||
return CloningDirector::CloneInstruction;
|
return CloningDirector::CloneInstruction;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto *Store = dyn_cast<StoreInst>(Inst)) {
|
if (auto *Store = dyn_cast<StoreInst>(Inst)) {
|
||||||
// Look for and suppress stores of the extracted landingpad values.
|
// Look for and suppress stores of the extracted landingpad values.
|
||||||
const Value *StoredValue = Store->getValueOperand();
|
const Value *StoredValue = Store->getValueOperand();
|
||||||
if (StoredValue == ExtractedEHPtr) {
|
if (StoredValue == ExtractedEHPtr) {
|
||||||
EHPtrStoreAddr = Store->getPointerOperand();
|
EHPtrStoreAddr = Store->getPointerOperand();
|
||||||
return CloningDirector::SkipInstruction;
|
return CloningDirector::SkipInstruction;
|
||||||
}
|
}
|
||||||
if (StoredValue == ExtractedSelector) {
|
if (StoredValue == ExtractedSelector) {
|
||||||
SelectorStoreAddr = Store->getPointerOperand();
|
SelectorStoreAddr = Store->getPointerOperand();
|
||||||
return CloningDirector::SkipInstruction;
|
return CloningDirector::SkipInstruction;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any other store just gets cloned.
|
// Any other store just gets cloned.
|
||||||
return CloningDirector::CloneInstruction;
|
return CloningDirector::CloneInstruction;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto *Load = dyn_cast<LoadInst>(Inst)) {
|
if (auto *Load = dyn_cast<LoadInst>(Inst)) {
|
||||||
// Look for loads of (previously suppressed) landingpad values.
|
// Look for loads of (previously suppressed) landingpad values.
|
||||||
// The EHPtr load can be ignored (it should only be used as
|
// The EHPtr load can be ignored (it should only be used as
|
||||||
// an argument to llvm.eh.begincatch), but the selector value
|
// an argument to llvm.eh.begincatch), but the selector value
|
||||||
// needs to be mapped to a constant value of 1 to be used to
|
// needs to be mapped to a constant value of 1 to be used to
|
||||||
// simplify the branching to always flow to the current handler.
|
// simplify the branching to always flow to the current handler.
|
||||||
const Value *LoadAddr = Load->getPointerOperand();
|
const Value *LoadAddr = Load->getPointerOperand();
|
||||||
if (LoadAddr == EHPtrStoreAddr) {
|
if (LoadAddr == EHPtrStoreAddr) {
|
||||||
VMap[Inst] = UndefValue::get(Int8PtrType);
|
VMap[Inst] = UndefValue::get(Int8PtrType);
|
||||||
return CloningDirector::SkipInstruction;
|
return CloningDirector::SkipInstruction;
|
||||||
}
|
}
|
||||||
if (LoadAddr == SelectorStoreAddr) {
|
if (LoadAddr == SelectorStoreAddr) {
|
||||||
VMap[Inst] = ConstantInt::get(SelectorIDType, 1);
|
VMap[Inst] = ConstantInt::get(SelectorIDType, 1);
|
||||||
return CloningDirector::SkipInstruction;
|
return CloningDirector::SkipInstruction;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any other loads just get cloned.
|
// Any other loads just get cloned.
|
||||||
return CloningDirector::CloneInstruction;
|
return CloningDirector::CloneInstruction;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match(Inst, m_Intrinsic<Intrinsic::eh_begincatch>())) {
|
if (match(Inst, m_Intrinsic<Intrinsic::eh_begincatch>())) {
|
||||||
// The argument to the call is some form of the first element of the
|
// The argument to the call is some form of the first element of the
|
||||||
// landingpad aggregate value, but that doesn't matter. It isn't used
|
// landingpad aggregate value, but that doesn't matter. It isn't used
|
||||||
// here.
|
// here.
|
||||||
// The return value of this instruction, however, is used to access the
|
// The return value of this instruction, however, is used to access the
|
||||||
// EH object pointer. We have generated an instruction to get that value
|
// EH object pointer. We have generated an instruction to get that value
|
||||||
// from the EH alloc block, so we can just map to that here.
|
// from the EH alloc block, so we can just map to that here.
|
||||||
VMap[Inst] = EHObj;
|
VMap[Inst] = EHObj;
|
||||||
return CloningDirector::SkipInstruction;
|
return CloningDirector::SkipInstruction;
|
||||||
}
|
}
|
||||||
if (match(Inst, m_Intrinsic<Intrinsic::eh_endcatch>())) {
|
if (match(Inst, m_Intrinsic<Intrinsic::eh_endcatch>())) {
|
||||||
auto *IntrinCall = dyn_cast<IntrinsicInst>(Inst);
|
auto *IntrinCall = dyn_cast<IntrinsicInst>(Inst);
|
||||||
// It might be interesting to track whether or not we are inside a catch
|
// It might be interesting to track whether or not we are inside a catch
|
||||||
// function, but that might make the algorithm more brittle than it needs
|
// function, but that might make the algorithm more brittle than it needs
|
||||||
// to be.
|
// to be.
|
||||||
|
|
||||||
// The end catch call can occur in one of two places: either in a
|
// The end catch call can occur in one of two places: either in a
|
||||||
// landingpad
|
// landingpad
|
||||||
// block that is part of the catch handlers exception mechanism, or at the
|
// block that is part of the catch handlers exception mechanism, or at the
|
||||||
// end of the catch block. If it occurs in a landing pad, we must skip it
|
// end of the catch block. If it occurs in a landing pad, we must skip it
|
||||||
// and continue so that the landing pad gets cloned.
|
// and continue so that the landing pad gets cloned.
|
||||||
// FIXME: This case isn't fully supported yet and shouldn't turn up in any
|
// FIXME: This case isn't fully supported yet and shouldn't turn up in any
|
||||||
// of the test cases until it is.
|
// of the test cases until it is.
|
||||||
if (IntrinCall->getParent()->isLandingPad())
|
if (IntrinCall->getParent()->isLandingPad())
|
||||||
return CloningDirector::SkipInstruction;
|
return CloningDirector::SkipInstruction;
|
||||||
|
|
||||||
// If an end catch occurs anywhere else the next instruction should be an
|
// If an end catch occurs anywhere else the next instruction should be an
|
||||||
// unconditional branch instruction that we want to replace with a return
|
// unconditional branch instruction that we want to replace with a return
|
||||||
// to the the address of the branch target.
|
// to the the address of the branch target.
|
||||||
const BasicBlock *EndCatchBB = IntrinCall->getParent();
|
const BasicBlock *EndCatchBB = IntrinCall->getParent();
|
||||||
const TerminatorInst *Terminator = EndCatchBB->getTerminator();
|
const TerminatorInst *Terminator = EndCatchBB->getTerminator();
|
||||||
const BranchInst *Branch = dyn_cast<BranchInst>(Terminator);
|
const BranchInst *Branch = dyn_cast<BranchInst>(Terminator);
|
||||||
assert(Branch && Branch->isUnconditional());
|
assert(Branch && Branch->isUnconditional());
|
||||||
assert(std::next(BasicBlock::const_iterator(IntrinCall)) ==
|
assert(std::next(BasicBlock::const_iterator(IntrinCall)) ==
|
||||||
BasicBlock::const_iterator(Branch));
|
BasicBlock::const_iterator(Branch));
|
||||||
|
|
||||||
ReturnInst::Create(NewBB->getContext(),
|
ReturnInst::Create(NewBB->getContext(),
|
||||||
BlockAddress::get(Branch->getSuccessor(0)), NewBB);
|
BlockAddress::get(Branch->getSuccessor(0)), NewBB);
|
||||||
|
|
||||||
// We just added a terminator to the cloned block.
|
// We just added a terminator to the cloned block.
|
||||||
// Tell the caller to stop processing the current basic block so that
|
// Tell the caller to stop processing the current basic block so that
|
||||||
// the branch instruction will be skipped.
|
// the branch instruction will be skipped.
|
||||||
return CloningDirector::StopCloningBB;
|
return CloningDirector::StopCloningBB;
|
||||||
}
|
}
|
||||||
if (match(Inst, m_Intrinsic<Intrinsic::eh_typeid_for>())) {
|
if (match(Inst, m_Intrinsic<Intrinsic::eh_typeid_for>())) {
|
||||||
auto *IntrinCall = dyn_cast<IntrinsicInst>(Inst);
|
auto *IntrinCall = dyn_cast<IntrinsicInst>(Inst);
|
||||||
Value *Selector = IntrinCall->getArgOperand(0)->stripPointerCasts();
|
Value *Selector = IntrinCall->getArgOperand(0)->stripPointerCasts();
|
||||||
// This causes a replacement that will collapse the landing pad CFG based
|
// This causes a replacement that will collapse the landing pad CFG based
|
||||||
// on the filter function we intend to match.
|
// on the filter function we intend to match.
|
||||||
if (Selector == CurrentSelector)
|
if (Selector == CurrentSelector)
|
||||||
VMap[Inst] = ConstantInt::get(SelectorIDType, 1);
|
VMap[Inst] = ConstantInt::get(SelectorIDType, 1);
|
||||||
else
|
else
|
||||||
VMap[Inst] = ConstantInt::get(SelectorIDType, 0);
|
VMap[Inst] = ConstantInt::get(SelectorIDType, 0);
|
||||||
// Tell the caller not to clone this instruction.
|
// Tell the caller not to clone this instruction.
|
||||||
return CloningDirector::SkipInstruction;
|
return CloningDirector::SkipInstruction;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue with the default cloning behavior.
|
// Continue with the default cloning behavior.
|
||||||
return CloningDirector::CloneInstruction;
|
return CloningDirector::CloneInstruction;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,83 +1,83 @@
|
||||||
; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
|
; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
|
||||||
|
|
||||||
; This test is based on the following code:
|
; This test is based on the following code:
|
||||||
;
|
;
|
||||||
; void test()
|
; void test()
|
||||||
; {
|
; {
|
||||||
; try {
|
; try {
|
||||||
; may_throw();
|
; may_throw();
|
||||||
; } catch (...) {
|
; } catch (...) {
|
||||||
; handle_exception();
|
; handle_exception();
|
||||||
; }
|
; }
|
||||||
; }
|
; }
|
||||||
;
|
;
|
||||||
; Parts of the IR have been hand-edited to simplify the test case.
|
; Parts of the IR have been hand-edited to simplify the test case.
|
||||||
; The full IR will be restored when Windows C++ EH support is complete.
|
; The full IR will be restored when Windows C++ EH support is complete.
|
||||||
|
|
||||||
; ModuleID = 'catch-all.cpp'
|
; ModuleID = 'catch-all.cpp'
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-pc-windows-msvc"
|
target triple = "x86_64-pc-windows-msvc"
|
||||||
|
|
||||||
; Function Attrs: uwtable
|
; Function Attrs: uwtable
|
||||||
define void @_Z4testv() #0 {
|
define void @_Z4testv() #0 {
|
||||||
entry:
|
entry:
|
||||||
%exn.slot = alloca i8*
|
%exn.slot = alloca i8*
|
||||||
%ehselector.slot = alloca i32
|
%ehselector.slot = alloca i32
|
||||||
invoke void @_Z9may_throwv()
|
invoke void @_Z9may_throwv()
|
||||||
to label %invoke.cont unwind label %lpad
|
to label %invoke.cont unwind label %lpad
|
||||||
|
|
||||||
invoke.cont: ; preds = %entry
|
invoke.cont: ; preds = %entry
|
||||||
br label %try.cont
|
br label %try.cont
|
||||||
|
|
||||||
lpad: ; preds = %entry
|
lpad: ; preds = %entry
|
||||||
%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
|
%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
|
||||||
catch i8* null
|
catch i8* null
|
||||||
%1 = extractvalue { i8*, i32 } %0, 0
|
%1 = extractvalue { i8*, i32 } %0, 0
|
||||||
store i8* %1, i8** %exn.slot
|
store i8* %1, i8** %exn.slot
|
||||||
%2 = extractvalue { i8*, i32 } %0, 1
|
%2 = extractvalue { i8*, i32 } %0, 1
|
||||||
store i32 %2, i32* %ehselector.slot
|
store i32 %2, i32* %ehselector.slot
|
||||||
br label %catch
|
br label %catch
|
||||||
|
|
||||||
catch: ; preds = %lpad
|
catch: ; preds = %lpad
|
||||||
%exn = load i8** %exn.slot
|
%exn = load i8** %exn.slot
|
||||||
%3 = call i8* @llvm.eh.begincatch(i8* %exn) #3
|
%3 = call i8* @llvm.eh.begincatch(i8* %exn) #3
|
||||||
call void @_Z16handle_exceptionv()
|
call void @_Z16handle_exceptionv()
|
||||||
br label %invoke.cont2
|
br label %invoke.cont2
|
||||||
|
|
||||||
invoke.cont2: ; preds = %catch
|
invoke.cont2: ; preds = %catch
|
||||||
call void @llvm.eh.endcatch()
|
call void @llvm.eh.endcatch()
|
||||||
br label %try.cont
|
br label %try.cont
|
||||||
|
|
||||||
try.cont: ; preds = %invoke.cont2, %invoke.cont
|
try.cont: ; preds = %invoke.cont2, %invoke.cont
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
; CHECK: define i8* @_Z4testv.catch(i8*, i8*) {
|
; CHECK: define i8* @_Z4testv.catch(i8*, i8*) {
|
||||||
; CHECK: catch.entry:
|
; CHECK: catch.entry:
|
||||||
; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
|
; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
|
||||||
; CHECK: %ehdata = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
|
; CHECK: %ehdata = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
|
||||||
; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata* %ehdata, i32 0, i32 1
|
; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata* %ehdata, i32 0, i32 1
|
||||||
; CHECK: %eh.obj = load i8** %eh.obj.ptr
|
; CHECK: %eh.obj = load i8** %eh.obj.ptr
|
||||||
; CHECK: call void @_Z16handle_exceptionv()
|
; CHECK: call void @_Z16handle_exceptionv()
|
||||||
; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
|
; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
|
||||||
; CHECK: }
|
; CHECK: }
|
||||||
|
|
||||||
declare void @_Z9may_throwv() #1
|
declare void @_Z9may_throwv() #1
|
||||||
|
|
||||||
declare i32 @__CxxFrameHandler3(...)
|
declare i32 @__CxxFrameHandler3(...)
|
||||||
|
|
||||||
declare i8* @llvm.eh.begincatch(i8*)
|
declare i8* @llvm.eh.begincatch(i8*)
|
||||||
|
|
||||||
declare void @_Z16handle_exceptionv() #1
|
declare void @_Z16handle_exceptionv() #1
|
||||||
|
|
||||||
declare void @llvm.eh.endcatch()
|
declare void @llvm.eh.endcatch()
|
||||||
|
|
||||||
attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||||
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||||
attributes #2 = { noinline noreturn nounwind }
|
attributes #2 = { noinline noreturn nounwind }
|
||||||
attributes #3 = { nounwind }
|
attributes #3 = { nounwind }
|
||||||
attributes #4 = { noreturn nounwind }
|
attributes #4 = { noreturn nounwind }
|
||||||
|
|
||||||
!llvm.ident = !{!0}
|
!llvm.ident = !{!0}
|
||||||
|
|
||||||
!0 = !{!"clang version 3.7.0 (trunk 226027)"}
|
!0 = !{!"clang version 3.7.0 (trunk 226027)"}
|
||||||
|
|
|
@ -1,102 +1,102 @@
|
||||||
; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
|
; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
|
||||||
|
|
||||||
; This test is based on the following code:
|
; This test is based on the following code:
|
||||||
;
|
;
|
||||||
; void test()
|
; void test()
|
||||||
; {
|
; {
|
||||||
; try {
|
; try {
|
||||||
; may_throw();
|
; may_throw();
|
||||||
; } catch (int) {
|
; } catch (int) {
|
||||||
; handle_int();
|
; handle_int();
|
||||||
; }
|
; }
|
||||||
; }
|
; }
|
||||||
;
|
;
|
||||||
; Parts of the IR have been hand-edited to simplify the test case.
|
; Parts of the IR have been hand-edited to simplify the test case.
|
||||||
; The full IR will be restored when Windows C++ EH support is complete.
|
; The full IR will be restored when Windows C++ EH support is complete.
|
||||||
|
|
||||||
;ModuleID = 'cppeh-catch-scalar.cpp'
|
;ModuleID = 'cppeh-catch-scalar.cpp'
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-pc-windows-msvc"
|
target triple = "x86_64-pc-windows-msvc"
|
||||||
|
|
||||||
@_ZTIi = external constant i8*
|
@_ZTIi = external constant i8*
|
||||||
|
|
||||||
; Function Attrs: uwtable
|
; Function Attrs: uwtable
|
||||||
define void @_Z4testv() #0 {
|
define void @_Z4testv() #0 {
|
||||||
entry:
|
entry:
|
||||||
%exn.slot = alloca i8*
|
%exn.slot = alloca i8*
|
||||||
%ehselector.slot = alloca i32
|
%ehselector.slot = alloca i32
|
||||||
invoke void @_Z9may_throwv()
|
invoke void @_Z9may_throwv()
|
||||||
to label %invoke.cont unwind label %lpad
|
to label %invoke.cont unwind label %lpad
|
||||||
|
|
||||||
invoke.cont: ; preds = %entry
|
invoke.cont: ; preds = %entry
|
||||||
br label %try.cont
|
br label %try.cont
|
||||||
|
|
||||||
lpad: ; preds = %entry
|
lpad: ; preds = %entry
|
||||||
%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
|
%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
|
||||||
catch i8* bitcast (i8** @_ZTIi to i8*)
|
catch i8* bitcast (i8** @_ZTIi to i8*)
|
||||||
%1 = extractvalue { i8*, i32 } %0, 0
|
%1 = extractvalue { i8*, i32 } %0, 0
|
||||||
store i8* %1, i8** %exn.slot
|
store i8* %1, i8** %exn.slot
|
||||||
%2 = extractvalue { i8*, i32 } %0, 1
|
%2 = extractvalue { i8*, i32 } %0, 1
|
||||||
store i32 %2, i32* %ehselector.slot
|
store i32 %2, i32* %ehselector.slot
|
||||||
br label %catch.dispatch
|
br label %catch.dispatch
|
||||||
|
|
||||||
catch.dispatch: ; preds = %lpad
|
catch.dispatch: ; preds = %lpad
|
||||||
%sel = load i32* %ehselector.slot
|
%sel = load i32* %ehselector.slot
|
||||||
%3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
|
%3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
|
||||||
%matches = icmp eq i32 %sel, %3
|
%matches = icmp eq i32 %sel, %3
|
||||||
br i1 %matches, label %catch, label %eh.resume
|
br i1 %matches, label %catch, label %eh.resume
|
||||||
|
|
||||||
catch: ; preds = %catch.dispatch
|
catch: ; preds = %catch.dispatch
|
||||||
%exn11 = load i8** %exn.slot
|
%exn11 = load i8** %exn.slot
|
||||||
%4 = call i8* @llvm.eh.begincatch(i8* %exn11) #3
|
%4 = call i8* @llvm.eh.begincatch(i8* %exn11) #3
|
||||||
%5 = bitcast i8* %4 to i32*
|
%5 = bitcast i8* %4 to i32*
|
||||||
call void @_Z10handle_intv()
|
call void @_Z10handle_intv()
|
||||||
br label %invoke.cont2
|
br label %invoke.cont2
|
||||||
|
|
||||||
invoke.cont2: ; preds = %catch
|
invoke.cont2: ; preds = %catch
|
||||||
call void @llvm.eh.endcatch() #3
|
call void @llvm.eh.endcatch() #3
|
||||||
br label %try.cont
|
br label %try.cont
|
||||||
|
|
||||||
try.cont: ; preds = %invoke.cont2, %invoke.cont
|
try.cont: ; preds = %invoke.cont2, %invoke.cont
|
||||||
ret void
|
ret void
|
||||||
|
|
||||||
eh.resume: ; preds = %catch.dispatch
|
eh.resume: ; preds = %catch.dispatch
|
||||||
%exn3 = load i8** %exn.slot
|
%exn3 = load i8** %exn.slot
|
||||||
%sel4 = load i32* %ehselector.slot
|
%sel4 = load i32* %ehselector.slot
|
||||||
%lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
|
%lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
|
||||||
%lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
|
%lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
|
||||||
resume { i8*, i32 } %lpad.val5
|
resume { i8*, i32 } %lpad.val5
|
||||||
}
|
}
|
||||||
|
|
||||||
; CHECK: define i8* @_Z4testv.catch(i8*, i8*) {
|
; CHECK: define i8* @_Z4testv.catch(i8*, i8*) {
|
||||||
; CHECK: catch.entry:
|
; CHECK: catch.entry:
|
||||||
; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
|
; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
|
||||||
; CHECK: %ehdata = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
|
; CHECK: %ehdata = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
|
||||||
; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata* %ehdata, i32 0, i32 1
|
; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata* %ehdata, i32 0, i32 1
|
||||||
; CHECK: %eh.obj = load i8** %eh.obj.ptr
|
; CHECK: %eh.obj = load i8** %eh.obj.ptr
|
||||||
; CHECK: %2 = bitcast i8* %eh.obj to i32*
|
; CHECK: %2 = bitcast i8* %eh.obj to i32*
|
||||||
; CHECK: call void @_Z10handle_intv()
|
; CHECK: call void @_Z10handle_intv()
|
||||||
; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
|
; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
|
||||||
; CHECK: }
|
; CHECK: }
|
||||||
|
|
||||||
declare void @_Z9may_throwv() #1
|
declare void @_Z9may_throwv() #1
|
||||||
|
|
||||||
declare i32 @__CxxFrameHandler3(...)
|
declare i32 @__CxxFrameHandler3(...)
|
||||||
|
|
||||||
; Function Attrs: nounwind readnone
|
; Function Attrs: nounwind readnone
|
||||||
declare i32 @llvm.eh.typeid.for(i8*) #2
|
declare i32 @llvm.eh.typeid.for(i8*) #2
|
||||||
|
|
||||||
declare i8* @llvm.eh.begincatch(i8*)
|
declare i8* @llvm.eh.begincatch(i8*)
|
||||||
|
|
||||||
declare void @llvm.eh.endcatch()
|
declare void @llvm.eh.endcatch()
|
||||||
|
|
||||||
declare void @_Z10handle_intv() #1
|
declare void @_Z10handle_intv() #1
|
||||||
|
|
||||||
attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||||
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||||
attributes #2 = { nounwind readnone }
|
attributes #2 = { nounwind readnone }
|
||||||
attributes #3 = { nounwind }
|
attributes #3 = { nounwind }
|
||||||
|
|
||||||
!llvm.ident = !{!0}
|
!llvm.ident = !{!0}
|
||||||
|
|
||||||
!0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}
|
!0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}
|
||||||
|
|
Loading…
Reference in New Issue