From f0e3e4cd84a73ebd9b5edf35a915431a5419614e Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 29 May 2015 21:58:11 +0000 Subject: [PATCH] Disable FP elimination in funcs using 32-bit MSVC EH personalities The value in 'ebp' acts as an implicit argument to the outlined handlers, and is recovered with frameaddress(1). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238619 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86WinEHState.cpp | 5 ++++ test/CodeGen/X86/win32-eh-states.ll | 6 ++--- test/CodeGen/X86/win32-eh.ll | 46 +++++++++++++++++++++---------------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/lib/Target/X86/X86WinEHState.cpp b/lib/Target/X86/X86WinEHState.cpp index 1a205e8aec4..8a4a8161a03 100644 --- a/lib/Target/X86/X86WinEHState.cpp +++ b/lib/Target/X86/X86WinEHState.cpp @@ -155,6 +155,11 @@ bool WinEHStatePass::runOnFunction(Function &F) { if (!isMSVCEHPersonality(Personality)) return false; + // Disable frame pointer elimination in this function. + // FIXME: Do the nested handlers need to keep the parent ebp in ebp, or can we + // use an arbitrary register? + F.addFnAttr("no-frame-pointer-elim", "true"); + emitExceptionRegistrationRecord(&F); auto *MMIPtr = getAnalysisIfAvailable(); diff --git a/test/CodeGen/X86/win32-eh-states.ll b/test/CodeGen/X86/win32-eh-states.ll index 6d561280367..8db127df6da 100644 --- a/test/CodeGen/X86/win32-eh-states.ll +++ b/test/CodeGen/X86/win32-eh-states.ll @@ -90,14 +90,14 @@ eh.resume: ; preds = %catch.dispatch.4 } ; CHECK-LABEL: _f: -; CHECK: movl $-1, [[state:[0-9]+]](%esp) +; CHECK: movl $-1, [[state:[-0-9]+]](%ebp) ; CHECK: movl $___ehhandler$f, {{.*}} ; -; CHECK: movl $0, [[state]](%esp) +; CHECK: movl $0, [[state]](%ebp) ; CHECK: movl $1, (%esp) ; CHECK: calll _may_throw ; -; CHECK: movl $1, [[state]](%esp) +; CHECK: movl $1, [[state]](%ebp) ; CHECK: movl $2, (%esp) ; CHECK: calll _may_throw diff --git a/test/CodeGen/X86/win32-eh.ll b/test/CodeGen/X86/win32-eh.ll index 2cdf6011ff7..ea1029ea3f2 100644 --- a/test/CodeGen/X86/win32-eh.ll +++ b/test/CodeGen/X86/win32-eh.ll @@ -19,16 +19,18 @@ catchall: } ; CHECK-LABEL: _use_except_handler3: +; CHECK: pushl %ebp +; CHECK: movl %esp, %ebp ; CHECK: subl ${{[0-9]+}}, %esp -; CHECK: movl $-1, 12(%esp) -; CHECK: movl $L__ehtable$use_except_handler3, 8(%esp) -; CHECK: movl $__except_handler3, 4(%esp) +; CHECK: movl $-1, -4(%ebp) +; CHECK: movl $L__ehtable$use_except_handler3, -8(%ebp) +; CHECK: movl $__except_handler3, -12(%ebp) ; CHECK: movl %fs:0, %[[next:[^ ,]*]] -; CHECK: movl %[[next]], (%esp) -; CHECK: leal (%esp), %[[node:[^ ,]*]] +; CHECK: movl %[[next]], -16(%ebp) +; CHECK: leal -16(%ebp), %[[node:[^ ,]*]] ; CHECK: movl %[[node]], %fs:0 ; CHECK: calll _may_throw_or_crash -; CHECK: movl (%esp), %[[next:[^ ,]*]] +; CHECK: movl -16(%ebp), %[[next:[^ ,]*]] ; CHECK: movl %[[next]], %fs:0 ; CHECK: retl @@ -44,17 +46,19 @@ catchall: } ; CHECK-LABEL: _use_except_handler4: +; CHECK: pushl %ebp +; CHECK: movl %esp, %ebp ; CHECK: subl ${{[0-9]+}}, %esp -; CHECK: movl %esp, (%esp) -; CHECK: movl $-1, 20(%esp) -; CHECK: movl $L__ehtable$use_except_handler4, 4(%esp) -; CHECK: leal 8(%esp), %[[node:[^ ,]*]] -; CHECK: movl $__except_handler4, 12(%esp) +; CHECK: movl %esp, -24(%ebp) +; CHECK: movl $-1, -4(%ebp) +; CHECK: movl $L__ehtable$use_except_handler4, -20(%ebp) +; CHECK: leal -16(%ebp), %[[node:[^ ,]*]] +; CHECK: movl $__except_handler4, -12(%ebp) ; CHECK: movl %fs:0, %[[next:[^ ,]*]] -; CHECK: movl %[[next]], 8(%esp) +; CHECK: movl %[[next]], -16(%ebp) ; CHECK: movl %[[node]], %fs:0 ; CHECK: calll _may_throw_or_crash -; CHECK: movl 8(%esp), %[[next:[^ ,]*]] +; CHECK: movl -16(%ebp), %[[next:[^ ,]*]] ; CHECK: movl %[[next]], %fs:0 ; CHECK: retl @@ -73,17 +77,19 @@ catchall: } ; CHECK-LABEL: _use_CxxFrameHandler3: +; CHECK: pushl %ebp +; CHECK: movl %esp, %ebp ; CHECK: subl ${{[0-9]+}}, %esp -; CHECK: movl %esp, (%esp) -; CHECK: movl $-1, 12(%esp) -; CHECK: leal 4(%esp), %[[node:[^ ,]*]] -; CHECK: movl $___ehhandler$use_CxxFrameHandler3, 8(%esp) +; CHECK: movl %esp, -16(%ebp) +; CHECK: movl $-1, -4(%ebp) +; CHECK: leal -12(%ebp), %[[node:[^ ,]*]] +; CHECK: movl $___ehhandler$use_CxxFrameHandler3, -8(%ebp) ; CHECK: movl %fs:0, %[[next:[^ ,]*]] -; CHECK: movl %[[next]], 4(%esp) +; CHECK: movl %[[next]], -12(%ebp) ; CHECK: movl %[[node]], %fs:0 -; CHECK: movl $0, 12(%esp) +; CHECK: movl $0, -4(%ebp) ; CHECK: calll _may_throw_or_crash -; CHECK: movl 4(%esp), %[[next:[^ ,]*]] +; CHECK: movl -12(%ebp), %[[next:[^ ,]*]] ; CHECK: movl %[[next]], %fs:0 ; CHECK: retl -- 2.11.0