[llvm] r253245 - [WinEH] Don't let UnwindHelp alias the return address
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 16 10:47:25 PST 2015
Author: rnk
Date: Mon Nov 16 12:47:25 2015
New Revision: 253245
URL: http://llvm.org/viewvc/llvm-project?rev=253245&view=rev
Log:
[WinEH] Don't let UnwindHelp alias the return address
On top of that, don't bother allocating and initializing UnwindHelp if
we don't have any funclets. Currently we always use RBP as our frame
pointer when funclets are present, so this change makes it impossible to
come here without any fixed stack objects.
Fixes PR25533.
Added:
llvm/trunk/test/CodeGen/X86/wineh-no-ehpads.ll
Modified:
llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
llvm/trunk/test/CodeGen/X86/win-cleanuppad.ll
Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=253245&r1=253244&r2=253245&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Mon Nov 16 12:47:25 2015
@@ -2662,17 +2662,17 @@ void X86FrameLowering::processFunctionBe
// If this function isn't doing Win64-style C++ EH, we don't need to do
// anything.
const Function *Fn = MF.getFunction();
- if (!STI.is64Bit() || !Fn->hasPersonalityFn() ||
- classifyEHPersonality(MF.getFunction()->getPersonalityFn()) !=
- EHPersonality::MSVC_CXX)
+ if (!STI.is64Bit() || !MF.getMMI().hasEHFunclets() ||
+ classifyEHPersonality(Fn->getPersonalityFn()) != EHPersonality::MSVC_CXX)
return;
// Win64 C++ EH needs to allocate the UnwindHelp object at some fixed offset
// relative to RSP after the prologue. Find the offset of the last fixed
- // object, so that we can allocate a slot immediately following it. Fixed
- // objects have negative frame indices.
+ // object, so that we can allocate a slot immediately following it. If there
+ // were no fixed objects, use offset -SlotSize, which is immediately after the
+ // return address. Fixed objects have negative frame indices.
MachineFrameInfo *MFI = MF.getFrameInfo();
- int64_t MinFixedObjOffset = 0;
+ int64_t MinFixedObjOffset = -SlotSize;
for (int I = MFI->getObjectIndexBegin(); I < 0; ++I)
MinFixedObjOffset = std::min(MinFixedObjOffset, MFI->getObjectOffset(I));
Modified: llvm/trunk/test/CodeGen/X86/win-cleanuppad.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/win-cleanuppad.ll?rev=253245&r1=253244&r2=253245&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/win-cleanuppad.ll (original)
+++ llvm/trunk/test/CodeGen/X86/win-cleanuppad.ll Mon Nov 16 12:47:25 2015
@@ -19,6 +19,36 @@ ehcleanup:
cleanupret %0 unwind to caller
}
+; CHECK: simple_cleanup: # @simple_cleanup
+; CHECK: pushq %rbp
+; CHECK: subq $48, %rsp
+; CHECK: leaq 48(%rsp), %rbp
+; CHECK: movq $-2, -8(%rbp)
+; CHECK: movl $1, %ecx
+; CHECK: callq f
+; CHECK: callq "??1Dtor@@QAE at XZ"
+; CHECK: nop
+; CHECK: addq $48, %rsp
+; CHECK: popq %rbp
+; CHECK: retq
+
+; CHECK: "?dtor$2@?0?simple_cleanup at 4HA":
+; CHECK: callq "??1Dtor@@QAE at XZ"
+; CHECK: retq
+
+; CHECK: $cppxdata$simple_cleanup:
+; CHECK-NEXT: .long 429065506
+; CHECK-NEXT: .long 1
+; CHECK-NEXT: .long ($stateUnwindMap$simple_cleanup)@IMGREL
+; CHECK-NEXT: .long 0
+; CHECK-NEXT: .long 0
+; CHECK-NEXT: .long 3
+; CHECK-NEXT: .long ($ip2state$simple_cleanup)@IMGREL
+; UnwindHelp offset should match the -2 store above
+; CHECK-NEXT: .long 40
+; CHECK-NEXT: .long 0
+; CHECK-NEXT: .long 1
+
declare void @f(i32) #0
declare i32 @__CxxFrameHandler3(...)
Added: llvm/trunk/test/CodeGen/X86/wineh-no-ehpads.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/wineh-no-ehpads.ll?rev=253245&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/wineh-no-ehpads.ll (added)
+++ llvm/trunk/test/CodeGen/X86/wineh-no-ehpads.ll Mon Nov 16 12:47:25 2015
@@ -0,0 +1,20 @@
+; RUN: llc < %s | FileCheck %s
+
+target triple = "x86_64-pc-windows-msvc"
+
+declare void @g()
+declare i32 @__CxxFrameHandler3(...)
+
+define void @personality_no_ehpad() personality i32 (...)* @__CxxFrameHandler3 {
+ call void @g()
+ ret void
+}
+
+; CHECK-LABEL: personality_no_ehpad: # @personality_no_ehpad
+; CHECK-NOT: movq $-2,
+; CHECK: callq g
+; CHECK: nop
+; CHECK: retq
+
+; Shouldn't have any LSDA either.
+; CHECK-NOT: cppxdata
More information about the llvm-commits
mailing list