[llvm] r249618 - [WinEH] Undo the effect of r249578 for 32-bit
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 7 14:13:16 PDT 2015
Author: rnk
Date: Wed Oct 7 16:13:15 2015
New Revision: 249618
URL: http://llvm.org/viewvc/llvm-project?rev=249618&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/CodeGen/WinEHFuncInfo.h
llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/WinException.h
llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
llvm/trunk/test/CodeGen/X86/win-catchpad.ll
Modified: llvm/trunk/include/llvm/CodeGen/WinEHFuncInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/WinEHFuncInfo.h?rev=249618&r1=249617&r2=249618&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/WinEHFuncInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/WinEHFuncInfo.h Wed Oct 7 16:13:15 2015
@@ -147,7 +147,6 @@ struct WinEHHandlerType {
/// index, and after PEI, becomes a raw offset.
union {
const AllocaInst *Alloca;
- int FrameOffset;
int FrameIndex;
} CatchObj = {};
GlobalVariable *TypeDescriptor;
@@ -180,7 +179,6 @@ struct WinEHFuncInfo {
SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
SmallVector<ClrEHUnwindMapEntry, 4> ClrEHUnwindMap;
int UnwindHelpFrameIdx = INT_MAX;
- int UnwindHelpFrameOffset = -1;
int getLastStateNumber() const { return UnwindMap.size() - 1; }
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp?rev=249618&r1=249617&r2=249618&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp Wed Oct 7 16:13:15 2015
@@ -38,6 +38,7 @@
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegisterInfo.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
using namespace llvm;
WinException::WinException(AsmPrinter *A) : EHStreamer(A) {
@@ -292,6 +293,14 @@ const MCExpr *WinException::getLabelPlus
Asm->OutContext);
}
+int WinException::getFrameIndexOffset(int FrameIndex) {
+ 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);
+}
+
namespace {
/// Information describing an invoke range.
struct InvokeRange {
@@ -599,6 +608,10 @@ void WinException::emitCXXFrameHandler3T
emitEHRegistrationOffsetLabel(FuncInfo, FuncLinkageName);
}
+ int UnwindHelpOffset = 0;
+ if (Asm->MAI->usesWindowsCFI())
+ UnwindHelpOffset = getFrameIndexOffset(FuncInfo.UnwindHelpFrameIdx);
+
MCSymbol *UnwindMapXData = nullptr;
MCSymbol *TryBlockMapXData = nullptr;
MCSymbol *IPToStateXData = nullptr;
@@ -637,7 +650,7 @@ void WinException::emitCXXFrameHandler3T
OS.EmitIntValue(IPToStateTable.size(), 4); // IPMapEntries
OS.EmitValue(create32bitRef(IPToStateXData), 4); // IPToStateMap
if (Asm->MAI->usesWindowsCFI())
- OS.EmitIntValue(FuncInfo.UnwindHelpFrameOffset, 4); // UnwindHelp
+ OS.EmitIntValue(UnwindHelpOffset, 4); // UnwindHelp
OS.EmitIntValue(0, 4); // ESTypeList
OS.EmitIntValue(1, 4); // EHFlags
@@ -714,8 +727,8 @@ void WinException::emitCXXFrameHandler3T
FuncLinkageName, HT.CatchObjRecoverIdx);
FrameAllocOffsetRef = MCSymbolRefExpr::create(
FrameAllocOffset, MCSymbolRefExpr::VK_None, Asm->OutContext);
- } else if (HT.CatchObj.FrameOffset != INT_MAX) {
- int Offset = HT.CatchObj.FrameOffset;
+ } else 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.
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/WinException.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/WinException.h?rev=249618&r1=249617&r2=249618&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/WinException.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/WinException.h Wed Oct 7 16:13:15 2015
@@ -63,6 +63,12 @@ class LLVM_LIBRARY_VISIBILITY WinExcepti
const MCExpr *create32bitRef(const Value *V);
const MCExpr *getLabelPlusOne(MCSymbol *Label);
+ /// Gets the offset that we should use in a table for a stack object with the
+ /// given index. For targets using CFI (Win64, etc), this is relative to the
+ /// established SP at the end of the prologue. For targets without CFI (Win32
+ /// only), it is relative to the frame pointer.
+ int getFrameIndexOffset(int FrameIndex);
+
public:
//===--------------------------------------------------------------------===//
// Main entry points.
Modified: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp?rev=249618&r1=249617&r2=249618&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp (original)
+++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp Wed Oct 7 16:13:15 2015
@@ -807,28 +807,6 @@ void PEI::replaceFrameIndices(MachineFun
const TargetFrameLowering &TFI = *Fn.getSubtarget().getFrameLowering();
if (!TFI.needsFrameIndexResolution(Fn)) return;
- MachineModuleInfo &MMI = Fn.getMMI();
- const Function *F = Fn.getFunction();
- const Function *ParentF = MMI.getWinEHParent(F);
- unsigned FrameReg;
- if (F == ParentF) {
- WinEHFuncInfo &FuncInfo = MMI.getWinEHFuncInfo(Fn.getFunction());
- // FIXME: This should be unconditional but we have bugs in the preparation
- // pass.
- if (FuncInfo.UnwindHelpFrameIdx != INT_MAX)
- FuncInfo.UnwindHelpFrameOffset = TFI.getFrameIndexReferenceFromSP(
- Fn, FuncInfo.UnwindHelpFrameIdx, FrameReg);
- for (WinEHTryBlockMapEntry &TBME : FuncInfo.TryBlockMap) {
- for (WinEHHandlerType &H : TBME.HandlerArray) {
- if (H.CatchObj.FrameIndex == INT_MAX)
- H.CatchObj.FrameOffset = INT_MAX;
- else
- H.CatchObj.FrameOffset = TFI.getFrameIndexReferenceFromSP(
- Fn, H.CatchObj.FrameIndex, FrameReg);
- }
- }
- }
-
// Store SPAdj at exit of a basic block.
SmallVector<int, 8> SPState;
SPState.resize(Fn.getNumBlockIDs());
Modified: llvm/trunk/test/CodeGen/X86/win-catchpad.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/win-catchpad.ll?rev=249618&r1=249617&r2=249618&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/win-catchpad.ll (original)
+++ llvm/trunk/test/CodeGen/X86/win-catchpad.ll Wed Oct 7 16:13:15 2015
@@ -120,7 +120,7 @@ catchendblock:
; X86: $handlerMap$0$try_catch_catch:
; X86-NEXT: .long 0
; X86-NEXT: .long "??_R0H at 8"
-; X86-NEXT: .long 24
+; X86-NEXT: .long -20
; X86-NEXT: .long "?catch$[[catch1bb]]@?0?try_catch_catch at 4HA"
; X86-NEXT: .long 64
; X86-NEXT: .long 0
More information about the llvm-commits
mailing list