[PATCH] D53948: [DWARF][NFC] Refactor a function to return Optional<> instead of bool

Wolfgang Pieb via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 31 14:08:12 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL345776: [DWARF][NFC] Refactor a function to return Optional<> instead of bool (authored by wolfgangp, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53948?vs=171987&id=172015#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53948

Files:
  llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
  llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
  llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp


Index: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
===================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
@@ -304,7 +304,7 @@
   }
 
   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;
 
Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
===================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
@@ -542,10 +542,12 @@
   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;
+    Optional<uint64_t> StrOffset = U->getStringOffsetSectionItem(Offset);
+    if (!StrOffset)
       return None;
-    Offset = StrOffset;
+    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.
Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
===================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -217,18 +217,16 @@
   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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53948.172015.patch
Type: text/x-patch
Size: 2506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181031/80d6f4eb/attachment.bin>


More information about the llvm-commits mailing list