From 8eb3c8145793446acd1ba01530b64a03242d0e91 Mon Sep 17 00:00:00 2001 From: Wolfgang Pieb Date: Wed, 31 Oct 2018 21:05:51 +0000 Subject: [PATCH] [DWARF][NFC] Refactor a function to return Optional<> instead of bool Minor refactor of DWARFUnit::getStringOffsetSectionItem(). Differential Revision: https://reviews.llvm.org/D53948 llvm-svn: 345776 --- llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h | 2 +- llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp | 8 +++++--- llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp | 10 ++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h index c3252157b0bd..458278e4282f 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -304,7 +304,7 @@ public: } Optional getAddrOffsetSectionItem(uint32_t Index) const; - bool getStringOffsetSectionItem(uint32_t Index, uint64_t &Result) const; + Optional getStringOffsetSectionItem(uint32_t Index) const; DWARFDataExtractor getDebugInfoExtractor() const; diff --git a/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp b/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp index ed510a0e4cd1..9226dcad39a9 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -542,10 +542,12 @@ Optional DWARFFormValue::getAsCString() const { 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 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. diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp index d475c44c3935..1caaa249bef9 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -217,18 +217,16 @@ DWARFUnit::getAddrOffsetSectionItem(uint32_t Index) const { return {{Address, Section}}; } -bool DWARFUnit::getStringOffsetSectionItem(uint32_t Index, - uint64_t &Result) const { +Optional 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,