diff --git a/bolt/include/bolt/Core/DebugData.h b/bolt/include/bolt/Core/DebugData.h --- a/bolt/include/bolt/Core/DebugData.h +++ b/bolt/include/bolt/Core/DebugData.h @@ -46,7 +46,7 @@ /// \param DIE die to look up in. /// \param AbbrevDecl abbrev declaration for the die. /// \param Index an index in Abbrev declaration entry. -Optional +std::optional findAttributeInfo(const DWARFDie DIE, const DWARFAbbreviationDeclaration *AbbrevDecl, uint32_t Index); @@ -56,7 +56,8 @@ /// \param DIE die to look up in. /// \param Attr the attribute to extract. /// \return an optional AttrInfo with DWARFFormValue and Offset. -Optional findAttributeInfo(const DWARFDie DIE, dwarf::Attribute Attr); +std::optional findAttributeInfo(const DWARFDie DIE, + dwarf::Attribute Attr); // DWARF5 Header in order of encoding. // Types represent encodnig sizes. diff --git a/bolt/lib/Core/DebugData.cpp b/bolt/lib/Core/DebugData.cpp --- a/bolt/lib/Core/DebugData.cpp +++ b/bolt/lib/Core/DebugData.cpp @@ -42,7 +42,7 @@ namespace bolt { -Optional +std::optional findAttributeInfo(const DWARFDie DIE, const DWARFAbbreviationDeclaration *AbbrevDecl, uint32_t Index) { @@ -73,8 +73,8 @@ return AttrInfo{*Value, DIE.getAbbreviationDeclarationPtr(), Offset, ValSize}; } -Optional findAttributeInfo(const DWARFDie DIE, - dwarf::Attribute Attr) { +std::optional findAttributeInfo(const DWARFDie DIE, + dwarf::Attribute Attr) { if (!DIE.isValid()) return std::nullopt; const DWARFAbbreviationDeclaration *AbbrevDecl = @@ -666,7 +666,7 @@ *LocStream << *LocBodyBuffer; if (!isSplitDwarf()) { - if (Optional AttrInfoVal = + if (std::optional AttrInfoVal = findAttributeInfo(CU.getUnitDIE(), dwarf::DW_AT_loclists_base)) DebugInfoPatcher.addLE32Patch(AttrInfoVal->Offset, LoclistBaseOffset + @@ -733,7 +733,7 @@ uint32_t Offset = DIE.getOffset() + 1; size_t NumOfAttributes = AbbrevDecl->getNumAttributes(); if (NumOfAttributes) { - Optional Val = + std::optional Val = findAttributeInfo(DIE, AbbrevDecl, NumOfAttributes - 1); assert(Val && "Invalid Value."); diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp --- a/bolt/lib/Rewrite/DWARFRewriter.cpp +++ b/bolt/lib/Rewrite/DWARFRewriter.cpp @@ -62,10 +62,10 @@ /// \param DIE die to look up in. /// \param Attrs finds the first attribute that matches and extracts it. /// \return an optional AttrInfo with DWARFFormValue and Offset. -Optional findAttributeInfo(const DWARFDie DIE, - std::vector Attrs) { +std::optional findAttributeInfo(const DWARFDie DIE, + std::vector Attrs) { for (dwarf::Attribute &Attr : Attrs) - if (Optional Info = findAttributeInfo(DIE, Attr)) + if (std::optional Info = findAttributeInfo(DIE, Attr)) return Info; return std::nullopt; } @@ -230,7 +230,7 @@ auto updateDWONameCompDir = [&](DWARFUnit &Unit) -> void { const DWARFDie &DIE = Unit.getUnitDIE(); - Optional AttrInfoVal = findAttributeInfo( + std::optional AttrInfoVal = findAttributeInfo( DIE, {dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}); (void)AttrInfoVal; assert(AttrInfoVal && "Skeleton CU doesn't have dwo_name."); @@ -514,11 +514,11 @@ } }; - if (Optional AttrVal = + if (std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_call_pc)) patchPC(*AttrVal, "DW_AT_call_pc"); - if (Optional AttrVal = + if (std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_call_return_pc)) patchPC(*AttrVal, "DW_AT_call_return_pc"); @@ -528,7 +528,7 @@ // Handle any tag that can have DW_AT_location attribute. DWARFFormValue Value; uint64_t AttrOffset; - if (Optional AttrVal = + if (std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_location)) { AttrOffset = AttrVal->Offset; Value = AttrVal->V; @@ -690,7 +690,7 @@ SizeDiff + CurrEndOffset, 1); } } - } else if (Optional AttrVal = + } else if (std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_low_pc)) { AttrOffset = AttrVal->Offset; Value = AttrVal->V; @@ -736,7 +736,7 @@ } } else if (IsDWP && Unit.isDWOUnit()) { // Not a common path so don't want to search all DIEs all the time. - Optional SignatureAttrVal = + std::optional SignatureAttrVal = findAttributeInfo(DIE, dwarf::DW_AT_signature); if (!SignatureAttrVal) continue; @@ -771,7 +771,8 @@ case dwarf::DW_FORM_ref8: case dwarf::DW_FORM_ref_udata: case dwarf::DW_FORM_ref_addr: { - Optional AttrVal = findAttributeInfo(DIE, AbbrevDecl, Index); + std::optional AttrVal = + findAttributeInfo(DIE, AbbrevDecl, Index); uint32_t DestinationAddress = AttrVal->V.getRawUValue() + (Decl.Form == dwarf::DW_FORM_ref_addr ? 0 : Unit.getOffset()); @@ -813,7 +814,7 @@ if (RangesBase) { // If DW_AT_GNU_ranges_base is present, update it. No further modifications // are needed for ranges base. - Optional RangesBaseAttrInfo = + std::optional RangesBaseAttrInfo = findAttributeInfo(DIE, dwarf::DW_AT_GNU_ranges_base); if (!RangesBaseAttrInfo) RangesBaseAttrInfo = findAttributeInfo(DIE, dwarf::DW_AT_rnglists_base); @@ -826,9 +827,9 @@ } } - Optional LowPCAttrInfo = + std::optional LowPCAttrInfo = findAttributeInfo(DIE, dwarf::DW_AT_low_pc); - if (Optional AttrVal = + if (std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_ranges)) { // Case 1: The object was already non-contiguous and had DW_AT_ranges. // In this case we simply need to update the value of DW_AT_ranges @@ -881,7 +882,7 @@ // Case 2: The object has both DW_AT_low_pc and DW_AT_high_pc emitted back // to back. Replace with new attributes and patch the DIE. - Optional HighPCAttrInfo = + std::optional HighPCAttrInfo = findAttributeInfo(DIE, dwarf::DW_AT_high_pc); if (LowPCAttrInfo && HighPCAttrInfo) { convertToRangesPatchAbbrev(*DIE.getDwarfUnit(), AbbreviationDecl, @@ -937,7 +938,7 @@ if (!Label) continue; - Optional AttrVal = + std::optional AttrVal = findAttributeInfo(CU.get()->getUnitDIE(), dwarf::DW_AT_stmt_list); if (!AttrVal) continue; @@ -951,7 +952,7 @@ for (const std::unique_ptr &TU : BC.DwCtx->types_section_units()) { DWARFUnit *Unit = TU.get(); - Optional AttrVal = + std::optional AttrVal = findAttributeInfo(TU.get()->getUnitDIE(), dwarf::DW_AT_stmt_list); if (!AttrVal) continue; @@ -1039,9 +1040,9 @@ uint64_t Offset = 0; uint64_t AttrOffset = 0; uint32_t Size = 0; - Optional AttrValGnu = + std::optional AttrValGnu = findAttributeInfo(DIE, dwarf::DW_AT_GNU_addr_base); - Optional AttrVal = + std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_addr_base); // For cases where Skeleton CU does not have DW_AT_GNU_addr_base @@ -1827,8 +1828,8 @@ namespace { -void getRangeAttrData(DWARFDie DIE, Optional &LowPCVal, - Optional &HighPCVal) { +void getRangeAttrData(DWARFDie DIE, std::optional &LowPCVal, + std::optional &HighPCVal) { LowPCVal = findAttributeInfo(DIE, dwarf::DW_AT_low_pc); HighPCVal = findAttributeInfo(DIE, dwarf::DW_AT_high_pc); uint64_t LowPCOffset = LowPCVal->Offset; @@ -1894,8 +1895,8 @@ DWARFDie DIE, uint64_t RangesSectionOffset, SimpleBinaryPatcher &DebugInfoPatcher, uint64_t LowPCToUse, Optional RangesBase) { - Optional LowPCVal; - Optional HighPCVal; + std::optional LowPCVal; + std::optional HighPCVal; getRangeAttrData(DIE, LowPCVal, HighPCVal); uint64_t LowPCOffset = LowPCVal->Offset; uint64_t HighPCOffset = HighPCVal->Offset;