OSDN Git Service

Disable FP elimination in funcs using 32-bit MSVC EH personalities
authorReid Kleckner <reid@kleckner.net>
Fri, 29 May 2015 21:58:11 +0000 (21:58 +0000)
committerReid Kleckner <reid@kleckner.net>
Fri, 29 May 2015 21:58:11 +0000 (21:58 +0000)
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
test/CodeGen/X86/win32-eh-states.ll
test/CodeGen/X86/win32-eh.ll

index 1a205e8..8a4a816 100644 (file)
@@ -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<MachineModuleInfo>();
index 6d56128..8db127d 100644 (file)
@@ -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
 
index 2cdf601..ea1029e 100644 (file)
@@ -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