diff --git a/include/llvm/CodeGen/WinEHFuncInfo.h b/include/llvm/CodeGen/WinEHFuncInfo.h index 732b5d24952..9b826754015 100644 --- a/include/llvm/CodeGen/WinEHFuncInfo.h +++ b/include/llvm/CodeGen/WinEHFuncInfo.h @@ -128,7 +128,6 @@ struct WinEHHandlerType { struct WinEHTryBlockMapEntry { int TryLow; int TryHigh; - int CatchHigh; SmallVector HandlerArray; }; @@ -136,6 +135,7 @@ struct WinEHFuncInfo { DenseMap LandingPadStateMap; DenseMap CatchHandlerParentFrameObjIdx; DenseMap CatchHandlerParentFrameObjOffset; + DenseMap CatchHandlerMaxState; SmallVector UnwindMap; SmallVector TryBlockMap; SmallVector, 4> IPToStateList; diff --git a/lib/CodeGen/AsmPrinter/Win64Exception.cpp b/lib/CodeGen/AsmPrinter/Win64Exception.cpp index 676ce65dedb..3bfcaa96593 100644 --- a/lib/CodeGen/AsmPrinter/Win64Exception.cpp +++ b/lib/CodeGen/AsmPrinter/Win64Exception.cpp @@ -421,11 +421,16 @@ void Win64Exception::emitCXXFrameHandler3Table(const MachineFunction *MF) { HandlerMaps.push_back(HandlerMapXData); + int CatchHigh = -1; + for (WinEHHandlerType &HT : TBME.HandlerArray) + CatchHigh = + std::max(CatchHigh, FuncInfo.CatchHandlerMaxState[HT.Handler]); + assert(TBME.TryLow <= TBME.TryHigh); - assert(TBME.CatchHigh > TBME.TryHigh); + assert(CatchHigh > TBME.TryHigh); OS.EmitIntValue(TBME.TryLow, 4); // TryLow OS.EmitIntValue(TBME.TryHigh, 4); // TryHigh - OS.EmitIntValue(TBME.CatchHigh, 4); // CatchHigh + OS.EmitIntValue(CatchHigh, 4); // CatchHigh OS.EmitIntValue(TBME.HandlerArray.size(), 4); // NumCatches OS.EmitValue(createImageRel32(HandlerMapXData), 4); // HandlerArray } diff --git a/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp index bfaab9e6b6b..4547906c275 100644 --- a/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ b/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -300,11 +300,7 @@ void WinEHNumbering::createTryBlockMapEntry(int TryLow, int TryHigh, WinEHTryBlockMapEntry TBME; TBME.TryLow = TryLow; TBME.TryHigh = TryHigh; - // FIXME: This should be revisited when we want to throw inside a catch - // handler. - TBME.CatchHigh = INT_MAX; assert(TBME.TryLow <= TBME.TryHigh); - assert(TBME.CatchHigh > TBME.TryHigh); for (CatchHandler *CH : Handlers) { WinEHHandlerType HT; if (CH->getSelector()->isNullValue()) { @@ -444,6 +440,8 @@ void WinEHNumbering::calculateStateNumbers(const Function &F) { ActionList.clear(); FuncInfo.LandingPadStateMap[LPI] = currentEHNumber(); } + + FuncInfo.CatchHandlerMaxState[&F] = NextState - 1; } /// clear - Clear out all the function-specific state. This returns this diff --git a/test/CodeGen/WinEH/cppeh-prepared-catch.ll b/test/CodeGen/WinEH/cppeh-prepared-catch.ll index 937b216edbd..7c53085edc5 100644 --- a/test/CodeGen/WinEH/cppeh-prepared-catch.ll +++ b/test/CodeGen/WinEH/cppeh-prepared-catch.ll @@ -137,12 +137,12 @@ try.cont8: ; preds = %lpad2, %try.cont ; CHECK-NEXT:"$tryMap$?f@@YAXXZ": ; CHECK-NEXT: .long 1 ; CHECK-NEXT: .long 1 -; CHECK-NEXT: .long 2147483647 +; CHECK-NEXT: .long 2 ; CHECK-NEXT: .long 1 ; CHECK-NEXT: .long ("$handlerMap$0$?f@@YAXXZ")@IMGREL ; CHECK-NEXT: .long 0 ; CHECK-NEXT: .long 2 -; CHECK-NEXT: .long 2147483647 +; CHECK-NEXT: .long 3 ; CHECK-NEXT: .long 1 ; CHECK-NEXT: .long ("$handlerMap$1$?f@@YAXXZ")@IMGREL ; CHECK-NEXT:"$handlerMap$0$?f@@YAXXZ":