llvm.org GIT mirror llvm / 03d0b14
[WinEH] Undo the effect of r249578 for 32-bit The __CxxFrameHandler3 tables for 32-bit are supposed to hold stack offsets relative to EBP, not ESP. I blindly updated the win-catchpad.ll test case, and immediately noticed that 32-bit catching stopped working. While I'm at it, move the frame index to frame offset WinEH table logic out of PEI. PEI shouldn't have to know about WinEHFuncInfo. I realized we can calculate frame index offsets just fine from the table printer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249618 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 4 years ago
5 changed file(s) with 23 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
146146 /// index, and after PEI, becomes a raw offset.
147147 union {
148148 const AllocaInst *Alloca;
149 int FrameOffset;
150149 int FrameIndex;
151150 } CatchObj = {};
152151 GlobalVariable *TypeDescriptor;
179178 SmallVector SEHUnwindMap;
180179 SmallVector ClrEHUnwindMap;
181180 int UnwindHelpFrameIdx = INT_MAX;
182 int UnwindHelpFrameOffset = -1;
183181
184182 int getLastStateNumber() const { return UnwindMap.size() - 1; }
185183
3737 #include "llvm/Target/TargetLoweringObjectFile.h"
3838 #include "llvm/Target/TargetOptions.h"
3939 #include "llvm/Target/TargetRegisterInfo.h"
40 #include "llvm/Target/TargetSubtargetInfo.h"
4041 using namespace llvm;
4142
4243 WinException::WinException(AsmPrinter *A) : EHStreamer(A) {
289290 return MCBinaryExpr::createAdd(create32bitRef(Label),
290291 MCConstantExpr::create(1, Asm->OutContext),
291292 Asm->OutContext);
293 }
294
295 int WinException::getFrameIndexOffset(int FrameIndex) {
296 const TargetFrameLowering &TFI = *Asm->MF->getSubtarget().getFrameLowering();
297 unsigned UnusedReg;
298 if (Asm->MAI->usesWindowsCFI())
299 return TFI.getFrameIndexReferenceFromSP(*Asm->MF, FrameIndex, UnusedReg);
300 return TFI.getFrameIndexReference(*Asm->MF, FrameIndex, UnusedReg);
292301 }
293302
294303 namespace {
598607 emitEHRegistrationOffsetLabel(FuncInfo, FuncLinkageName);
599608 }
600609
610 int UnwindHelpOffset = 0;
611 if (Asm->MAI->usesWindowsCFI())
612 UnwindHelpOffset = getFrameIndexOffset(FuncInfo.UnwindHelpFrameIdx);
613
601614 MCSymbol *UnwindMapXData = nullptr;
602615 MCSymbol *TryBlockMapXData = nullptr;
603616 MCSymbol *IPToStateXData = nullptr;
636649 OS.EmitIntValue(IPToStateTable.size(), 4); // IPMapEntries
637650 OS.EmitValue(create32bitRef(IPToStateXData), 4); // IPToStateMap
638651 if (Asm->MAI->usesWindowsCFI())
639 OS.EmitIntValue(FuncInfo.UnwindHelpFrameOffset, 4); // UnwindHelp
652 OS.EmitIntValue(UnwindHelpOffset, 4); // UnwindHelp
640653 OS.EmitIntValue(0, 4); // ESTypeList
641654 OS.EmitIntValue(1, 4); // EHFlags
642655
713726 FuncLinkageName, HT.CatchObjRecoverIdx);
714727 FrameAllocOffsetRef = MCSymbolRefExpr::create(
715728 FrameAllocOffset, MCSymbolRefExpr::VK_None, Asm->OutContext);
716 } else if (HT.CatchObj.FrameOffset != INT_MAX) {
717 int Offset = HT.CatchObj.FrameOffset;
729 } else if (HT.CatchObj.FrameIndex != INT_MAX) {
730 int Offset = getFrameIndexOffset(HT.CatchObj.FrameIndex);
718731 // For 32-bit, the catch object offset is relative to the end of the
719732 // EH registration node. For 64-bit, it's relative to SP at the end of
720733 // the prologue.
6262 const MCExpr *create32bitRef(const Value *V);
6363 const MCExpr *getLabelPlusOne(MCSymbol *Label);
6464
65 /// Gets the offset that we should use in a table for a stack object with the
66 /// given index. For targets using CFI (Win64, etc), this is relative to the
67 /// established SP at the end of the prologue. For targets without CFI (Win32
68 /// only), it is relative to the frame pointer.
69 int getFrameIndexOffset(int FrameIndex);
70
6571 public:
6672 //===--------------------------------------------------------------------===//
6773 // Main entry points.
806806 const TargetFrameLowering &TFI = *Fn.getSubtarget().getFrameLowering();
807807 if (!TFI.needsFrameIndexResolution(Fn)) return;
808808
809 MachineModuleInfo &MMI = Fn.getMMI();
810 const Function *F = Fn.getFunction();
811 const Function *ParentF = MMI.getWinEHParent(F);
812 unsigned FrameReg;
813 if (F == ParentF) {
814 WinEHFuncInfo &FuncInfo = MMI.getWinEHFuncInfo(Fn.getFunction());
815 // FIXME: This should be unconditional but we have bugs in the preparation
816 // pass.
817 if (FuncInfo.UnwindHelpFrameIdx != INT_MAX)
818 FuncInfo.UnwindHelpFrameOffset = TFI.getFrameIndexReferenceFromSP(
819 Fn, FuncInfo.UnwindHelpFrameIdx, FrameReg);
820 for (WinEHTryBlockMapEntry &TBME : FuncInfo.TryBlockMap) {
821 for (WinEHHandlerType &H : TBME.HandlerArray) {
822 if (H.CatchObj.FrameIndex == INT_MAX)
823 H.CatchObj.FrameOffset = INT_MAX;
824 else
825 H.CatchObj.FrameOffset = TFI.getFrameIndexReferenceFromSP(
826 Fn, H.CatchObj.FrameIndex, FrameReg);
827 }
828 }
829 }
830
831809 // Store SPAdj at exit of a basic block.
832810 SmallVector SPState;
833811 SPState.resize(Fn.getNumBlockIDs());
119119 ; X86: $handlerMap$0$try_catch_catch:
120120 ; X86-NEXT: .long 0
121121 ; X86-NEXT: .long "??_R0H@8"
122 ; X86-NEXT: .long 24
122 ; X86-NEXT: .long -20
123123 ; X86-NEXT: .long "?catch$[[catch1bb]]@?0?try_catch_catch@4HA"
124124 ; X86-NEXT: .long 64
125125 ; X86-NEXT: .long 0