From 2110815361e55cc3fa273b4f006f4f2b0d4722da Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Sun, 26 Jul 2020 17:21:58 -0400 Subject: [PATCH 1/2] CodeGen: Don't assert when printing null GlobalAddress operands --- llvm/lib/CodeGen/MachineOperand.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp index d9e5e9d9d1e41..7be4563c8b11c 100644 --- a/llvm/lib/CodeGen/MachineOperand.cpp +++ b/llvm/lib/CodeGen/MachineOperand.cpp @@ -909,7 +909,11 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST, OS << printJumpTableEntryReference(getIndex()); break; case MachineOperand::MO_GlobalAddress: - getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST); + if (const auto *GV = getGlobal()) + getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST); + else + OS << "globaladdress(null)"; + printOperandOffset(OS, getOffset()); break; case MachineOperand::MO_ExternalSymbol: { From c6b7619a2a5773b5cd18133db96265843645d637 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 3 Dec 2024 19:15:21 -0500 Subject: [PATCH 2/2] Add comment --- llvm/lib/CodeGen/MachineOperand.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp index 7be4563c8b11c..18027b2db2947 100644 --- a/llvm/lib/CodeGen/MachineOperand.cpp +++ b/llvm/lib/CodeGen/MachineOperand.cpp @@ -911,7 +911,7 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST, case MachineOperand::MO_GlobalAddress: if (const auto *GV = getGlobal()) getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST); - else + else // Invalid, but may appear in debugging scenarios. OS << "globaladdress(null)"; printOperandOffset(OS, getOffset());