[llvm] r249578 - [WinEH] Fix two minor issues in __CxxFrameHandler3 tables

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 7 10:49:32 PDT 2015


Author: rnk
Date: Wed Oct  7 12:49:32 2015
New Revision: 249578

URL: http://llvm.org/viewvc/llvm-project?rev=249578&view=rev
Log:
[WinEH] Fix two minor issues in __CxxFrameHandler3 tables

There was an off-by-one bug in ip2state tables which manifested when one
call immediately preceded the try-range of the next. The return address
of the previous call would appear to be within the try range of the next
scope, resulting in extra destructors or catches running.

We also computed the wrong offset for catch parameter stack objects. The
offset should be from RSP, not from RBP.

Modified:
    llvm/trunk/include/llvm/Target/TargetFrameLowering.h
    llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
    llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
    llvm/trunk/test/CodeGen/X86/win-catchpad.ll

Modified: llvm/trunk/include/llvm/Target/TargetFrameLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetFrameLowering.h?rev=249578&r1=249577&r2=249578&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetFrameLowering.h (original)
+++ llvm/trunk/include/llvm/Target/TargetFrameLowering.h Wed Oct  7 12:49:32 2015
@@ -236,10 +236,11 @@ public:
                                      unsigned &FrameReg) const;
 
   /// Same as above, except that the 'base register' will always be RSP, not
-  /// RBP on x86.  This is used exclusively for lowering STATEPOINT nodes.
+  /// RBP on x86. This is generally used for emitting statepoint or EH tables
+  /// that use offsets from RSP.
   /// TODO: This should really be a parameterizable choice.
   virtual int getFrameIndexReferenceFromSP(const MachineFunction &MF, int FI,
-                                          unsigned &FrameReg) const {
+                                           unsigned &FrameReg) const {
     // default to calling normal version, we override this on x86 only
     llvm_unreachable("unimplemented for non-x86");
     return 0;

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp?rev=249578&r1=249577&r2=249578&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp Wed Oct  7 12:49:32 2015
@@ -791,7 +791,7 @@ void WinException::computeIP2StateTable(
       // Emit an entry indicating that PCs after 'Label' have this EH state.
       if (I.State != LastEHState)
         IPToStateTable.push_back(
-            std::make_pair(create32bitRef(I.BeginLabel), I.State));
+            std::make_pair(getLabelPlusOne(I.BeginLabel), I.State));
       LastEHState = I.State;
       LastEndLabel = I.EndLabel;
     }

Modified: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp?rev=249578&r1=249577&r2=249578&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp (original)
+++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp Wed Oct  7 12:49:32 2015
@@ -820,12 +820,11 @@ void PEI::replaceFrameIndices(MachineFun
           Fn, FuncInfo.UnwindHelpFrameIdx, FrameReg);
     for (WinEHTryBlockMapEntry &TBME : FuncInfo.TryBlockMap) {
       for (WinEHHandlerType &H : TBME.HandlerArray) {
-        unsigned UnusedReg;
         if (H.CatchObj.FrameIndex == INT_MAX)
           H.CatchObj.FrameOffset = INT_MAX;
         else
-          H.CatchObj.FrameOffset =
-              TFI.getFrameIndexReference(Fn, H.CatchObj.FrameIndex, UnusedReg);
+          H.CatchObj.FrameOffset = TFI.getFrameIndexReferenceFromSP(
+              Fn, H.CatchObj.FrameIndex, FrameReg);
       }
     }
   }

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=249578&r1=249577&r2=249578&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/win-catchpad.ll (original)
+++ llvm/trunk/test/CodeGen/X86/win-catchpad.ll Wed Oct  7 12:49:32 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   -20
+; X86-NEXT:   .long   24
 ; X86-NEXT:   .long   "?catch$[[catch1bb]]@?0?try_catch_catch at 4HA"
 ; X86-NEXT:   .long   64
 ; X86-NEXT:   .long   0
@@ -156,7 +156,7 @@ catchendblock:
 ; X64: .seh_endprologue
 ; X64-DAG: .Ltmp4
 ; X64-DAG: leaq -[[local_offs]](%rbp), %rdx
-; X64-DAG: movl [[e_addr:[-0-9]+]](%rbp), %ecx
+; X64-DAG: movl -4(%rbp), %ecx
 ; X64: callq f
 ; X64: leaq [[contbb]](%rip), %rax
 ; X64-NEXT: addq $32, %rsp
@@ -204,7 +204,7 @@ catchendblock:
 ; X64-NEXT:   .long   0
 ; X64-NEXT:   .long   "??_R0H at 8"@IMGREL
 ; FIXME: This should probably be offset from rsp, not rbp.
-; X64-NEXT:   .long   [[e_addr]]
+; X64-NEXT:   .long   44
 ; X64-NEXT:   .long   "?catch$[[catch1bb]]@?0?try_catch_catch at 4HA"@IMGREL
 ; X64-NEXT:   .long   56
 ; X64-NEXT:   .long   64
@@ -216,9 +216,9 @@ catchendblock:
 ; X64: $ip2state$try_catch_catch:
 ; X64-NEXT: .long   .Lfunc_begin0 at IMGREL
 ; X64-NEXT: .long   -1
-; X64-NEXT: .long   .Ltmp0 at IMGREL
+; X64-NEXT: .long   .Ltmp0 at IMGREL+1
 ; X64-NEXT: .long   0
-; X64-NEXT: .long   .Ltmp4 at IMGREL
+; X64-NEXT: .long   .Ltmp4 at IMGREL+1
 ; X64-NEXT: .long   1
 ; X64-NEXT: .long   .Ltmp3 at IMGREL+1
 ; X64-NEXT: .long   -1
@@ -353,7 +353,7 @@ catchendblock:
 ; X64-LABEL: $ip2state$branch_to_normal_dest:
 ; X64-NEXT: .long   .Lfunc_begin1 at IMGREL
 ; X64-NEXT: .long   -1
-; X64-NEXT: .long   .Ltmp[[before_call]]@IMGREL
+; X64-NEXT: .long   .Ltmp[[before_call]]@IMGREL+1
 ; X64-NEXT: .long   0
 ; X64-NEXT: .long   .Ltmp[[after_call]]@IMGREL+1
 ; X64-NEXT: .long   -1




More information about the llvm-commits mailing list