[PATCH] D53333: [SystemZ] Make sure that SystemZAddressingMode::dump() does not crash.

Jonas Paulsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 16 10:08:08 PDT 2018


jonpa created this revision.
jonpa added reviewers: uweigand, thegameg.

I tried to compile a file with '-mllvm -debug', which caused a crash. This time this was during isel, where the common code did not properly handle a \
call to printIRSlotNumber without a Function pointer set. This occurred because SystemZAddressingMode::dump() was calling SDNode::dump() without passi\
ng the DAG pointer.

This patch:

1. It seems reasonable that the common code does not crash, and this patch at least prints a question mark instead of calling printIRSlotNumber() when  the Function pointer is not set.
2. Since the DAG is available, SystemZAddressingMode::dump() should pass it.

My problem would disappear even without (1) since (2) avoids it. This also means there is no test case for (1). Adding reviewer for (1) also.


https://reviews.llvm.org/D53333

Files:
  lib/CodeGen/MachineOperand.cpp
  lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
  test/CodeGen/SystemZ/isel-debug.ll


Index: test/CodeGen/SystemZ/isel-debug.ll
===================================================================
--- /dev/null
+++ test/CodeGen/SystemZ/isel-debug.ll
@@ -0,0 +1,19 @@
+; RUN: llc < %s -mtriple=s390x-linux-gnu -debug-only=systemz-isel -o - 2>&1 | \
+; RUN:   FileCheck %s
+
+; REQUIRES: asserts
+;
+; Check that some debug output is printed without problems.
+; CHECK: SystemZAddressingMode
+; CHECK: Base
+; CHECK: Index
+; CHECK: Disp
+
+define void @fun(i64* %ptr) {
+entry:
+  %0 = bitcast i64* %ptr to i32**
+  %1 = load i32*, i32** %0, align 8
+  %xpv_pv = getelementptr inbounds i32, i32* %1
+  store i32 0, i32* %xpv_pv
+  ret void
+}
Index: lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
===================================================================
--- lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
+++ lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
@@ -71,19 +71,19 @@
   // True if the address can (and must) include ADJDYNALLOC.
   bool isDynAlloc() { return Form == FormBDXDynAlloc; }
 
-  void dump() {
+  void dump(const llvm::SelectionDAG *DAG) {
     errs() << "SystemZAddressingMode " << this << '\n';
 
     errs() << " Base ";
     if (Base.getNode())
-      Base.getNode()->dump();
+      Base.getNode()->dump(DAG);
     else
       errs() << "null\n";
 
     if (hasIndexField()) {
       errs() << " Index ";
       if (Index.getNode())
-        Index.getNode()->dump();
+        Index.getNode()->dump(DAG);
       else
         errs() << "null\n";
     }
@@ -589,7 +589,7 @@
   if (AM.isDynAlloc() && !AM.IncludesDynAlloc)
     return false;
 
-  LLVM_DEBUG(AM.dump());
+  LLVM_DEBUG(AM.dump(CurDAG));
   return true;
 }
 
Index: lib/CodeGen/MachineOperand.cpp
===================================================================
--- lib/CodeGen/MachineOperand.cpp
+++ lib/CodeGen/MachineOperand.cpp
@@ -461,7 +461,10 @@
     printLLVMNameWithoutPrefix(OS, V.getName());
     return;
   }
-  MachineOperand::printIRSlotNumber(OS, MST.getLocalSlot(&V));
+  if (MST.getCurrentFunction())
+    MachineOperand::printIRSlotNumber(OS, MST.getLocalSlot(&V));
+  else
+    OS << "?";
 }
 
 static void printSyncScope(raw_ostream &OS, const LLVMContext &Context,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53333.169847.patch
Type: text/x-patch
Size: 2185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181016/7f69ff6c/attachment.bin>


More information about the llvm-commits mailing list