[llvm] r345776 - [DWARF][NFC] Refactor a function to return Optional<> instead of bool
Wolfgang Pieb via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 31 14:05:51 PDT 2018
Author: wolfgangp
Date: Wed Oct 31 14:05:51 2018
New Revision: 345776
URL: http://llvm.org/viewvc/llvm-project?rev=345776&view=rev
Log:
[DWARF][NFC] Refactor a function to return Optional<> instead of bool
Minor refactor of DWARFUnit::getStringOffsetSectionItem().
Differential Revision: https://reviews.llvm.org/D53948
Modified:
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h?rev=345776&r1=345775&r2=345776&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h Wed Oct 31 14:05:51 2018
@@ -304,7 +304,7 @@ public:
}
Optional<SectionedAddress> getAddrOffsetSectionItem(uint32_t Index) const;
- bool getStringOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
+ Optional<uint64_t> getStringOffsetSectionItem(uint32_t Index) const;
DWARFDataExtractor getDebugInfoExtractor() const;
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp?rev=345776&r1=345775&r2=345776&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp Wed Oct 31 14:05:51 2018
@@ -542,10 +542,12 @@ Optional<const char *> DWARFFormValue::g
if (Form == DW_FORM_GNU_str_index || Form == DW_FORM_strx ||
Form == DW_FORM_strx1 || Form == DW_FORM_strx2 || Form == DW_FORM_strx3 ||
Form == DW_FORM_strx4) {
- uint64_t StrOffset;
- if (!U || !U->getStringOffsetSectionItem(Offset, StrOffset))
+ if (!U)
return None;
- Offset = StrOffset;
+ Optional<uint64_t> StrOffset = U->getStringOffsetSectionItem(Offset);
+ if (!StrOffset)
+ return None;
+ Offset = *StrOffset;
}
// Prefer the Unit's string extractor, because for .dwo it will point to
// .debug_str.dwo, while the Context's extractor always uses .debug_str.
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp?rev=345776&r1=345775&r2=345776&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp Wed Oct 31 14:05:51 2018
@@ -217,18 +217,16 @@ DWARFUnit::getAddrOffsetSectionItem(uint
return {{Address, Section}};
}
-bool DWARFUnit::getStringOffsetSectionItem(uint32_t Index,
- uint64_t &Result) const {
+Optional<uint64_t> DWARFUnit::getStringOffsetSectionItem(uint32_t Index) const {
if (!StringOffsetsTableContribution)
- return false;
+ return None;
unsigned ItemSize = getDwarfStringOffsetsByteSize();
uint32_t Offset = getStringOffsetsBase() + Index * ItemSize;
if (StringOffsetSection.Data.size() < Offset + ItemSize)
- return false;
+ return None;
DWARFDataExtractor DA(Context.getDWARFObj(), StringOffsetSection,
isLittleEndian, 0);
- Result = DA.getRelocatedValue(ItemSize, &Offset);
- return true;
+ return DA.getRelocatedValue(ItemSize, &Offset);
}
bool DWARFUnitHeader::extract(DWARFContext &Context,
More information about the llvm-commits
mailing list