[llvm] r257182 - [WinEH] CatchHandler which don't have catch objects in StackColoring

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 8 09:24:50 PST 2016


Author: majnemer
Date: Fri Jan  8 11:24:47 2016
New Revision: 257182

URL: http://llvm.org/viewvc/llvm-project?rev=257182&view=rev
Log:
[WinEH] CatchHandler which don't have catch objects in StackColoring

StackColoring rewrites the frame indicies of operations involving
allocas if it can find that the life time of two objects do not overlap.
MSVC EH needs to be kept aware of this if happens in the event that a
catch object has moved around.  However, we represent the non-existance
of a catch object with a sentinel frame index (INT_MAX).  This sentinel
also happens to be the EmptyKey of the SlotRemap DenseMap.  Testing for
whether or not we need to translate the frame index fails in this case
because we call the count method on the DenseMap with the EmptyKey,
leading to assertions.  Instead, check if it is our sentinel value
before trying to look into the DenseMap.

This fixes PR26073.

Modified:
    llvm/trunk/lib/CodeGen/StackColoring.cpp
    llvm/trunk/test/CodeGen/X86/catchpad-lifetime.ll

Modified: llvm/trunk/lib/CodeGen/StackColoring.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StackColoring.cpp?rev=257182&r1=257181&r2=257182&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/StackColoring.cpp (original)
+++ llvm/trunk/lib/CodeGen/StackColoring.cpp Fri Jan  8 11:24:47 2016
@@ -571,10 +571,12 @@ void StackColoring::remapInstructions(De
       }
     }
 
+  // Update the location of C++ catch objects for the MSVC personality routine.
   if (WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo())
     for (WinEHTryBlockMapEntry &TBME : EHInfo->TryBlockMap)
       for (WinEHHandlerType &H : TBME.HandlerArray)
-        if (SlotRemap.count(H.CatchObj.FrameIndex))
+        if (H.CatchObj.FrameIndex != INT_MAX &&
+            SlotRemap.count(H.CatchObj.FrameIndex))
           H.CatchObj.FrameIndex = SlotRemap[H.CatchObj.FrameIndex];
 
   DEBUG(dbgs()<<"Fixed "<<FixedMemOp<<" machine memory operands.\n");

Modified: llvm/trunk/test/CodeGen/X86/catchpad-lifetime.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/catchpad-lifetime.ll?rev=257182&r1=257181&r2=257182&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/catchpad-lifetime.ll (original)
+++ llvm/trunk/test/CodeGen/X86/catchpad-lifetime.ll Fri Jan  8 11:24:47 2016
@@ -44,6 +44,44 @@ unreachable:
 ; CHECK-LABEL: $cppxdata$test1:
 ; CHECK: .long   32                      # CatchObjOffset
 
+define void @test2() personality i32 (...)* @__CxxFrameHandler3 {
+entry:
+  %alloca2 = alloca i8*, align 4
+  %alloca1 = alloca i8*, align 4
+  store volatile i8* null, i8** %alloca1
+  invoke void @throw()
+          to label %unreachable unwind label %catch.dispatch
+
+; CHECK-LABEL: test2:
+; CHECK: movq  $0, -16(%rbp)
+; CHECK: callq throw
+
+catch.dispatch:                                   ; preds = %entry
+  %cs = catchswitch within none [label %catch.pad] unwind to caller
+
+catch.pad:                                        ; preds = %catch.dispatch
+  %cp = catchpad within %cs [i8* null, i32 0, i8** null]
+  store volatile i8* null, i8** %alloca1
+  %bc1 = bitcast i8** %alloca1 to i8*
+  call void @llvm.lifetime.end(i64 4, i8* nonnull %bc1)
+  %bc2 = bitcast i8** %alloca2 to i8*
+  call void @llvm.lifetime.start(i64 4, i8* %bc2)
+  store volatile i8* null, i8** %alloca1
+  unreachable
+
+; CHECK-LABEL: "?catch$2@?0?test2 at 4HA"
+; CHECK: movq  $0, -16(%rbp)
+; CHECK: movq  $0, -16(%rbp)
+; CHECK: ud2
+
+unreachable:                                      ; preds = %entry
+  unreachable
+}
+
+; CHECK-LABEL: $cppxdata$test2:
+; CHECK: .long   0                       # CatchObjOffset
+
+
 ; Function Attrs: argmemonly nounwind
 declare void @llvm.lifetime.start(i64, i8* nocapture) #0
 




More information about the llvm-commits mailing list