Skip to content

Commit

Permalink
Remove all variants of DWARFDie::getAttributeValueAs...() that had pa…
Browse files Browse the repository at this point in the history
…rameters that specified default values.

Now we only support returning Optional<> values and have changed all clients over to use Optional::getValueOr().

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

llvm-svn: 291686
  • Loading branch information
Greg Clayton committed Jan 11, 2017
1 parent 778d081 commit d1efea8
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 210 deletions.
74 changes: 0 additions & 74 deletions llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,6 @@ class DWARFDie {
const char *getAttributeValueAsString(dwarf::Attribute Attr,
const char *FailValue) const;

/// Extract the specified attribute from this DIE as an address.
///
/// Extract an attribute value from this DIE only. This call doesn't look
/// for the attribute value in any DW_AT_specification or
/// DW_AT_abstract_origin referenced DIEs.
///
/// \param Attr the attribute to extract.
/// \param FailValue the value to return if this DIE doesn't have this
/// attribute.
/// \returns the address value of the attribute or FailValue if the
/// attribute doesn't exist or if the attribute's form isn't a form that
/// describes an address.
uint64_t getAttributeValueAsAddress(dwarf::Attribute Attr,
uint64_t FailValue) const;

/// Extract the specified attribute from this DIE as an address.
///
/// Extract an attribute value from this DIE only. This call doesn't look
Expand All @@ -165,21 +150,6 @@ class DWARFDie {
/// \returns an optional value for the attribute.
Optional<uint64_t> getAttributeValueAsAddress(dwarf::Attribute Attr) const;

/// Extract the specified attribute from this DIE as a signed integer.
///
/// Extract an attribute value from this DIE only. This call doesn't look
/// for the attribute value in any DW_AT_specification or
/// DW_AT_abstract_origin referenced DIEs.
///
/// \param Attr the attribute to extract.
/// \param FailValue the value to return if this DIE doesn't have this
/// attribute.
/// \returns the signed integer constant value of the attribute or FailValue
/// if the attribute doesn't exist or if the attribute's form isn't a form
/// that describes a signed integer.
int64_t getAttributeValueAsSignedConstant(dwarf::Attribute Attr,
int64_t FailValue) const;

/// Extract the specified attribute from this DIE as a signed integer.
///
/// Extract an attribute value from this DIE only. This call doesn't look
Expand All @@ -191,21 +161,6 @@ class DWARFDie {
Optional<int64_t>
getAttributeValueAsSignedConstant(dwarf::Attribute Attr) const;

/// Extract the specified attribute from this DIE as an unsigned integer.
///
/// Extract an attribute value from this DIE only. This call doesn't look
/// for the attribute value in any DW_AT_specification or
/// DW_AT_abstract_origin referenced DIEs.
///
/// \param Attr the attribute to extract.
/// \param FailValue the value to return if this DIE doesn't have this
/// attribute.
/// \returns the unsigned integer constant value of the attribute or FailValue
/// if the attribute doesn't exist or if the attribute's form isn't a form
/// that describes an unsigned integer.
uint64_t getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr,
uint64_t FailValue) const;

/// Extract the specified attribute from this DIE as an unsigned integer.
///
/// Extract an attribute value from this DIE only. This call doesn't look
Expand All @@ -217,21 +172,6 @@ class DWARFDie {
Optional<uint64_t>
getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr) const;

/// Extract the specified attribute from this DIE as absolute DIE Offset.
///
/// Extract an attribute value from this DIE only. This call doesn't look
/// for the attribute value in any DW_AT_specification or
/// DW_AT_abstract_origin referenced DIEs.
///
/// \param Attr the attribute to extract.
/// \param FailValue the value to return if this DIE doesn't have this
/// attribute.
/// \returns the unsigned integer constant value of the attribute or FailValue
/// if the attribute doesn't exist or if the attribute's form isn't a form
/// that describes a reference.
uint64_t getAttributeValueAsReference(dwarf::Attribute Attr,
uint64_t FailValue) const;

/// Extract the specified attribute from this DIE as absolute DIE Offset.
///
/// Extract an attribute value from this DIE only. This call doesn't look
Expand All @@ -242,20 +182,6 @@ class DWARFDie {
/// \returns an optional value for the attribute.
Optional<uint64_t> getAttributeValueAsReference(dwarf::Attribute Attr) const;

/// Extract the specified attribute from this DIE as absolute section offset.
///
/// Extract an attribute value from this DIE only. This call doesn't look
/// for the attribute value in any DW_AT_specification or
/// DW_AT_abstract_origin referenced DIEs.
///
/// \param Attr the attribute to extract.
/// \param FailValue the value to return if this DIE doesn't have this
/// attribute.
/// \returns the unsigned integer constant value of the attribute or FailValue
/// if the attribute doesn't exist or if the attribute's form isn't a form
/// that describes a section offset.
uint64_t getAttributeValueAsSectionOffset(dwarf::Attribute Attr,
uint64_t FailValue) const;
/// Extract the specified attribute from this DIE as absolute section offset.
///
/// Extract an attribute value from this DIE only. This call doesn't look
Expand Down
45 changes: 4 additions & 41 deletions llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,72 +152,34 @@ const char *DWARFDie::getAttributeValueAsString(dwarf::Attribute Attr,
return Result.hasValue() ? Result.getValue() : FailValue;
}

uint64_t DWARFDie::getAttributeValueAsAddress(dwarf::Attribute Attr,
uint64_t FailValue) const {
if (auto Value = getAttributeValueAsAddress(Attr))
return *Value;
return FailValue;
}

Optional<uint64_t>
DWARFDie::getAttributeValueAsAddress(dwarf::Attribute Attr) const {
if (auto FormValue = getAttributeValue(Attr))
return FormValue->getAsAddress();
return None;
}

int64_t DWARFDie::getAttributeValueAsSignedConstant(dwarf::Attribute Attr,
int64_t FailValue) const {
if (auto Value = getAttributeValueAsSignedConstant(Attr))
return *Value;
return FailValue;
}

Optional<int64_t>
DWARFDie::getAttributeValueAsSignedConstant(dwarf::Attribute Attr) const {
if (auto FormValue = getAttributeValue(Attr))
return FormValue->getAsSignedConstant();
return None;
}

uint64_t
DWARFDie::getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr,
uint64_t FailValue) const {
if (auto Value = getAttributeValueAsUnsignedConstant(Attr))
return *Value;
return FailValue;
}


Optional<uint64_t>
DWARFDie::getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr) const {
if (auto FormValue = getAttributeValue(Attr))
return FormValue->getAsUnsignedConstant();
return None;
}

uint64_t DWARFDie::getAttributeValueAsReference(dwarf::Attribute Attr,
uint64_t FailValue) const {
if (auto Value = getAttributeValueAsReference(Attr))
return *Value;
return FailValue;
}


Optional<uint64_t>
DWARFDie::getAttributeValueAsReference(dwarf::Attribute Attr) const {
if (auto FormValue = getAttributeValue(Attr))
return FormValue->getAsReference();
return None;
}

uint64_t DWARFDie::getAttributeValueAsSectionOffset(dwarf::Attribute Attr,
uint64_t FailValue) const {
if (auto Value = getAttributeValueAsSectionOffset(Attr))
return *Value;
return FailValue;
}

Optional<uint64_t>
DWARFDie::getAttributeValueAsSectionOffset(dwarf::Attribute Attr) const {
if (auto FormValue = getAttributeValue(Attr))
Expand Down Expand Up @@ -345,9 +307,10 @@ DWARFDie::getName(DINameKind Kind) const {

void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
uint32_t &CallColumn) const {
CallFile = getAttributeValueAsUnsignedConstant(DW_AT_call_file, 0);
CallLine = getAttributeValueAsUnsignedConstant(DW_AT_call_line, 0);
CallColumn = getAttributeValueAsUnsignedConstant(DW_AT_call_column, 0);
CallFile = getAttributeValueAsUnsignedConstant(DW_AT_call_file).getValueOr(0);
CallLine = getAttributeValueAsUnsignedConstant(DW_AT_call_line).getValueOr(0);
CallColumn =
getAttributeValueAsUnsignedConstant(DW_AT_call_column).getValueOr(0);
}

void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth,
Expand Down
10 changes: 6 additions & 4 deletions llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,12 @@ size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {
BaseAddr = UnitDie.getAttributeValueAsAddress(DW_AT_entry_pc);
if (BaseAddr)
setBaseAddress(*BaseAddr);
AddrOffsetSectionBase = UnitDie.getAttributeValueAsSectionOffset(
DW_AT_GNU_addr_base, 0);
RangeSectionBase = UnitDie.getAttributeValueAsSectionOffset(
DW_AT_rnglists_base, 0);
AddrOffsetSectionBase =
UnitDie.getAttributeValueAsSectionOffset(DW_AT_GNU_addr_base)
.getValueOr(0);
RangeSectionBase =
UnitDie.getAttributeValueAsSectionOffset(DW_AT_rnglists_base)
.getValueOr(0);
// Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for
// skeleton CU DIE, so that DWARF users not aware of it are not broken.
}
Expand Down
41 changes: 25 additions & 16 deletions llvm/tools/dsymutil/DwarfLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ class CompileUnit {
Info.resize(OrigUnit.getNumDIEs());

auto CUDie = OrigUnit.getUnitDIE(false);
unsigned Lang = CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_language, 0);
unsigned Lang =
CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_language)
.getValueOr(0);
HasODR = CanUseODR && (Lang == dwarf::DW_LANG_C_plus_plus ||
Lang == dwarf::DW_LANG_C_plus_plus_03 ||
Lang == dwarf::DW_LANG_C_plus_plus_11 ||
Expand Down Expand Up @@ -1556,7 +1558,8 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
// Do not unique anything inside CU local functions.
if ((Context.getTag() == dwarf::DW_TAG_namespace ||
Context.getTag() == dwarf::DW_TAG_compile_unit) &&
!DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_external, 0))
!DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_external)
.getValueOr(0))
return PointerIntPair<DeclContext *, 1>(nullptr);
LLVM_FALLTHROUGH;
case dwarf::DW_TAG_member:
Expand All @@ -1570,7 +1573,8 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
// created on demand. For example implicitely defined constructors
// are ambiguous because of the way we identify contexts, and they
// won't be generated everytime everywhere.
if (DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_artificial, 0))
if (DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_artificial)
.getValueOr(0))
return PointerIntPair<DeclContext *, 1>(nullptr);
break;
}
Expand Down Expand Up @@ -1610,11 +1614,12 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
// namespaces, use these additional data points to make the process
// safer. This is disabled for clang modules, because forward
// declarations of module-defined types do not have a file and line.
ByteSize = DIE.getAttributeValueAsUnsignedConstant(
dwarf::DW_AT_byte_size, UINT64_MAX);
ByteSize = DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_byte_size)
.getValueOr(UINT64_MAX);
if (Tag != dwarf::DW_TAG_namespace || !Name) {
if (unsigned FileNum = DIE.getAttributeValueAsUnsignedConstant(
dwarf::DW_AT_decl_file, 0)) {
if (unsigned FileNum =
DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_decl_file)
.getValueOr(0)) {
if (const auto *LT = U.getOrigUnit().getContext().getLineTableForUnit(
&U.getOrigUnit())) {
// FIXME: dsymutil-classic compatibility. I'd rather not
Expand All @@ -1627,8 +1632,9 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
// instead of "" would allow more uniquing, but for now, do
// it this way to match dsymutil-classic.
if (LT->hasFileAtIndex(FileNum)) {
Line = DIE.getAttributeValueAsUnsignedConstant(
dwarf::DW_AT_decl_line, 0);
Line =
DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_decl_line)
.getValueOr(0);
// Cache the resolved paths, because calling realpath is expansive.
StringRef ResolvedPath = U.getResolvedPath(FileNum);
if (!ResolvedPath.empty()) {
Expand Down Expand Up @@ -1803,9 +1809,10 @@ static bool analyzeContextInfo(const DWARFDie &DIE,
// Prune this DIE if it is either a forward declaration inside a
// DW_TAG_module or a DW_TAG_module that contains nothing but
// forward declarations.
Info.Prune &= (DIE.getTag() == dwarf::DW_TAG_module) ||
DIE.getAttributeValueAsUnsignedConstant(
dwarf::DW_AT_declaration, 0);
Info.Prune &=
(DIE.getTag() == dwarf::DW_TAG_module) ||
DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_declaration)
.getValueOr(0);

// Don't prune it if there is no definition for the DIE.
Info.Prune &= Info.Ctxt && Info.Ctxt->getCanonicalDIEOffset();
Expand Down Expand Up @@ -2740,12 +2747,13 @@ DIE *DwarfLinker::DIECloner::cloneDIE(
// independantly by the linker). The computation of the actual
// high_pc value is done in cloneAddressAttribute().
AttrInfo.OrigHighPc =
InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_high_pc, 0);
InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_high_pc).getValueOr(0);
// Also store the low_pc. It might get relocated in an
// inline_subprogram that happens at the beginning of its
// inlining function.
AttrInfo.OrigLowPc =
InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_low_pc, UINT64_MAX);
InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_low_pc)
.getValueOr(UINT64_MAX);
}

// Reset the Offset to 0 as we will be working on the local copy of
Expand Down Expand Up @@ -2864,8 +2872,9 @@ void DwarfLinker::patchRangesForUnit(const CompileUnit &Unit,
auto InvalidRange = FunctionRanges.end(), CurrRange = InvalidRange;
DWARFUnit &OrigUnit = Unit.getOrigUnit();
auto OrigUnitDie = OrigUnit.getUnitDIE(false);
uint64_t OrigLowPc = OrigUnitDie.getAttributeValueAsAddress(
dwarf::DW_AT_low_pc, -1ULL);
uint64_t OrigLowPc =
OrigUnitDie.getAttributeValueAsAddress(dwarf::DW_AT_low_pc)
.getValueOr(-1ULL);
// Ranges addresses are based on the unit's low_pc. Compute the
// offset we need to apply to adapt to the new unit's low_pc.
int64_t UnitPcOffset = 0;
Expand Down

0 comments on commit d1efea8

Please sign in to comment.