From bf3672857eab1e9dc38ed20f78129e691de646ff Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Mon, 12 Aug 2019 23:02:00 +0000 Subject: [PATCH] [WinEH] Fix catch block parent frame pointer offset r367088 made it so that funclets store XMM registers into their local frame instead of storing them to the parent frame. However, that change forgot to update the parent frame pointer offset for catch blocks. This change does that. Fixes crashes when an exception is rethrown in a catch block that saves XMMs, as described in https://crbug.com/992860. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368631 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86FrameLowering.cpp | 11 ++++++++--- test/CodeGen/X86/win64-funclet-savexmm.ll | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Target/X86/X86FrameLowering.cpp b/lib/Target/X86/X86FrameLowering.cpp index 47be92e5972..9d8cb89dbef 100644 --- a/lib/Target/X86/X86FrameLowering.cpp +++ b/lib/Target/X86/X86FrameLowering.cpp @@ -3191,14 +3191,19 @@ void X86FrameLowering::orderFrameObjects( std::reverse(ObjectsToAllocate.begin(), ObjectsToAllocate.end()); } - -unsigned X86FrameLowering::getWinEHParentFrameOffset(const MachineFunction &MF) const { +unsigned +X86FrameLowering::getWinEHParentFrameOffset(const MachineFunction &MF) const { + const X86MachineFunctionInfo *X86FI = MF.getInfo(); // RDX, the parent frame pointer, is homed into 16(%rsp) in the prologue. unsigned Offset = 16; // RBP is immediately pushed. Offset += SlotSize; // All callee-saved registers are then pushed. - Offset += MF.getInfo()->getCalleeSavedFrameSize(); + Offset += X86FI->getCalleeSavedFrameSize(); + // Funclets allocate space for however XMM registers are required. + int Ignore; + if (MF.getTarget().getMCAsmInfo()->usesWindowsCFI()) + Offset += X86FI->getCalleeSavedXMMFrameInfo(Ignore); // Every funclet allocates enough stack space for the largest outgoing call. Offset += getWinEHFuncletFrameSize(MF); return Offset; diff --git a/test/CodeGen/X86/win64-funclet-savexmm.ll b/test/CodeGen/X86/win64-funclet-savexmm.ll index f41c52e00ef..6b4b68f1728 100644 --- a/test/CodeGen/X86/win64-funclet-savexmm.ll +++ b/test/CodeGen/X86/win64-funclet-savexmm.ll @@ -66,3 +66,14 @@ unreachable: ; preds = %entry ; CHECK: popq %rbx ; CHECK: popq %rbp ; CHECK: retq # CATCHRET + +; CHECK-LABEL: "$handlerMap$0$?foo@@YAXXZ": +; CHECK-NEXT: .long 0 # Adjectives +; CHECK-NEXT: .long "??_R0H@8"@IMGREL # Type +; CHECK-NEXT: .long 44 # CatchObjOffset +; CHECK-NEXT: .long "?catch${{.*}}??foo@@YAXXZ@4HA"@IMGREL # Handler +; Sum of: +; 16 RDX store offset +; 16 two pushes +; 72 stack alloc +; CHECK-NEXT: .long 104 # ParentFrameOffset -- 2.40.0