Switch functions that returned bool and filled in a DWARFFormValue arg with ones that return Optional<DWARFFormValue>

Differential Revision: https://reviews.llvm.org/D27737

llvm-svn: 289611
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
index 638830e..6126470 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -143,12 +143,12 @@
   return None;
 }
 
-bool DWARFAbbreviationDeclaration::getAttributeValue(
-    const uint32_t DIEOffset, const dwarf::Attribute Attr, const DWARFUnit &U,
-    DWARFFormValue &FormValue) const {
+Optional<DWARFFormValue> DWARFAbbreviationDeclaration::getAttributeValue(
+    const uint32_t DIEOffset, const dwarf::Attribute Attr,
+    const DWARFUnit &U) const {
   Optional<uint32_t> MatchAttrIndex = findAttributeIndex(Attr);
   if (!MatchAttrIndex)
-    return false;
+    return None;
 
   auto DebugInfoData = U.getDebugInfoExtractor();
 
@@ -159,8 +159,9 @@
   for (const auto &Spec : AttributeSpecs) {
     if (*MatchAttrIndex == AttrIndex) {
       // We have arrived at the attribute to extract, extract if from Offset.
-      FormValue.setForm(Spec.Form);
-      return FormValue.extractValue(DebugInfoData, &Offset, &U);
+      DWARFFormValue FormValue(Spec.Form);
+      if (FormValue.extractValue(DebugInfoData, &Offset, &U))
+        return FormValue;
     }
     // March Offset along until we get to the attribute we want.
     if (Optional<uint8_t> FixedSize = Spec.getByteSize(U))
@@ -169,7 +170,7 @@
       DWARFFormValue::skipValue(Spec.Form, DebugInfoData, &Offset, &U);
     ++AttrIndex;
   }
-  return false;
+  return None;
 }
 
 size_t DWARFAbbreviationDeclaration::FixedSizeInfo::getByteSize(
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index a41fe6f..f52cc11 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -133,68 +133,68 @@
   return Tag == DW_TAG_subprogram || Tag == DW_TAG_inlined_subroutine;
 }
 
-bool DWARFDie::getAttributeValue(dwarf::Attribute Attr,
-                                 DWARFFormValue &FormValue) const {
-  if (!U)
-    return false;
+Optional<DWARFFormValue>
+DWARFDie::getAttributeValue(dwarf::Attribute Attr) const {
+  if (!isValid())
+    return None;
   auto AbbrevDecl = getAbbreviationDeclarationPtr();
   if (AbbrevDecl)
-    return AbbrevDecl->getAttributeValue(getOffset(), Attr, *U, FormValue);
-  return false;
+    return AbbrevDecl->getAttributeValue(getOffset(), Attr, *U);
+  return None;
 }
 
 const char *DWARFDie::getAttributeValueAsString(dwarf::Attribute Attr,
                                                 const char *FailValue) const {
-  DWARFFormValue FormValue;
-  if (!getAttributeValue(Attr, FormValue))
+  auto FormValue = getAttributeValue(Attr);
+  if (!FormValue)
     return FailValue;
-  Optional<const char *> Result = FormValue.getAsCString();
+  Optional<const char *> Result = FormValue->getAsCString();
   return Result.hasValue() ? Result.getValue() : FailValue;
 }
 
 uint64_t DWARFDie::getAttributeValueAsAddress(dwarf::Attribute Attr,
                                               uint64_t FailValue) const {
-  DWARFFormValue FormValue;
-  if (!getAttributeValue(Attr, FormValue))
+  auto FormValue = getAttributeValue(Attr);
+  if (!FormValue)
     return FailValue;
-  Optional<uint64_t> Result = FormValue.getAsAddress();
+  Optional<uint64_t> Result = FormValue->getAsAddress();
   return Result.hasValue() ? Result.getValue() : FailValue;
 }
 
 int64_t DWARFDie::getAttributeValueAsSignedConstant(dwarf::Attribute Attr,
                                                     int64_t FailValue) const {
-  DWARFFormValue FormValue;
-  if (!getAttributeValue(Attr, FormValue))
+  auto FormValue = getAttributeValue(Attr);
+  if (!FormValue)
     return FailValue;
-  Optional<int64_t> Result = FormValue.getAsSignedConstant();
+  Optional<int64_t> Result = FormValue->getAsSignedConstant();
   return Result.hasValue() ? Result.getValue() : FailValue;
 }
 
 uint64_t
 DWARFDie::getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr,
                                               uint64_t FailValue) const {
-  DWARFFormValue FormValue;
-  if (!getAttributeValue(Attr, FormValue))
+  auto FormValue = getAttributeValue(Attr);
+  if (!FormValue)
     return FailValue;
-  Optional<uint64_t> Result = FormValue.getAsUnsignedConstant();
+  Optional<uint64_t> Result = FormValue->getAsUnsignedConstant();
   return Result.hasValue() ? Result.getValue() : FailValue;
 }
 
 uint64_t DWARFDie::getAttributeValueAsReference(dwarf::Attribute Attr,
                                                 uint64_t FailValue) const {
-  DWARFFormValue FormValue;
-  if (!getAttributeValue(Attr, FormValue))
+  auto FormValue = getAttributeValue(Attr);
+  if (!FormValue)
     return FailValue;
-  Optional<uint64_t> Result = FormValue.getAsReference();
+  Optional<uint64_t> Result = FormValue->getAsReference();
   return Result.hasValue() ? Result.getValue() : FailValue;
 }
 
 uint64_t DWARFDie::getAttributeValueAsSectionOffset(dwarf::Attribute Attr,
                                                     uint64_t FailValue) const {
-  DWARFFormValue FormValue;
-  if (!getAttributeValue(Attr, FormValue))
+  auto FormValue = getAttributeValue(Attr);
+  if (!FormValue)
     return FailValue;
-  Optional<uint64_t> Result = FormValue.getAsSectionOffset();
+  Optional<uint64_t> Result = FormValue->getAsSectionOffset();
   return Result.hasValue() ? Result.getValue() : FailValue;
 }
 
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp
index dacd644..88fb203 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp
@@ -26,11 +26,7 @@
 
 void DWARFTypeUnit::dump(raw_ostream &OS, bool SummarizeTypes) {
   DWARFDie TD = getDIEForOffset(TypeOffset + getOffset());
-  DWARFFormValue NameVal;
-  const char *Name = "";
-  if (TD.getAttributeValue(llvm::dwarf::DW_AT_name, NameVal))
-    if (auto ON = NameVal.getAsCString())
-      Name = *ON;
+  const char *Name = TD.getAttributeValueAsString(llvm::dwarf::DW_AT_name, "");
 
   if (SummarizeTypes) {
     OS << "name = '" << Name << "'"