Index: include/llvm/CodeGen/WinEHFuncInfo.h =================================================================== --- include/llvm/CodeGen/WinEHFuncInfo.h +++ include/llvm/CodeGen/WinEHFuncInfo.h @@ -132,21 +132,24 @@ }; struct WinEHFuncInfo { + DenseMap RootLPad; DenseMap LandingPadStateMap; DenseMap CatchHandlerParentFrameObjIdx; DenseMap CatchHandlerParentFrameObjOffset; DenseMap CatchHandlerMaxState; + DenseMap HandlerBaseState; SmallVector UnwindMap; SmallVector TryBlockMap; SmallVector, 4> IPToStateList; int UnwindHelpFrameIdx; int UnwindHelpFrameOffset; + int MaxState; unsigned NumIPToStateFuncsVisited; WinEHFuncInfo() : UnwindHelpFrameIdx(INT_MAX), UnwindHelpFrameOffset(-1), - NumIPToStateFuncsVisited(0) {} + NumIPToStateFuncsVisited(0), MaxState(-1) {} }; } Index: lib/CodeGen/AsmPrinter/Win64Exception.cpp =================================================================== --- lib/CodeGen/AsmPrinter/Win64Exception.cpp +++ lib/CodeGen/AsmPrinter/Win64Exception.cpp @@ -299,6 +299,17 @@ // The parent function and the catch handlers contribute to the 'ip2state' // table. + + // Include ip2state entries for the beginning of the main function and + // for catch handler functions. + if (F == ParentF) { + FuncInfo.IPToStateList.push_back(std::make_pair(LastLabel, -1)); + LastEHState = -1; + } else if (FuncInfo.HandlerBaseState.count(F)) { + FuncInfo.IPToStateList.push_back(std::make_pair(LastLabel, + FuncInfo.HandlerBaseState[F])); + LastEHState = FuncInfo.HandlerBaseState[F]; + } for (const auto &MBB : *MF) { for (const auto &MI : MBB) { if (!MI.isEHLabel()) { @@ -323,7 +334,8 @@ assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] && "Inconsistent landing pad map!"); - if (SawPotentiallyThrowing) { + // FIXME: Should this be using FuncInfo.HandlerBaseState? + if (SawPotentiallyThrowing && LastEHState != -1) { FuncInfo.IPToStateList.push_back(std::make_pair(LastLabel, -1)); SawPotentiallyThrowing = false; LastEHState = -1; @@ -376,7 +388,7 @@ // EHFlags & 4 -> The function is noexcept(true), unwinding can't continue. OS.EmitLabel(FuncInfoXData); OS.EmitIntValue(0x19930522, 4); // MagicNumber - OS.EmitIntValue(FuncInfo.UnwindMap.size(), 4); // MaxState + OS.EmitIntValue(FuncInfo.MaxState, 4); // MaxState OS.EmitValue(createImageRel32(UnwindMapXData), 4); // UnwindMap OS.EmitIntValue(FuncInfo.TryBlockMap.size(), 4); // NumTryBlocks OS.EmitValue(createImageRel32(TryBlockMapXData), 4); // TryBlockMap Index: lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp =================================================================== --- lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -82,16 +82,18 @@ namespace { struct WinEHNumbering { - WinEHNumbering(WinEHFuncInfo &FuncInfo) : FuncInfo(FuncInfo), NextState(0) {} + WinEHNumbering(WinEHFuncInfo &FuncInfo) : FuncInfo(FuncInfo), + CurrentBaseState(-1), NextState(0) {} WinEHFuncInfo &FuncInfo; + int CurrentBaseState; int NextState; SmallVector HandlerStack; SmallPtrSet VisitedHandlers; int currentEHNumber() const { - return HandlerStack.empty() ? -1 : HandlerStack.back()->getEHState(); + return HandlerStack.empty() ? CurrentBaseState : HandlerStack.back()->getEHState(); } void createUnwindMapEntry(int ToState, ActionHandler *AH); @@ -99,6 +101,7 @@ ArrayRef Handlers); void processCallSite(ArrayRef Actions, ImmutableCallSite CS); void calculateStateNumbers(const Function &F); + void findActionRootLPads(const Function &F); }; } @@ -294,9 +297,17 @@ EHInfo = &MMI.getWinEHFuncInfo(WinEHParentFn); if (EHInfo->LandingPadStateMap.empty()) { WinEHNumbering Num(*EHInfo); + Num.findActionRootLPads(*WinEHParentFn); + // The VisitedHandlers list is used by both findActionRootLPads and + // calculateStateNumbers, but both functions need to visit all handlers. + Num.VisitedHandlers.clear(); Num.calculateStateNumbers(*WinEHParentFn); // Pop everything on the handler stack. - Num.processCallSite(None, ImmutableCallSite()); + // It may be necessary to call this more than once because a handler can + // be pushed on the stack as a result of clearing the stack. + while (!Num.HandlerStack.empty()) + Num.processCallSite(None, ImmutableCallSite()); + EHInfo->MaxState = Num.NextState; } // Copy the state numbers to LandingPadInfo for the current function, which @@ -401,12 +412,30 @@ void WinEHNumbering::processCallSite(ArrayRef Actions, ImmutableCallSite CS) { + DEBUG(dbgs() << "processCallSite (EH state = " << currentEHNumber() + << ") for: "); + print_name(CS ? CS.getCalledValue() : nullptr); + DEBUG(dbgs() << '\n'); + + DEBUG(dbgs() << "HandlerStack: \n"); + for (int I = 0, E = HandlerStack.size(); I < E; ++I) { + DEBUG(dbgs() << " "); + print_name(HandlerStack[I]->getHandlerBlockOrFunc()); + DEBUG(dbgs() << '\n'); + } + DEBUG(dbgs() << "Actions: \n"); + for (int I = 0, E = Actions.size(); I < E; ++I) { + DEBUG(dbgs() << " "); + print_name(Actions[I]->getHandlerBlockOrFunc()); + DEBUG(dbgs() << '\n'); + } int FirstMismatch = 0; for (int E = std::min(HandlerStack.size(), Actions.size()); FirstMismatch < E; ++FirstMismatch) { if (HandlerStack[FirstMismatch]->getHandlerBlockOrFunc() != Actions[FirstMismatch]->getHandlerBlockOrFunc()) break; + // Delete any actions that are already represented on the handler stack. delete Actions[FirstMismatch]; } @@ -429,45 +458,80 @@ // will not push any more actions. int TryHigh = NextState - 1; if (!EnteringScope && !PoppedCatches.empty()) { + DEBUG(dbgs() << "createUnwindMapEntry(" << currentEHNumber() << ", " << TryHigh << '\n'); createUnwindMapEntry(currentEHNumber(), nullptr); - ++NextState; } int LastTryLowIdx = 0; for (int I = 0, E = PoppedCatches.size(); I != E; ++I) { CatchHandler *CH = PoppedCatches[I]; + DEBUG(dbgs() << "Popped handler with state " << CH->getEHState() << "\n"); if (I + 1 == E || CH->getEHState() != PoppedCatches[I + 1]->getEHState()) { int TryLow = CH->getEHState(); auto Handlers = makeArrayRef(&PoppedCatches[LastTryLowIdx], I - LastTryLowIdx + 1); + DEBUG(dbgs() << "createTryBlockMapEntry(" << TryLow << ", " << TryHigh); + for (int J = 0; J < Handlers.size(); ++J) { + DEBUG(dbgs() << ", "); + print_name(Handlers[J]->getHandlerBlockOrFunc()); + } + DEBUG(dbgs() << ")\n"); createTryBlockMapEntry(TryLow, TryHigh, Handlers); LastTryLowIdx = I + 1; } } for (CatchHandler *CH : PoppedCatches) { - if (auto *F = dyn_cast(CH->getHandlerBlockOrFunc())) + if (auto *F = dyn_cast(CH->getHandlerBlockOrFunc())) { + DEBUG(dbgs() << "Assigning base state " << NextState << " to "); + print_name(F); + DEBUG(dbgs() << '\n'); + FuncInfo.HandlerBaseState[F] = NextState; + ++NextState; calculateStateNumbers(*F); + } delete CH; } + // The handler functions may have pushed actions onto the handler stack + // that we expected to push here. Compare the handler stack to our + // actions again to check for that possibility. + if (HandlerStack.size() > FirstMismatch) { + for (int E = std::min(HandlerStack.size(), Actions.size()); FirstMismatch < E; + ++FirstMismatch) { + if (HandlerStack[FirstMismatch]->getHandlerBlockOrFunc() != + Actions[FirstMismatch]->getHandlerBlockOrFunc()) + break; + delete Actions[FirstMismatch]; + } + } + + DEBUG(dbgs() << "Pushing actions for CallSite: "); + print_name(CS ? CS.getCalledValue() : nullptr); + DEBUG(dbgs() << '\n'); + bool LastActionWasCatch = false; + const LandingPadInst *LastRootLPad = nullptr; for (size_t I = FirstMismatch; I != Actions.size(); ++I) { // We can reuse eh states when pushing two catches for the same invoke. bool CurrActionIsCatch = isa(Actions[I]); - // FIXME: Reenable this optimization! - if (CurrActionIsCatch && LastActionWasCatch && false) { + auto *Handler = cast(Actions[I]->getHandlerBlockOrFunc()); + const LandingPadInst* RootLPad = FuncInfo.RootLPad[Handler]; + if (CurrActionIsCatch && LastActionWasCatch && RootLPad == LastRootLPad) { + DEBUG(dbgs() << "setEHState for handler to " << currentEHNumber() << "\n"); Actions[I]->setEHState(currentEHNumber()); } else { + DEBUG(dbgs() << "createUnwindMapEntry(" << currentEHNumber() << ", "); + print_name(Actions[I]->getHandlerBlockOrFunc()); + DEBUG(dbgs() << ")\n"); createUnwindMapEntry(currentEHNumber(), Actions[I]); + DEBUG(dbgs() << "setEHState for handler to " << NextState << "\n"); Actions[I]->setEHState(NextState); NextState++; - DEBUG(dbgs() << "Creating unwind map entry for: ("); - print_name(Actions[I]->getHandlerBlockOrFunc()); - DEBUG(dbgs() << ", " << currentEHNumber() << ")\n"); } HandlerStack.push_back(Actions[I]); LastActionWasCatch = CurrActionIsCatch; + LastRootLPad = RootLPad; } DEBUG(dbgs() << "In EHState " << currentEHNumber() << " for CallSite: "); @@ -480,6 +544,11 @@ if (!I.second) return; // We've already visited this handler, don't renumber it. + int OldBaseState = CurrentBaseState; + if (FuncInfo.HandlerBaseState.count(&F)) { + CurrentBaseState = FuncInfo.HandlerBaseState[&F]; + } + DEBUG(dbgs() << "Calculating state numbers for: " << F.getName() << '\n'); SmallVector ActionList; for (const BasicBlock &BB : F) { @@ -498,12 +567,68 @@ continue; assert(ActionsCall->getIntrinsicID() == Intrinsic::eh_actions); parseEHActions(ActionsCall, ActionList); + if (ActionList.empty()) + continue; processCallSite(ActionList, II); ActionList.clear(); FuncInfo.LandingPadStateMap[LPI] = currentEHNumber(); + DEBUG(dbgs() << "Assigning state " << currentEHNumber() + << " to landing pad at " << LPI->getParent()->getName() + << '\n'); } FuncInfo.CatchHandlerMaxState[&F] = NextState - 1; + + CurrentBaseState = OldBaseState; +} + +// This function follows the same basic traversal as calculateStateNumbers +// but it is necessary to identify the root landing pad associated +// with each action before we start assigning state numbers. +void WinEHNumbering::findActionRootLPads(const Function &F) { + auto I = VisitedHandlers.insert(&F); + if (!I.second) + return; // We've already visited this handler, don't revisit it. + + SmallVector ActionList; + for (const BasicBlock &BB : F) { + const auto *II = dyn_cast(BB.getTerminator()); + if (!II) + continue; + const LandingPadInst *LPI = II->getLandingPadInst(); + auto *ActionsCall = dyn_cast(LPI->getNextNode()); + if (!ActionsCall) + continue; + + assert(ActionsCall->getIntrinsicID() == Intrinsic::eh_actions); + parseEHActions(ActionsCall, ActionList); + if (ActionList.empty()) + continue; + for (int I = 0, E = ActionList.size(); I < E; ++I) { + if (auto *Handler + = dyn_cast(ActionList[I]->getHandlerBlockOrFunc())) { + // Don't replace the root landing pad if we previously saw this + // handler in a different function. + if (FuncInfo.RootLPad.count(Handler) && + FuncInfo.RootLPad[Handler]->getParent()->getParent() != &F) + continue; + DEBUG(dbgs() << "Setting root lpad for "); + print_name(Handler); + DEBUG(dbgs() << " to " << LPI->getParent()->getName() << '\n'); + FuncInfo.RootLPad[Handler] = LPI; + } + } + // Walk the actions again and look for nested handlers. This has to + // happen after all of the actions have been processed in the current + // function. + for (int I = 0, E = ActionList.size(); I < E; ++I) + if (auto *Handler + = dyn_cast(ActionList[I]->getHandlerBlockOrFunc())) + findActionRootLPads(*Handler); + + DeleteContainerPointers(ActionList); + ActionList.clear(); + } } /// clear - Clear out all the function-specific state. This returns this Index: test/CodeGen/WinEH/cppeh-prepared-catch-reordered.ll =================================================================== --- test/CodeGen/WinEH/cppeh-prepared-catch-reordered.ll +++ test/CodeGen/WinEH/cppeh-prepared-catch-reordered.ll @@ -120,7 +120,7 @@ ; CHECK-NEXT: .long ($stateUnwindMap$main)@IMGREL ; CHECK-NEXT: .long 1 ; CHECK-NEXT: .long ($tryMap$main)@IMGREL -; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 3 ; CHECK-NEXT: .long ($ip2state$main)@IMGREL ; CHECK-NEXT: .long 40 ; CHECK-NEXT: .long 0 Index: test/CodeGen/WinEH/cppeh-prepared-catch.ll =================================================================== --- test/CodeGen/WinEH/cppeh-prepared-catch.ll +++ test/CodeGen/WinEH/cppeh-prepared-catch.ll @@ -127,7 +127,7 @@ ; CHECK-NEXT: .long ("$stateUnwindMap$?f@@YAXXZ")@IMGREL ; CHECK-NEXT: .long 2 ; CHECK-NEXT: .long ("$tryMap$?f@@YAXXZ")@IMGREL -; CHECK-NEXT: .long 3 +; CHECK-NEXT: .long 6 ; CHECK-NEXT: .long ("$ip2state$?f@@YAXXZ")@IMGREL ; CHECK-NEXT: .long 32 ; CHECK-NEXT: .long 0 @@ -165,8 +165,14 @@ ; CHECK-NEXT: .long "?f@@YAXXZ.catch1"@IMGREL ; CHECK-NEXT: .long ".L?f@@YAXXZ.catch1$parent_frame_offset" ; CHECK-NEXT:"$ip2state$?f@@YAXXZ": +; CHECK-NEXT: .long .Lfunc_begin0@IMGREL +; CHECK-NEXT: .long 2 ; CHECK-NEXT: .long .Ltmp0@IMGREL ; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long .Lfunc_begin1@IMGREL +; CHECK-NEXT: .long 3 +; CHECK-NEXT: .long .Lfunc_begin2@IMGREL +; CHECK-NEXT: .long -1 ; CHECK-NEXT: .long .Ltmp13@IMGREL ; CHECK-NEXT: .long 1 ; CHECK-NEXT: .long .Ltmp16@IMGREL Index: test/CodeGen/WinEH/cppeh-prepared-cleanups.ll =================================================================== --- test/CodeGen/WinEH/cppeh-prepared-cleanups.ll +++ test/CodeGen/WinEH/cppeh-prepared-cleanups.ll @@ -36,7 +36,7 @@ ; CHECK-NEXT: .long ("$stateUnwindMap$?test1@@YAXXZ")@IMGREL ; CHECK-NEXT: .long 0 ; CHECK-NEXT: .long 0 -; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 2 ; CHECK-NEXT: .long ("$ip2state$?test1@@YAXXZ")@IMGREL ; CHECK-NEXT: .long 32 ; CHECK-NEXT: .long 0 @@ -45,6 +45,8 @@ ; CHECK-NEXT: .long -1 ; CHECK-NEXT: .long "?test1@@YAXXZ.cleanup"@IMGREL ; CHECK-NEXT:"$ip2state$?test1@@YAXXZ": +; CHECK-NEXT: .long .Lfunc_begin0@IMGREL +; CHECK-NEXT: .long -1 ; CHECK-NEXT: .long .Ltmp0@IMGREL ; CHECK-NEXT: .long 0 Index: test/CodeGen/WinEH/cppeh-state-calc-1.ll =================================================================== --- test/CodeGen/WinEH/cppeh-state-calc-1.ll +++ test/CodeGen/WinEH/cppeh-state-calc-1.ll @@ -0,0 +1,289 @@ +; RUN: llc < %s | FileCheck %s + +; This test was generated from the following code. +; +; void test() { +; try { +; try { +; try { +; two(); +; throw 2; +; } catch (int x) { +; catch_two(); +; } +; a(); +; throw 'a'; +; } catch (char c) { +; catch_a(); +; } +; one(); +; throw 1; +; } catch(int x) { +; catch_one(); +; } catch(...) { +; catch_all(); +; } +; } +; +; The function calls before the throws were declared as 'noexcept' and are +; just here to make blocks easier to identify in the IR. + +; ModuleID = '' +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] } +%eh.CatchHandlerType = type { i32, i8* } +%eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 } +%eh.CatchableTypeArray.1 = type { i32, [1 x i32] } +%eh.ThrowInfo = type { i32, i32, i32, i32 } + +$"\01??_R0H@8" = comdat any + +$"\01??_R0D@8" = comdat any + +$"_CT??_R0H@84" = comdat any + +$_CTA1H = comdat any + +$_TI1H = comdat any + +$"_CT??_R0D@81" = comdat any + +$_CTA1D = comdat any + +$_TI1D = comdat any + +@"\01??_7type_info@@6B@" = external constant i8* +@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat +@llvm.eh.handlertype.H.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata" +@"\01??_R0D@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".D\00" }, comdat +@llvm.eh.handlertype.D.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0D@8" to i8*) }, section "llvm.metadata" +@__ImageBase = external constant i8 +@"_CT??_R0H@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 4, i32 0 }, section ".xdata", comdat +@_CTA1H = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableType* @"_CT??_R0H@84" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32)] }, section ".xdata", comdat +@_TI1H = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableTypeArray.1* @_CTA1H to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section ".xdata", comdat +@"_CT??_R0D@81" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor2* @"\01??_R0D@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 1, i32 0 }, section ".xdata", comdat +@_CTA1D = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableType* @"_CT??_R0D@81" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32)] }, section ".xdata", comdat +@_TI1D = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableTypeArray.1* @_CTA1D to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section ".xdata", comdat + +; Function Attrs: nounwind uwtable +define void @"\01?test@@YAXXZ"() #0 { +entry: + %tmp = alloca i32, align 4 + %x = alloca i32, align 4 + %tmp2 = alloca i8, align 1 + %c = alloca i8, align 1 + %tmp11 = alloca i32, align 4 + %x21 = alloca i32, align 4 + call void @"\01?two@@YAXXZ"() #3 + store i32 2, i32* %tmp + %0 = bitcast i32* %tmp to i8* + call void (...) @llvm.frameescape(i32* %x, i8* %c, i32* %x21) + invoke void @_CxxThrowException(i8* %0, %eh.ThrowInfo* @_TI1H) #5 + to label %unreachable unwind label %lpad + +lpad: ; preds = %entry + %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) + catch i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*) + catch %eh.CatchHandlerType* @llvm.eh.handlertype.D.0 + catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0 + catch i8* null + %recover = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*), i32 0, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch", i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.D.0 to i8*), i32 1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1", i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch2", i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch3") + indirectbr i8* %recover, [label %try.cont, label %try.cont10, label %try.cont22] + +try.cont: ; preds = %lpad + call void @"\01?a@@YAXXZ"() #3 + store i8 97, i8* %tmp2 + invoke void @_CxxThrowException(i8* %tmp2, %eh.ThrowInfo* @_TI1D) #5 + to label %unreachable unwind label %lpad3 + +lpad3: ; preds = %try.cont + %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) + catch %eh.CatchHandlerType* @llvm.eh.handlertype.D.0 + catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0 + catch i8* null + %recover1 = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.D.0 to i8*), i32 1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1", i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch2", i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch3") + indirectbr i8* %recover1, [label %try.cont10, label %try.cont22] + +try.cont10: ; preds = %lpad3, %lpad + call void @"\01?one@@YAXXZ"() #3 + store i32 1, i32* %tmp11 + %3 = bitcast i32* %tmp11 to i8* + invoke void @_CxxThrowException(i8* %3, %eh.ThrowInfo* @_TI1H) #5 + to label %unreachable unwind label %lpad12 + +lpad12: ; preds = %try.cont10 + %4 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) + catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0 + catch i8* null + %recover2 = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch2", i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch3") + indirectbr i8* %recover2, [label %try.cont22] + +try.cont22: ; preds = %lpad12, %lpad3, %lpad + ret void + +unreachable: ; preds = %try.cont10, %try.cont, %entry + unreachable +} + +; Function Attrs: nounwind +declare void @"\01?two@@YAXXZ"() #1 + +declare void @_CxxThrowException(i8*, %eh.ThrowInfo*) + +declare i32 @__CxxFrameHandler3(...) + +; Function Attrs: nounwind readnone +declare i32 @llvm.eh.typeid.for(i8*) #2 + +; Function Attrs: nounwind +declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3 + +; Function Attrs: nounwind +declare void @"\01?catch_two@@YAXXZ"() #1 + +; Function Attrs: nounwind +declare void @llvm.eh.endcatch() #3 + +; Function Attrs: nounwind +declare void @"\01?a@@YAXXZ"() #1 + +; Function Attrs: nounwind +declare void @"\01?catch_a@@YAXXZ"() #1 + +; Function Attrs: nounwind +declare void @"\01?one@@YAXXZ"() #1 + +; Function Attrs: nounwind +declare void @"\01?catch_all@@YAXXZ"() #1 + +; Function Attrs: nounwind +declare void @"\01?catch_one@@YAXXZ"() #1 + +; Function Attrs: nounwind +declare i8* @llvm.eh.actions(...) #3 + +define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) #4 { +entry: + %x.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0) + %x = bitcast i8* %x.i8 to i32* + %2 = bitcast i32* %x to i8* + call void @"\01?catch_two@@YAXXZ"() #3 + invoke void @llvm.donothing() + to label %entry.split unwind label %stub + +entry.split: ; preds = %entry + ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont) + +stub: ; preds = %entry + %3 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) + cleanup + %recover = call i8* (...) @llvm.eh.actions() + unreachable +} + +; Function Attrs: nounwind readnone +declare void @llvm.donothing() #2 + +define internal i8* @"\01?test@@YAXXZ.catch1"(i8*, i8*) #4 { +entry: + call void @"\01?catch_a@@YAXXZ"() #3 + invoke void @llvm.donothing() + to label %entry.split unwind label %stub + +entry.split: ; preds = %entry + ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont10) + +stub: ; preds = %entry + %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) + cleanup + %recover = call i8* (...) @llvm.eh.actions() + unreachable +} + +define internal i8* @"\01?test@@YAXXZ.catch2"(i8*, i8*) #4 { +entry: + %x21.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2) + %x21 = bitcast i8* %x21.i8 to i32* + %2 = bitcast i32* %x21 to i8* + call void @"\01?catch_one@@YAXXZ"() #3 + invoke void @llvm.donothing() + to label %entry.split unwind label %stub + +entry.split: ; preds = %entry + ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont22) + +stub: ; preds = %entry + %3 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) + cleanup + %recover = call i8* (...) @llvm.eh.actions() + unreachable +} + +define internal i8* @"\01?test@@YAXXZ.catch3"(i8*, i8*) #4 { +entry: + call void @"\01?catch_all@@YAXXZ"() #3 + invoke void @llvm.donothing() + to label %entry.split unwind label %stub + +entry.split: ; preds = %entry + ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont22) + +stub: ; preds = %entry + %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) + cleanup + %recover = call i8* (...) @llvm.eh.actions() + unreachable +} + +; Function Attrs: nounwind +declare void @llvm.frameescape(...) #3 + +; Function Attrs: nounwind readnone +declare i8* @llvm.framerecover(i8*, i8*, i32) #2 + +attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" "wineh-parent"="?test@@YAXXZ" } +attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { nounwind readnone } +attributes #3 = { nounwind } +attributes #4 = { "wineh-parent"="?test@@YAXXZ" } +attributes #5 = { noreturn } + +!llvm.module.flags = !{!0} +!llvm.ident = !{!1} + +!0 = !{i32 1, !"PIC Level", i32 2} +!1 = !{!"clang version 3.7.0 (trunk 236059)"} + +; CHECK-LABEL: "$cppxdata$?test@@YAXXZ": +; CHECK-NEXT: .long 429065506 +; CHECK-NEXT: .long +; CHECK-NEXT: .long ("$stateUnwindMap$?test@@YAXXZ")@IMGREL +; CHECK-NEXT: .long +; CHECK-NEXT: .long ("$tryMap$?test@@YAXXZ")@IMGREL +; CHECK-NEXT: .long +; CHECK-NEXT: .long ("$ip2state$?test@@YAXXZ")@IMGREL +; CHECK-NEXT: .long 40 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 1 +; CHECK: "$stateUnwindMap$?test@@YAXXZ": +; CHECK: "$tryMap$?test@@YAXXZ": +; CHECK: "$handlerMap$0$?test@@YAXXZ": +; CHECK: "$ip2state$?test@@YAXXZ": +; CHECK-NEXT: .long .Lfunc_begin0@IMGREL +; CHECK-NEXT: .long -1 +; CHECK-NEXT: .long .Ltmp0@IMGREL +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long .Ltmp3@IMGREL +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long .Ltmp6@IMGREL +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long .Lfunc_begin1@IMGREL +; CHECK-NEXT: .long 3 +; CHECK-NEXT: .long .Lfunc_begin2@IMGREL +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long .Lfunc_begin3@IMGREL +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long .Lfunc_begin4@IMGREL +; CHECK-NEXT: .long 6