[llvm] Cope with MCOperand null Insts (PR #91794)
Nathan Sidwell via llvm-commits
llvm-commits at lists.llvm.org
Fri May 10 11:52:36 PDT 2024
https://github.com/urnathan created https://github.com/llvm/llvm-project/pull/91794
I encountered a bolt segfault due to an MCOperand of type Inst with a null pointer. It seems bolt is intentionally creating such operands, so it would be good for the printer to not barf on them.
The bolt code is bolt/include/bolt/Core/MCPlusBuilder.h where the annotation machinery is. For example line 131 in setAnnotationOpValue:
` Inst.addOperand(MCOperand::createInst(nullptr));`
In my case it was annotating an X86 JCC instruction, and using --debug crashed.
>From 8b5624e1014f56d3804dce8dbb9a3af0aaa0c96e Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan at acm.org>
Date: Fri, 10 May 2024 14:45:41 -0400
Subject: [PATCH] Cope with MCOperand null Insts
---
llvm/lib/MC/MCInst.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/MC/MCInst.cpp b/llvm/lib/MC/MCInst.cpp
index 3cc50ff43513e..639619fe4e991 100644
--- a/llvm/lib/MC/MCInst.cpp
+++ b/llvm/lib/MC/MCInst.cpp
@@ -38,7 +38,10 @@ void MCOperand::print(raw_ostream &OS, const MCRegisterInfo *RegInfo) const {
OS << "Expr:(" << *getExpr() << ")";
} else if (isInst()) {
OS << "Inst:(";
- getInst()->print(OS, RegInfo);
+ if (const auto *Inst = getInst())
+ Inst->print(OS, RegInfo);
+ else
+ OS << "NULL";
OS << ")";
} else
OS << "UNDEFINED";
More information about the llvm-commits
mailing list