From 6ddae31045615b4f4e7005427d013e525b73bbd3 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 5 Nov 2015 21:09:49 +0000 Subject: [WinEH] Fix funclet prologues with stack realignment We already had a test for this for 32-bit SEH catchpads, but those don't actually create funclets. We had a bug that only appeared in funclet prologues, where we would establish EBP and ESI as our FP and BP, and then downstream prologue code would overwrite them. While I was at it, I fixed Win64+funclets+stackrealign. This issue doesn't come up as often there due to the ABI requring 16 byte stack alignment, but now we can rest easy that AVX and WinEH will work well together =P. llvm-svn: 252210 --- llvm/lib/CodeGen/AsmPrinter/WinException.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'llvm/lib/CodeGen/AsmPrinter/WinException.cpp') diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp index 3999268b407..33eb3906fce 100644 --- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp @@ -299,12 +299,17 @@ const MCExpr *WinException::getOffsetPlusOne(const MCSymbol *OffsetOf, Asm->OutContext); } -int WinException::getFrameIndexOffset(int FrameIndex) { +int WinException::getFrameIndexOffset(int FrameIndex, WinEHFuncInfo &FuncInfo) { const TargetFrameLowering &TFI = *Asm->MF->getSubtarget().getFrameLowering(); unsigned UnusedReg; if (Asm->MAI->usesWindowsCFI()) return TFI.getFrameIndexReferenceFromSP(*Asm->MF, FrameIndex, UnusedReg); - return TFI.getFrameIndexReference(*Asm->MF, FrameIndex, UnusedReg); + // For 32-bit, offsets should be relative to the end of the EH registration + // node. For 64-bit, it's relative to SP at the end of the prologue. + assert(FuncInfo.EHRegNodeEndOffset != INT_MAX); + int Offset = TFI.getFrameIndexReference(*Asm->MF, FrameIndex, UnusedReg); + Offset += FuncInfo.EHRegNodeEndOffset; + return Offset; } namespace { @@ -613,7 +618,8 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) { int UnwindHelpOffset = 0; if (Asm->MAI->usesWindowsCFI()) - UnwindHelpOffset = getFrameIndexOffset(FuncInfo.UnwindHelpFrameIdx); + UnwindHelpOffset = + getFrameIndexOffset(FuncInfo.UnwindHelpFrameIdx, FuncInfo); MCSymbol *UnwindMapXData = nullptr; MCSymbol *TryBlockMapXData = nullptr; @@ -733,14 +739,7 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) { // emit an offset of zero, indicating that no copy will occur. const MCExpr *FrameAllocOffsetRef = nullptr; if (HT.CatchObj.FrameIndex != INT_MAX) { - int Offset = getFrameIndexOffset(HT.CatchObj.FrameIndex); - // For 32-bit, the catch object offset is relative to the end of the - // EH registration node. For 64-bit, it's relative to SP at the end of - // the prologue. - if (!shouldEmitPersonality) { - assert(FuncInfo.EHRegNodeEndOffset != INT_MAX); - Offset += FuncInfo.EHRegNodeEndOffset; - } + int Offset = getFrameIndexOffset(HT.CatchObj.FrameIndex, FuncInfo); FrameAllocOffsetRef = MCConstantExpr::create(Offset, Asm->OutContext); } else { FrameAllocOffsetRef = MCConstantExpr::create(0, Asm->OutContext); -- cgit v1.2.3