[PATCH] D156226: [DebugInfo] Fix crash when printing malformed DBG machine instructions

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 27 09:34:54 PDT 2023


foad updated this revision to Diff 544821.
foad added a comment.

Use >=.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156226/new/

https://reviews.llvm.org/D156226

Files:
  llvm/lib/CodeGen/MachineInstr.cpp
  llvm/test/CodeGen/MIR/Generic/dbg-value.mir


Index: llvm/test/CodeGen/MIR/Generic/dbg-value.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/MIR/Generic/dbg-value.mir
@@ -0,0 +1,14 @@
+# RUN: llc -run-pass=machineinstr-printer -o - %s | FileCheck %s
+
+---
+name: test
+body: |
+  bb.0:
+    ; CHECK-LABEL: name: test
+    ; CHECK: DBG_VALUE
+    ; CHECK-NEXT: DBG_VALUE_LIST
+    ; CHECK-NEXT: DBG_INSTR_REF
+    DBG_VALUE
+    DBG_VALUE_LIST
+    DBG_INSTR_REF
+...
Index: llvm/lib/CodeGen/MachineInstr.cpp
===================================================================
--- llvm/lib/CodeGen/MachineInstr.cpp
+++ llvm/lib/CodeGen/MachineInstr.cpp
@@ -1883,16 +1883,20 @@
     DL.print(OS);
   }
 
-  // Print extra comments for DEBUG_VALUE.
-  if (isDebugValueLike() && getDebugVariableOp().isMetadata()) {
-    if (!HaveSemi) {
-      OS << ";";
-      HaveSemi = true;
+  // Print extra comments for DEBUG_VALUE and friends if they are well-formed.
+  if ((isNonListDebugValue() && getNumOperands() >= 4) ||
+      (isDebugValueList() && getNumOperands() >= 2) ||
+      (isDebugRef() && getNumOperands() >= 3)) {
+    if (getDebugVariableOp().isMetadata()) {
+      if (!HaveSemi) {
+        OS << ";";
+        HaveSemi = true;
+      }
+      auto *DV = getDebugVariable();
+      OS << " line no:" << DV->getLine();
+      if (isIndirectDebugValue())
+        OS << " indirect";
     }
-    auto *DV = getDebugVariable();
-    OS << " line no:" <<  DV->getLine();
-    if (isIndirectDebugValue())
-      OS << " indirect";
   }
   // TODO: DBG_LABEL
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156226.544821.patch
Type: text/x-patch
Size: 1578 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230727/e7ffd211/attachment.bin>


More information about the llvm-commits mailing list