[llvm] Cope with MCOperand null Insts (PR #91794)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 12 06:46:02 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mc
Author: Nathan Sidwell (urnathan)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/91794.diff
1 Files Affected:
- (modified) llvm/lib/MC/MCInst.cpp (+4-1)
``````````diff
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";
``````````
</details>
https://github.com/llvm/llvm-project/pull/91794
More information about the llvm-commits
mailing list