diff options
author | Jay Foad <jay.foad@amd.com> | 2023-07-25 11:43:38 +0100 |
---|---|---|
committer | Jay Foad <jay.foad@amd.com> | 2023-08-02 08:28:20 +0100 |
commit | 8f973d5c455cecfbee7766e23c3fcc3eb1048f1e (patch) | |
tree | 71c51c70b19a3ad0224f4044a9aa107e8a638311 /llvm/lib/CodeGen/MachineInstr.cpp | |
parent | 620e2bb20cb7f9e59a7c30eab0737e34eb26ed2d (diff) | |
download | llvm-8f973d5c455cecfbee7766e23c3fcc3eb1048f1e.zip llvm-8f973d5c455cecfbee7766e23c3fcc3eb1048f1e.tar.gz llvm-8f973d5c455cecfbee7766e23c3fcc3eb1048f1e.tar.bz2 |
[DebugInfo] Fix crash when printing malformed DBG machine instructions
MachineVerifier does not check that DBG_VALUE, DBG_VALUE_LIST and
DBG_INSTR_REF have the expected number of operands, so printing them
(e.g. with -print-after-all) should not crash.
Differential Revision: https://reviews.llvm.org/D156226
Diffstat (limited to 'llvm/lib/CodeGen/MachineInstr.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineInstr.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index a930948..0c4353f 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -1883,16 +1883,20 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, 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 |