[llvm] [llvm-dwarfdump] Add a null-check in `prettyPrintBaseTypeRef`. (PR #93156)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 02:04:37 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-debuginfo
Author: None (mgschossmann)
<details>
<summary>Changes</summary>
Fixes #<!-- -->93104
Prevent a crash by only printing DWARFUnit-unaware information in cases in which `DWARFUnit* U` is `nullptr`.
---
Full diff: https://github.com/llvm/llvm-project/pull/93156.diff
1 Files Affected:
- (modified) llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp (+14-10)
``````````diff
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
index 87a4fc78ceb19..0c28701360b3c 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -240,17 +240,21 @@ static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
ArrayRef<uint64_t> Operands,
unsigned Operand) {
assert(Operand < Operands.size() && "operand out of bounds");
- auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]);
- if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
- OS << " (";
- if (DumpOpts.Verbose)
- OS << format("0x%08" PRIx64 " -> ", Operands[Operand]);
- OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]);
- if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name)))
- OS << " \"" << *Name << "\"";
+ if (U) {
+ auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]);
+ if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
+ OS << " (";
+ if (DumpOpts.Verbose)
+ OS << format("0x%08" PRIx64 " -> ", Operands[Operand]);
+ OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]);
+ if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name)))
+ OS << " \"" << *Name << "\"";
+ } else {
+ OS << format(" <invalid base_type ref: 0x%" PRIx64 ">",
+ Operands[Operand]);
+ }
} else {
- OS << format(" <invalid base_type ref: 0x%" PRIx64 ">",
- Operands[Operand]);
+ OS << format(" <base_type ref: 0x%" PRIx64 ">", Operands[Operand]);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/93156
More information about the llvm-commits
mailing list