[llvm] CodeGen: Don't assert when printing null GlobalAddress operands (PR #115531)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 10:32:42 PST 2024


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/115531

None

>From 2110815361e55cc3fa273b4f006f4f2b0d4722da Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sun, 26 Jul 2020 17:21:58 -0400
Subject: [PATCH] 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 d9e5e9d9d1e41f..7be4563c8b11c9 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: {



More information about the llvm-commits mailing list