[PATCH] D70493: [StackMaps] Avoid crash when a call follows a patchpoint

James Molloy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 07:18:30 PST 2019


jmolloy created this revision.
Herald added subscribers: hiraditya, aprantl.
Herald added a project: LLVM.

A call after a patchpoint will cause the patchpoint to implicitly have SSP as liveout. SSP doesn't have a DWARF regnum or a register class, so we blow up in getDwarfRegNum().

Guard this by only trying to emit stackmap information for allocatable registers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70493

Files:
  llvm/lib/CodeGen/StackMaps.cpp
  llvm/test/CodeGen/X86/stackmap-shadow-optimization.ll


Index: llvm/test/CodeGen/X86/stackmap-shadow-optimization.ll
===================================================================
--- llvm/test/CodeGen/X86/stackmap-shadow-optimization.ll
+++ llvm/test/CodeGen/X86/stackmap-shadow-optimization.ll
@@ -24,5 +24,17 @@
   ret void
 }
 
+; Check no crash.
+; CHECK-LABEL: shadow_optimization_test2:
+define void @shadow_optimization_test2() {
+entry:
+  call void @bar()
+  tail call void (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.void(i64 0, i32 8, i8* null, i32 0)
+  call void @bar()
+  call void @bar()
+  ret void
+}
+
 declare void @llvm.experimental.stackmap(i64, i32, ...)
+declare void @llvm.experimental.patchpoint.void(i64, i32, i8*, i32, ...)
 declare void @bar()
Index: llvm/lib/CodeGen/StackMaps.cpp
===================================================================
--- llvm/lib/CodeGen/StackMaps.cpp
+++ llvm/lib/CodeGen/StackMaps.cpp
@@ -261,7 +261,8 @@
   // Create a LiveOutReg for each bit that is set in the register mask.
   for (unsigned Reg = 0, NumRegs = TRI->getNumRegs(); Reg != NumRegs; ++Reg)
     if ((Mask[Reg / 32] >> (Reg % 32)) & 1)
-      LiveOuts.push_back(createLiveOutReg(Reg, TRI));
+      if (TRI->isInAllocatableClass(Reg))
+        LiveOuts.push_back(createLiveOutReg(Reg, TRI));
 
   // We don't need to keep track of a register if its super-register is already
   // in the list. Merge entries that refer to the same dwarf register and use


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70493.230259.patch
Type: text/x-patch
Size: 1443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191120/dc034480/attachment-0001.bin>


More information about the llvm-commits mailing list