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

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 16:15:59 PST 2024


Author: Matt Arsenault
Date: 2024-12-03T19:15:56-05:00
New Revision: e9dc6c5fbb6d2c2c93095acb6ff4ca0b515057ed

URL: https://github.com/llvm/llvm-project/commit/e9dc6c5fbb6d2c2c93095acb6ff4ca0b515057ed
DIFF: https://github.com/llvm/llvm-project/commit/e9dc6c5fbb6d2c2c93095acb6ff4ca0b515057ed.diff

LOG: CodeGen: Don't assert when printing null GlobalAddress operands (#115531)

Added: 
    

Modified: 
    llvm/lib/CodeGen/MachineOperand.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp
index d9e5e9d9d1e41f..18027b2db2947c 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 // Invalid, but may appear in debugging scenarios.
+      OS << "globaladdress(null)";
+
     printOperandOffset(OS, getOffset());
     break;
   case MachineOperand::MO_ExternalSymbol: {


        


More information about the llvm-commits mailing list