diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/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 diff --git a/llvm/test/CodeGen/MIR/Generic/dbg-value.mir b/llvm/test/CodeGen/MIR/Generic/dbg-value.mir new file mode 100644 --- /dev/null +++ b/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 +...