diff options
author | Greg Clayton <gclayton@apple.com> | 2016-12-14 22:38:08 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2016-12-14 22:38:08 +0000 |
commit | 52fe1f68c8f405dc5799a640ff275c6afd74ebb1 (patch) | |
tree | 2cd938401d902651f7ab6469db90baab2d9cf81d /llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | |
parent | e7bbf7fde3f6513ef0311eda82b6f8f37b644fa9 (diff) | |
download | bcm5719-llvm-52fe1f68c8f405dc5799a640ff275c6afd74ebb1.tar.gz bcm5719-llvm-52fe1f68c8f405dc5799a640ff275c6afd74ebb1.zip |
Add the ability to get attribute values as Optional<T>
When getting attributes it is sometimes nicer to use Optional<T> some of the time instead of magic values. I tried to cut over to only using the Optional values but it made many of the call sites very messy, so it makes sense the leave in the calls that can return a default value. Otherwise code that looks like this:
uint64_t CallColumn = Die.getAttributeValueAsAddress(DW_AT_call_line, 0);
Has to be turned into:
uint64_t CallColumn = 0;
if (auto CallColumnValue = Die.getAttributeValueAsAddress(DW_AT_call_line))
CallColumn = *CallColumnValue;
The first snippet of code looks much better. But in cases where you want an offset that may or may not be there, the following code looks better:
if (auto StmtOffset = Die.getAttributeValueAsSectionOffset(DW_AT_stmt_list)) {
// Use StmtOffset
}
Differential Revision: https://reviews.llvm.org/D27772
llvm-svn: 289731
Diffstat (limited to 'llvm/lib/DebugInfo/DWARF/DWARFContext.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp index 5982fbbab24..0f2a48bd509 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -159,13 +159,13 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType, bool DumpEH, auto CUDIE = CU->getUnitDIE(); if (!CUDIE) continue; - unsigned stmtOffset = CUDIE.getAttributeValueAsSectionOffset( - DW_AT_stmt_list, -1U); - if (stmtOffset != -1U) { + if (auto StmtOffset = + CUDIE.getAttributeValueAsSectionOffset(DW_AT_stmt_list)) { DataExtractor lineData(getLineSection().Data, isLittleEndian(), savedAddressByteSize); DWARFDebugLine::LineTable LineTable; - LineTable.parse(lineData, &getLineSection().Relocs, &stmtOffset); + uint32_t Offset = *StmtOffset; + LineTable.parse(lineData, &getLineSection().Relocs, &Offset); LineTable.dump(OS); } } @@ -416,12 +416,11 @@ DWARFContext::getLineTableForUnit(DWARFUnit *U) { if (!UnitDIE) return nullptr; - unsigned stmtOffset = - UnitDIE.getAttributeValueAsSectionOffset(DW_AT_stmt_list, -1U); - if (stmtOffset == -1U) + auto Offset = UnitDIE.getAttributeValueAsSectionOffset(DW_AT_stmt_list); + if (!Offset) return nullptr; // No line table for this compile unit. - stmtOffset += U->getLineTableOffset(); + uint32_t stmtOffset = *Offset + U->getLineTableOffset(); // See if the line table is cached. if (const DWARFLineTable *lt = Line->getLineTable(stmtOffset)) return lt; |