aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineInstr.cpp
diff options
context:
space:
mode:
authorJay Foad <jay.foad@amd.com>2023-07-25 11:43:38 +0100
committerJay Foad <jay.foad@amd.com>2023-08-02 08:28:20 +0100
commit8f973d5c455cecfbee7766e23c3fcc3eb1048f1e (patch)
tree71c51c70b19a3ad0224f4044a9aa107e8a638311 /llvm/lib/CodeGen/MachineInstr.cpp
parent620e2bb20cb7f9e59a7c30eab0737e34eb26ed2d (diff)
downloadllvm-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.cpp22
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