55 changes: 28 additions & 27 deletions llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void dumpUUID(raw_ostream &OS, const ObjectFile &Obj) {
}

using ContributionCollection =
std::vector<Optional<StrOffsetsContributionDescriptor>>;
std::vector<std::optional<StrOffsetsContributionDescriptor>>;

// Collect all the contributions to the string offsets table from all units,
// sort them by their starting offsets and remove duplicates.
Expand All @@ -117,8 +117,8 @@ collectContributionData(DWARFContext::unit_iterator_range Units) {
// the start of the contributions vector. This way they are reported
// first.
llvm::sort(Contributions,
[](const Optional<StrOffsetsContributionDescriptor> &L,
const Optional<StrOffsetsContributionDescriptor> &R) {
[](const std::optional<StrOffsetsContributionDescriptor> &L,
const std::optional<StrOffsetsContributionDescriptor> &R) {
if (L && R)
return L->Base < R->Base;
return R.has_value();
Expand All @@ -129,8 +129,8 @@ collectContributionData(DWARFContext::unit_iterator_range Units) {
// to report them more than once.
Contributions.erase(
std::unique(Contributions.begin(), Contributions.end(),
[](const Optional<StrOffsetsContributionDescriptor> &L,
const Optional<StrOffsetsContributionDescriptor> &R) {
[](const std::optional<StrOffsetsContributionDescriptor> &L,
const std::optional<StrOffsetsContributionDescriptor> &R) {
if (L && R)
return L->Base == R->Base && L->Size == R->Size;
return false;
Expand Down Expand Up @@ -245,7 +245,7 @@ static void dumpAddrSection(raw_ostream &OS, DWARFDataExtractor &AddrData,
// Dump the .debug_rnglists or .debug_rnglists.dwo section (DWARF v5).
static void dumpRnglistsSection(
raw_ostream &OS, DWARFDataExtractor &rnglistData,
llvm::function_ref<Optional<object::SectionedAddress>(uint32_t)>
llvm::function_ref<std::optional<object::SectionedAddress>(uint32_t)>
LookupPooledAddress,
DIDumpOptions DumpOpts) {
uint64_t Offset = 0;
Expand Down Expand Up @@ -312,7 +312,7 @@ static void dumpLoclistsSection(raw_ostream &OS, DIDumpOptions DumpOpts,
DWARFDataExtractor Data,
const MCRegisterInfo *MRI,
const DWARFObject &Obj,
Optional<uint64_t> DumpOffset) {
std::optional<uint64_t> DumpOffset) {
uint64_t Offset = 0;

while (Data.isValidOffset(Offset)) {
Expand Down Expand Up @@ -351,7 +351,7 @@ static void dumpPubTableSection(raw_ostream &OS, DIDumpOptions DumpOpts,

void DWARFContext::dump(
raw_ostream &OS, DIDumpOptions DumpOpts,
std::array<Optional<uint64_t>, DIDT_ID_Count> DumpOffsets) {
std::array<std::optional<uint64_t>, DIDT_ID_Count> DumpOffsets) {
uint64_t DumpType = DumpOpts.DumpType;

StringRef Extension = sys::path::extension(DObj->getFileName());
Expand All @@ -368,7 +368,7 @@ void DWARFContext::dump(
bool Explicit = DumpType != DIDT_All && !IsDWO;
bool ExplicitDWO = Explicit && IsDWO;
auto shouldDump = [&](bool Explicit, const char *Name, unsigned ID,
StringRef Section) -> Optional<uint64_t> * {
StringRef Section) -> std::optional<uint64_t> * {
unsigned Mask = 1U << ID;
bool Should = (DumpType & Mask) && (Explicit || !Section.empty());
if (!Should)
Expand Down Expand Up @@ -459,7 +459,7 @@ void DWARFContext::dump(
}
}

if (const Optional<uint64_t> *Off =
if (const std::optional<uint64_t> *Off =
shouldDump(Explicit, ".debug_frame", DIDT_ID_DebugFrame,
DObj->getFrameSection().Data)) {
if (Expected<const DWARFDebugFrame *> DF = getDebugFrame())
Expand All @@ -468,7 +468,7 @@ void DWARFContext::dump(
RecoverableErrorHandler(DF.takeError());
}

if (const Optional<uint64_t> *Off =
if (const std::optional<uint64_t> *Off =
shouldDump(Explicit, ".eh_frame", DIDT_ID_DebugFrame,
DObj->getEHFrameSection().Data)) {
if (Expected<const DWARFDebugFrame *> DF = getEHFrame())
Expand Down Expand Up @@ -519,7 +519,7 @@ void DWARFContext::dump(

auto DumpLineSection = [&](DWARFDebugLine::SectionParser Parser,
DIDumpOptions DumpOpts,
Optional<uint64_t> DumpOffset) {
std::optional<uint64_t> DumpOffset) {
while (!Parser.done()) {
if (DumpOffset && Parser.getOffset() != *DumpOffset) {
Parser.skip(DumpOpts.WarningHandler, DumpOpts.WarningHandler);
Expand Down Expand Up @@ -612,7 +612,8 @@ void DWARFContext::dump(
}
}

auto LookupPooledAddress = [&](uint32_t Index) -> Optional<SectionedAddress> {
auto LookupPooledAddress =
[&](uint32_t Index) -> std::optional<SectionedAddress> {
const auto &CUs = compile_units();
auto I = CUs.begin();
if (I == CUs.end())
Expand Down Expand Up @@ -712,7 +713,7 @@ DWARFTypeUnit *DWARFContext::getTypeUnitForHash(uint16_t Version, uint64_t Hash,

struct UnitContainers {
const DWARFUnitVector &Units;
Optional<DenseMap<uint64_t, DWARFTypeUnit *>> &Map;
std::optional<DenseMap<uint64_t, DWARFTypeUnit *>> &Map;
};
UnitContainers Units = IsDWO ? UnitContainers{DWOUnits, DWOTypeUnits}
: UnitContainers{NormalUnits, NormalTypeUnits};
Expand Down Expand Up @@ -744,8 +745,8 @@ DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) {
for (const auto &DWOCU : dwo_compile_units()) {
// Might not have parsed DWO ID yet.
if (!DWOCU->getDWOId()) {
if (Optional<uint64_t> DWOId =
toUnsigned(DWOCU->getUnitDIE().find(DW_AT_GNU_dwo_id)))
if (std::optional<uint64_t> DWOId =
toUnsigned(DWOCU->getUnitDIE().find(DW_AT_GNU_dwo_id)))
DWOCU->setDWOId(*DWOId);
else
// No DWO ID?
Expand Down Expand Up @@ -1111,7 +1112,7 @@ static bool getFunctionNameAndStartLineForAddress(
DWARFCompileUnit *CU, uint64_t Address, FunctionNameKind Kind,
DILineInfoSpecifier::FileLineInfoKind FileNameKind,
std::string &FunctionName, std::string &StartFile, uint32_t &StartLine,
Optional<uint64_t> &StartAddress) {
std::optional<uint64_t> &StartAddress) {
// The address may correspond to instruction in some inlined function,
// so we have to build the chain of inlined functions and take the
// name of the topmost function in it.
Expand Down Expand Up @@ -1141,9 +1142,9 @@ static bool getFunctionNameAndStartLineForAddress(
return FoundResult;
}

static Optional<int64_t>
static std::optional<int64_t>
getExpressionFrameOffset(ArrayRef<uint8_t> Expr,
Optional<unsigned> FrameBaseReg) {
std::optional<unsigned> FrameBaseReg) {
if (!Expr.empty() &&
(Expr[0] == DW_OP_fbreg ||
(FrameBaseReg && Expr[0] == DW_OP_breg0 + *FrameBaseReg))) {
Expand All @@ -1168,9 +1169,9 @@ void DWARFContext::addLocalsForDie(DWARFCompileUnit *CU, DWARFDie Subprogram,
if (const char *Name = Subprogram.getSubroutineName(DINameKind::ShortName))
Local.FunctionName = Name;

Optional<unsigned> FrameBaseReg;
std::optional<unsigned> FrameBaseReg;
if (auto FrameBase = Subprogram.find(DW_AT_frame_base))
if (Optional<ArrayRef<uint8_t>> Expr = FrameBase->getAsBlock())
if (std::optional<ArrayRef<uint8_t>> Expr = FrameBase->getAsBlock())
if (!Expr->empty() && (*Expr)[0] >= DW_OP_reg0 &&
(*Expr)[0] <= DW_OP_reg31) {
FrameBaseReg = (*Expr)[0] - DW_OP_reg0;
Expand All @@ -1179,7 +1180,7 @@ void DWARFContext::addLocalsForDie(DWARFCompileUnit *CU, DWARFDie Subprogram,
if (Expected<std::vector<DWARFLocationExpression>> Loc =
Die.getLocations(DW_AT_location)) {
for (const auto &Entry : *Loc) {
if (Optional<int64_t> FrameOffset =
if (std::optional<int64_t> FrameOffset =
getExpressionFrameOffset(Entry.Expr, FrameBaseReg)) {
Local.FrameOffset = *FrameOffset;
break;
Expand All @@ -1198,7 +1199,7 @@ void DWARFContext::addLocalsForDie(DWARFCompileUnit *CU, DWARFDie Subprogram,
Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
Die = Origin;
if (auto NameAttr = Die.find(DW_AT_name))
if (Optional<const char *> Name = dwarf::toString(*NameAttr))
if (std::optional<const char *> Name = dwarf::toString(*NameAttr))
Local.Name = *Name;
if (auto Type = Die.getAttributeValueAsReferencedDie(DW_AT_type))
Local.Size = Type.getTypeSize(getCUAddrSize());
Expand Down Expand Up @@ -1285,7 +1286,7 @@ DILineInfoTable DWARFContext::getLineInfoForAddressRange(
uint32_t StartLine = 0;
std::string StartFileName;
std::string FunctionName(DILineInfo::BadString);
Optional<uint64_t> StartAddress;
std::optional<uint64_t> StartAddress;
getFunctionNameAndStartLineForAddress(CU, Address.Address, Spec.FNKind,
Spec.FLIKind, FunctionName,
StartFileName, StartLine, StartAddress);
Expand Down Expand Up @@ -1846,9 +1847,9 @@ class DWARFObjInMemory final : public DWARFObject {
if (Supports && Supports(Reloc.getType())) {
auto I = Map->try_emplace(
Reloc.getOffset(),
RelocAddrEntry{SymInfoOrErr->SectionIndex, Reloc,
SymInfoOrErr->Address,
Optional<object::RelocationRef>(), 0, Resolver});
RelocAddrEntry{
SymInfoOrErr->SectionIndex, Reloc, SymInfoOrErr->Address,
std::optional<object::RelocationRef>(), 0, Resolver});
// If we didn't successfully insert that's because we already had a
// relocation for that offset. Store it as a second relocation in the
// same RelocAddrEntry instead.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFDataExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ uint64_t DWARFDataExtractor::getRelocatedValue(uint32_t Size, uint64_t *Off,
return R;
}

Optional<uint64_t>
std::optional<uint64_t>
DWARFDataExtractor::getEncodedPointer(uint64_t *Offset, uint8_t Encoding,
uint64_t PCRelOffset) const {
if (Encoding == dwarf::DW_EH_PE_omit)
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/DebugInfo/DWARF/DWARFDebugAddr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ Expected<uint64_t> DWARFDebugAddrTable::getAddrEntry(uint32_t Index) const {
Index, Offset);
}

Optional<uint64_t> DWARFDebugAddrTable::getFullLength() const {
std::optional<uint64_t> DWARFDebugAddrTable::getFullLength() const {
if (Length == 0)
return std::nullopt;
return Length + dwarf::getUnitLengthFieldByteSize(Format);
}

14 changes: 7 additions & 7 deletions llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ UnwindLocation UnwindLocation::createAtCFAPlusOffset(int32_t Offset) {

UnwindLocation
UnwindLocation::createIsRegisterPlusOffset(uint32_t RegNum, int32_t Offset,
Optional<uint32_t> AddrSpace) {
std::optional<uint32_t> AddrSpace) {
return {RegPlusOffset, RegNum, Offset, AddrSpace, false};
}

UnwindLocation
UnwindLocation::createAtRegisterPlusOffset(uint32_t RegNum, int32_t Offset,
Optional<uint32_t> AddrSpace) {
std::optional<uint32_t> AddrSpace) {
return {RegPlusOffset, RegNum, Offset, AddrSpace, true};
}

Expand Down Expand Up @@ -571,7 +571,7 @@ Error UnwindTable::parseRows(const CFIProgram &CFIP, UnwindRow &Row,
llvm::Expected<uint64_t> RegNum = Inst.getOperandAsUnsigned(CFIP, 0);
if (!RegNum)
return RegNum.takeError();
if (Optional<UnwindLocation> O =
if (std::optional<UnwindLocation> O =
InitialLocs->getRegisterLocation(*RegNum))
Row.getRegisterLocations().setRegisterLocation(*RegNum, *O);
else
Expand Down Expand Up @@ -1089,8 +1089,8 @@ Error DWARFDebugFrame::parse(DWARFDataExtractor Data) {
StringRef AugmentationData("");
uint32_t FDEPointerEncoding = DW_EH_PE_absptr;
uint32_t LSDAPointerEncoding = DW_EH_PE_omit;
Optional<uint64_t> Personality;
Optional<uint32_t> PersonalityEncoding;
std::optional<uint64_t> Personality;
std::optional<uint32_t> PersonalityEncoding;
if (IsEH) {
std::optional<uint64_t> AugmentationLength;
uint64_t StartAugmentationOffset;
Expand Down Expand Up @@ -1170,7 +1170,7 @@ Error DWARFDebugFrame::parse(DWARFDataExtractor Data) {
uint64_t CIEPointer = Id;
uint64_t InitialLocation = 0;
uint64_t AddressRange = 0;
Optional<uint64_t> LSDAAddress;
std::optional<uint64_t> LSDAAddress;
CIE *Cie = CIEs[IsEH ? (StartStructureOffset - CIEPointer) : CIEPointer];

if (IsEH) {
Expand Down Expand Up @@ -1244,7 +1244,7 @@ FrameEntry *DWARFDebugFrame::getEntryAtOffset(uint64_t Offset) const {

void DWARFDebugFrame::dump(raw_ostream &OS, DIDumpOptions DumpOpts,
const MCRegisterInfo *MRI,
Optional<uint64_t> Offset) const {
std::optional<uint64_t> Offset) const {
if (Offset) {
if (auto *Entry = getEntryAtOffset(*Offset))
Entry->dump(OS, DumpOpts, MRI, IsEH);
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint64_t *OffsetPtr,
}
// See if all attributes in this DIE have fixed byte sizes. If so, we can
// just add this size to the offset to skip to the next DIE.
if (Optional<size_t> FixedSize = AbbrevDecl->getFixedAttributesByteSize(U)) {
if (std::optional<size_t> FixedSize =
AbbrevDecl->getFixedAttributesByteSize(U)) {
*OffsetPtr += *FixedSize;
return true;
}
Expand Down
23 changes: 13 additions & 10 deletions llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ bool DWARFDebugLine::Prologue::hasFileAtIndex(uint64_t FileIndex) const {
return FileIndex != 0 && FileIndex <= FileNames.size();
}

Optional<uint64_t> DWARFDebugLine::Prologue::getLastValidFileIndex() const {
std::optional<uint64_t>
DWARFDebugLine::Prologue::getLastValidFileIndex() const {
if (FileNames.empty())
return std::nullopt;
uint16_t DwarfVersion = getVersion();
Expand Down Expand Up @@ -717,8 +718,8 @@ DWARFDebugLine::ParsingState::handleSpecialOpcode(uint8_t Opcode,
/// Parse a ULEB128 using the specified \p Cursor. \returns the parsed value on
/// success, or None if \p Cursor is in a failing state.
template <typename T>
static Optional<T> parseULEB128(DWARFDataExtractor &Data,
DataExtractor::Cursor &Cursor) {
static std::optional<T> parseULEB128(DWARFDataExtractor &Data,
DataExtractor::Cursor &Cursor) {
T Value = Data.getULEB128(Cursor);
if (Cursor)
return Value;
Expand Down Expand Up @@ -1005,7 +1006,7 @@ Error DWARFDebugLine::LineTable::parse(
// Takes a single unsigned LEB128 operand, multiplies it by the
// min_inst_length field of the prologue, and adds the
// result to the address register of the state machine.
if (Optional<uint64_t> Operand =
if (std::optional<uint64_t> Operand =
parseULEB128<uint64_t>(TableData, Cursor)) {
uint64_t AddrOffset =
State.advanceAddr(*Operand, Opcode, OpcodeOffset);
Expand All @@ -1030,7 +1031,7 @@ Error DWARFDebugLine::LineTable::parse(
case DW_LNS_set_file:
// Takes a single unsigned LEB128 operand and stores it in the file
// register of the state machine.
if (Optional<uint16_t> File =
if (std::optional<uint16_t> File =
parseULEB128<uint16_t>(TableData, Cursor)) {
State.Row.File = *File;
if (Verbose)
Expand All @@ -1041,7 +1042,7 @@ Error DWARFDebugLine::LineTable::parse(
case DW_LNS_set_column:
// Takes a single unsigned LEB128 operand and stores it in the
// column register of the state machine.
if (Optional<uint16_t> Column =
if (std::optional<uint16_t> Column =
parseULEB128<uint16_t>(TableData, Cursor)) {
State.Row.Column = *Column;
if (Verbose)
Expand Down Expand Up @@ -1117,7 +1118,8 @@ Error DWARFDebugLine::LineTable::parse(
case DW_LNS_set_isa:
// Takes a single unsigned LEB128 operand and stores it in the
// ISA register of the state machine.
if (Optional<uint8_t> Isa = parseULEB128<uint8_t>(TableData, Cursor)) {
if (std::optional<uint8_t> Isa =
parseULEB128<uint8_t>(TableData, Cursor)) {
State.Row.Isa = *Isa;
if (Verbose)
*OS << " (" << (uint64_t)State.Row.Isa << ")";
Expand All @@ -1135,7 +1137,7 @@ Error DWARFDebugLine::LineTable::parse(
uint8_t OpcodeLength = Prologue.StandardOpcodeLengths[Opcode - 1];
std::vector<uint64_t> Operands;
for (uint8_t I = 0; I < OpcodeLength; ++I) {
if (Optional<uint64_t> Value =
if (std::optional<uint64_t> Value =
parseULEB128<uint64_t>(TableData, Cursor))
Operands.push_back(*Value);
else
Expand Down Expand Up @@ -1330,8 +1332,9 @@ bool DWARFDebugLine::LineTable::lookupAddressRangeImpl(
return true;
}

Optional<StringRef> DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex,
FileLineInfoKind Kind) const {
std::optional<StringRef>
DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex,
FileLineInfoKind Kind) const {
if (Kind == FileLineInfoKind::None || !Prologue.hasFileAtIndex(FileIndex))
return std::nullopt;
const FileNameEntry &Entry = Prologue.getFileNameEntry(FileIndex);
Expand Down
41 changes: 20 additions & 21 deletions llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ class DWARFObject;

namespace {
class DWARFLocationInterpreter {
Optional<object::SectionedAddress> Base;
std::function<Optional<object::SectionedAddress>(uint32_t)> LookupAddr;
std::optional<object::SectionedAddress> Base;
std::function<std::optional<object::SectionedAddress>(uint32_t)> LookupAddr;

public:
DWARFLocationInterpreter(
Optional<object::SectionedAddress> Base,
std::function<Optional<object::SectionedAddress>(uint32_t)> LookupAddr)
std::optional<object::SectionedAddress> Base,
std::function<std::optional<object::SectionedAddress>(uint32_t)>
LookupAddr)
: Base(Base), LookupAddr(std::move(LookupAddr)) {}

Expected<Optional<DWARFLocationExpression>>
Expected<std::optional<DWARFLocationExpression>>
Interpret(const DWARFLocationEntry &E);
};
} // namespace
Expand All @@ -48,7 +49,7 @@ static Error createResolverError(uint32_t Index, unsigned Kind) {
return make_error<ResolverError>(Index, (dwarf::LoclistEntries)Kind);
}

Expected<Optional<DWARFLocationExpression>>
Expected<std::optional<DWARFLocationExpression>>
DWARFLocationInterpreter::Interpret(const DWARFLocationEntry &E) {
switch (E.Kind) {
case dwarf::DW_LLE_end_of_list:
Expand All @@ -60,18 +61,18 @@ DWARFLocationInterpreter::Interpret(const DWARFLocationEntry &E) {
return std::nullopt;
}
case dwarf::DW_LLE_startx_endx: {
Optional<SectionedAddress> LowPC = LookupAddr(E.Value0);
std::optional<SectionedAddress> LowPC = LookupAddr(E.Value0);
if (!LowPC)
return createResolverError(E.Value0, E.Kind);
Optional<SectionedAddress> HighPC = LookupAddr(E.Value1);
std::optional<SectionedAddress> HighPC = LookupAddr(E.Value1);
if (!HighPC)
return createResolverError(E.Value1, E.Kind);
return DWARFLocationExpression{
DWARFAddressRange{LowPC->Address, HighPC->Address, LowPC->SectionIndex},
E.Loc};
}
case dwarf::DW_LLE_startx_length: {
Optional<SectionedAddress> LowPC = LookupAddr(E.Value0);
std::optional<SectionedAddress> LowPC = LookupAddr(E.Value0);
if (!LowPC)
return createResolverError(E.Value0, E.Kind);
return DWARFLocationExpression{DWARFAddressRange{LowPC->Address,
Expand Down Expand Up @@ -120,21 +121,19 @@ static void dumpExpression(raw_ostream &OS, DIDumpOptions DumpOpts,
DWARFExpression(Extractor, AddressSize).print(OS, DumpOpts, MRI, U);
}

bool DWARFLocationTable::dumpLocationList(uint64_t *Offset, raw_ostream &OS,
Optional<SectionedAddress> BaseAddr,
const MCRegisterInfo *MRI,
const DWARFObject &Obj, DWARFUnit *U,
DIDumpOptions DumpOpts,
unsigned Indent) const {
bool DWARFLocationTable::dumpLocationList(
uint64_t *Offset, raw_ostream &OS, std::optional<SectionedAddress> BaseAddr,
const MCRegisterInfo *MRI, const DWARFObject &Obj, DWARFUnit *U,
DIDumpOptions DumpOpts, unsigned Indent) const {
DWARFLocationInterpreter Interp(
BaseAddr, [U](uint32_t Index) -> Optional<SectionedAddress> {
BaseAddr, [U](uint32_t Index) -> std::optional<SectionedAddress> {
if (U)
return U->getAddrOffsetSectionItem(Index);
return std::nullopt;
});
OS << format("0x%8.8" PRIx64 ": ", *Offset);
Error E = visitLocationList(Offset, [&](const DWARFLocationEntry &E) {
Expected<Optional<DWARFLocationExpression>> Loc = Interp.Interpret(E);
Expected<std::optional<DWARFLocationExpression>> Loc = Interp.Interpret(E);
if (!Loc || DumpOpts.DisplayRawContents)
dumpRawEntry(E, OS, Indent, DumpOpts, Obj);
if (Loc && *Loc) {
Expand Down Expand Up @@ -170,12 +169,12 @@ bool DWARFLocationTable::dumpLocationList(uint64_t *Offset, raw_ostream &OS,
}

Error DWARFLocationTable::visitAbsoluteLocationList(
uint64_t Offset, Optional<SectionedAddress> BaseAddr,
std::function<Optional<SectionedAddress>(uint32_t)> LookupAddr,
uint64_t Offset, std::optional<SectionedAddress> BaseAddr,
std::function<std::optional<SectionedAddress>(uint32_t)> LookupAddr,
function_ref<bool(Expected<DWARFLocationExpression>)> Callback) const {
DWARFLocationInterpreter Interp(BaseAddr, std::move(LookupAddr));
return visitLocationList(&Offset, [&](const DWARFLocationEntry &E) {
Expected<Optional<DWARFLocationExpression>> Loc = Interp.Interpret(E);
Expected<std::optional<DWARFLocationExpression>> Loc = Interp.Interpret(E);
if (!Loc)
return Callback(Loc.takeError());
if (*Loc)
Expand All @@ -186,7 +185,7 @@ Error DWARFLocationTable::visitAbsoluteLocationList(

void DWARFDebugLoc::dump(raw_ostream &OS, const MCRegisterInfo *MRI,
const DWARFObject &Obj, DIDumpOptions DumpOpts,
Optional<uint64_t> DumpOffset) const {
std::optional<uint64_t> DumpOffset) const {
auto BaseAddr = std::nullopt;
unsigned Indent = 12;
if (DumpOffset) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ void DWARFDebugMacro::dump(raw_ostream &OS) const {
}

Error DWARFDebugMacro::parseImpl(
Optional<DWARFUnitVector::compile_unit_range> Units,
Optional<DataExtractor> StringExtractor, DWARFDataExtractor Data,
std::optional<DWARFUnitVector::compile_unit_range> Units,
std::optional<DataExtractor> StringExtractor, DWARFDataExtractor Data,
bool IsMacro) {
uint64_t Offset = 0;
MacroList *M = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void DWARFDebugRangeList::dump(raw_ostream &OS) const {
}

DWARFAddressRangesVector DWARFDebugRangeList::getAbsoluteRanges(
llvm::Optional<object::SectionedAddress> BaseAddr) const {
std::optional<object::SectionedAddress> BaseAddr) const {
DWARFAddressRangesVector Res;
// debug_addr can't use the max integer tombstone because that's used for the
// base address specifier entry - so use max-1.
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/DebugInfo/DWARF/DWARFDebugRnglists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ Error RangeListEntry::extract(DWARFDataExtractor Data, uint64_t *OffsetPtr) {
}

DWARFAddressRangesVector DWARFDebugRnglist::getAbsoluteRanges(
llvm::Optional<object::SectionedAddress> BaseAddr, DWARFUnit &U) const {
std::optional<object::SectionedAddress> BaseAddr, DWARFUnit &U) const {
return getAbsoluteRanges(
BaseAddr, U.getAddressByteSize(),
[&](uint32_t Index) { return U.getAddrOffsetSectionItem(Index); });
}

DWARFAddressRangesVector DWARFDebugRnglist::getAbsoluteRanges(
Optional<object::SectionedAddress> BaseAddr, uint8_t AddressByteSize,
function_ref<Optional<object::SectionedAddress>(uint32_t)>
std::optional<object::SectionedAddress> BaseAddr, uint8_t AddressByteSize,
function_ref<std::optional<object::SectionedAddress>(uint32_t)>
LookupPooledAddress) const {
DWARFAddressRangesVector Res;
uint64_t Tombstone = dwarf::computeTombstoneAddress(AddressByteSize);
Expand Down Expand Up @@ -175,7 +175,7 @@ DWARFAddressRangesVector DWARFDebugRnglist::getAbsoluteRanges(
void RangeListEntry::dump(
raw_ostream &OS, uint8_t AddrSize, uint8_t MaxEncodingStringLength,
uint64_t &CurrentBase, DIDumpOptions DumpOpts,
llvm::function_ref<Optional<object::SectionedAddress>(uint32_t)>
llvm::function_ref<std::optional<object::SectionedAddress>(uint32_t)>
LookupPooledAddress) const {
auto PrintRawEntry = [](raw_ostream &OS, const RangeListEntry &Entry,
uint8_t AddrSize, DIDumpOptions DumpOpts) {
Expand Down
44 changes: 22 additions & 22 deletions llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
Color = HighlightColor::String;
if (const auto *LT = U->getContext().getLineTableForUnit(U)) {
if (Optional<uint64_t> Val = FormValue.getAsUnsignedConstant()) {
if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant()) {
if (LT->getFileNameByIndex(
*Val, U->getCompilationDir(),
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
Expand All @@ -147,13 +147,13 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
}
}
}
} else if (Optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
} else if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
Name = AttributeValueString(Attr, *Val);

if (!Name.empty())
WithColor(OS, Color) << Name;
else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line) {
if (Optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
OS << *Val;
else
FormValue.dump(OS, DumpOpts);
Expand Down Expand Up @@ -207,7 +207,7 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
OS << '"';
}
} else if (Attr == DW_AT_APPLE_property_attribute) {
if (Optional<uint64_t> OptVal = FormValue.getAsUnsignedConstant())
if (std::optional<uint64_t> OptVal = FormValue.getAsUnsignedConstant())
dumpApplePropertyAttribute(OS, *OptVal);
} else if (Attr == DW_AT_ranges) {
const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj();
Expand Down Expand Up @@ -249,7 +249,7 @@ bool DWARFDie::isSubroutineDIE() const {
return Tag == DW_TAG_subprogram || Tag == DW_TAG_inlined_subroutine;
}

Optional<DWARFFormValue> DWARFDie::find(dwarf::Attribute Attr) const {
std::optional<DWARFFormValue> DWARFDie::find(dwarf::Attribute Attr) const {
if (!isValid())
return std::nullopt;
auto AbbrevDecl = getAbbreviationDeclarationPtr();
Expand All @@ -258,7 +258,7 @@ Optional<DWARFFormValue> DWARFDie::find(dwarf::Attribute Attr) const {
return std::nullopt;
}

Optional<DWARFFormValue>
std::optional<DWARFFormValue>
DWARFDie::find(ArrayRef<dwarf::Attribute> Attrs) const {
if (!isValid())
return std::nullopt;
Expand All @@ -272,7 +272,7 @@ DWARFDie::find(ArrayRef<dwarf::Attribute> Attrs) const {
return std::nullopt;
}

Optional<DWARFFormValue>
std::optional<DWARFFormValue>
DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const {
SmallVector<DWARFDie, 3> Worklist;
Worklist.push_back(*this);
Expand Down Expand Up @@ -307,7 +307,7 @@ DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const {

DWARFDie
DWARFDie::getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const {
if (Optional<DWARFFormValue> F = find(Attr))
if (std::optional<DWARFFormValue> F = find(Attr))
return getAttributeValueAsReferencedDie(*F);
return DWARFDie();
}
Expand All @@ -328,7 +328,7 @@ DWARFDie::getAttributeValueAsReferencedDie(const DWARFFormValue &V) const {

DWARFDie DWARFDie::resolveTypeUnitReference() const {
if (auto Attr = find(DW_AT_signature)) {
if (Optional<uint64_t> Sig = Attr->getAsReferenceUVal()) {
if (std::optional<uint64_t> Sig = Attr->getAsReferenceUVal()) {
if (DWARFTypeUnit *TU = U->getContext().getTypeUnitForHash(
U->getVersion(), *Sig, U->isDWOUnit()))
return TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
Expand All @@ -337,15 +337,15 @@ DWARFDie DWARFDie::resolveTypeUnitReference() const {
return *this;
}

Optional<uint64_t> DWARFDie::getRangesBaseAttribute() const {
std::optional<uint64_t> DWARFDie::getRangesBaseAttribute() const {
return toSectionOffset(find({DW_AT_rnglists_base, DW_AT_GNU_ranges_base}));
}

Optional<uint64_t> DWARFDie::getLocBaseAttribute() const {
std::optional<uint64_t> DWARFDie::getLocBaseAttribute() const {
return toSectionOffset(find(DW_AT_loclists_base));
}

Optional<uint64_t> DWARFDie::getHighPC(uint64_t LowPC) const {
std::optional<uint64_t> DWARFDie::getHighPC(uint64_t LowPC) const {
uint64_t Tombstone = dwarf::computeTombstoneAddress(U->getAddressByteSize());
if (LowPC == Tombstone)
return std::nullopt;
Expand Down Expand Up @@ -385,7 +385,7 @@ Expected<DWARFAddressRangesVector> DWARFDie::getAddressRanges() const {
if (getLowAndHighPC(LowPC, HighPC, Index))
return DWARFAddressRangesVector{{LowPC, HighPC, Index}};

Optional<DWARFFormValue> Value = find(DW_AT_ranges);
std::optional<DWARFFormValue> Value = find(DW_AT_ranges);
if (Value) {
if (Value->getForm() == DW_FORM_rnglistx)
return U->findRnglistFromIndex(*Value->getAsSectionOffset());
Expand All @@ -409,12 +409,12 @@ bool DWARFDie::addressRangeContainsAddress(const uint64_t Address) const {

Expected<DWARFLocationExpressionsVector>
DWARFDie::getLocations(dwarf::Attribute Attr) const {
Optional<DWARFFormValue> Location = find(Attr);
std::optional<DWARFFormValue> Location = find(Attr);
if (!Location)
return createStringError(inconvertibleErrorCode(), "No %s",
dwarf::AttributeString(Attr).data());

if (Optional<uint64_t> Off = Location->getAsSectionOffset()) {
if (std::optional<uint64_t> Off = Location->getAsSectionOffset()) {
uint64_t Offset = *Off;

if (Location->getForm() == DW_FORM_loclistx) {
Expand All @@ -427,7 +427,7 @@ DWARFDie::getLocations(dwarf::Attribute Attr) const {
return U->findLoclistFromOffset(Offset);
}

if (Optional<ArrayRef<uint8_t>> Expr = Location->getAsBlock()) {
if (std::optional<ArrayRef<uint8_t>> Expr = Location->getAsBlock()) {
return DWARFLocationExpressionsVector{
DWARFLocationExpression{std::nullopt, to_vector<4>(*Expr)}};
}
Expand Down Expand Up @@ -492,9 +492,9 @@ void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
CallDiscriminator = toUnsigned(find(DW_AT_GNU_discriminator), 0);
}

Optional<uint64_t> DWARFDie::getTypeSize(uint64_t PointerSize) {
std::optional<uint64_t> DWARFDie::getTypeSize(uint64_t PointerSize) {
if (auto SizeAttr = find(DW_AT_byte_size))
if (Optional<uint64_t> Size = SizeAttr->getAsUnsignedConstant())
if (std::optional<uint64_t> Size = SizeAttr->getAsUnsignedConstant())
return Size;

switch (getTag()) {
Expand All @@ -521,7 +521,7 @@ Optional<uint64_t> DWARFDie::getTypeSize(uint64_t PointerSize) {
DWARFDie BaseType = getAttributeValueAsReferencedDie(DW_AT_type);
if (!BaseType)
return std::nullopt;
Optional<uint64_t> BaseSize = BaseType.getTypeSize(PointerSize);
std::optional<uint64_t> BaseSize = BaseType.getTypeSize(PointerSize);
if (!BaseSize)
return std::nullopt;
uint64_t Size = *BaseSize;
Expand All @@ -530,11 +530,11 @@ Optional<uint64_t> DWARFDie::getTypeSize(uint64_t PointerSize) {
continue;

if (auto ElemCountAttr = Child.find(DW_AT_count))
if (Optional<uint64_t> ElemCount =
if (std::optional<uint64_t> ElemCount =
ElemCountAttr->getAsUnsignedConstant())
Size *= *ElemCount;
if (auto UpperBoundAttr = Child.find(DW_AT_upper_bound))
if (Optional<int64_t> UpperBound =
if (std::optional<int64_t> UpperBound =
UpperBoundAttr->getAsSignedConstant()) {
int64_t LowerBound = 0;
if (auto LowerBoundAttr = Child.find(DW_AT_lower_bound))
Expand Down Expand Up @@ -592,7 +592,7 @@ void DWARFDie::dump(raw_ostream &OS, unsigned Indent,
if (DumpOpts.Verbose) {
OS << format(" [%u] %c", abbrCode,
AbbrevDecl->hasChildren() ? '*' : ' ');
if (Optional<uint32_t> ParentIdx = Die->getParentIdx())
if (std::optional<uint32_t> ParentIdx = Die->getParentIdx())
OS << format(" (0x%8.8" PRIx64 ")",
U->getDIEAtIndex(*ParentIdx).getOffset());
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static DWARFExpression::Operation::Description getOpDesc(unsigned OpCode) {

bool DWARFExpression::Operation::extract(DataExtractor Data,
uint8_t AddressSize, uint64_t Offset,
Optional<DwarfFormat> Format) {
std::optional<DwarfFormat> Format) {
EndOffset = Offset;
Opcode = Data.getU8(&Offset);

Expand Down
34 changes: 19 additions & 15 deletions llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ bool DWARFFormValue::skipValue(dwarf::Form Form, DataExtractor DebugInfoData,
case DW_FORM_GNU_ref_alt:
case DW_FORM_GNU_strp_alt:
case DW_FORM_implicit_const:
if (Optional<uint8_t> FixedSize =
if (std::optional<uint8_t> FixedSize =
dwarf::getFixedFormByteSize(Form, Params)) {
*OffsetPtr += *FixedSize;
return true;
Expand Down Expand Up @@ -427,7 +427,8 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
OS << "<invalid dwarf unit>";
break;
}
Optional<object::SectionedAddress> A = U->getAddrOffsetSectionItem(UValue);
std::optional<object::SectionedAddress> A =
U->getAddrOffsetSectionItem(UValue);
if (!A || DumpOpts.Verbose)
AddrOS << format("indexed (%8.8x) address = ", (uint32_t)UValue);
if (A)
Expand All @@ -443,7 +444,8 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
}
uint32_t Index = UValue >> 32;
uint32_t Offset = UValue & 0xffffffff;
Optional<object::SectionedAddress> A = U->getAddrOffsetSectionItem(Index);
std::optional<object::SectionedAddress> A =
U->getAddrOffsetSectionItem(Index);
if (!A || DumpOpts.Verbose)
AddrOS << format("indexed (%8.8x) + 0x%x address = ", Index, Offset);
if (A) {
Expand Down Expand Up @@ -666,13 +668,13 @@ Expected<const char *> DWARFFormValue::getAsCString() const {
inconvertibleErrorCode());
}

Optional<uint64_t> DWARFFormValue::getAsAddress() const {
std::optional<uint64_t> DWARFFormValue::getAsAddress() const {
if (auto SA = getAsSectionedAddress())
return SA->Address;
return std::nullopt;
}

Optional<object::SectionedAddress>
std::optional<object::SectionedAddress>
DWARFFormValue::getAsSectionedAddress() const {
if (!isFormClass(FC_Address))
return std::nullopt;
Expand All @@ -682,7 +684,8 @@ DWARFFormValue::getAsSectionedAddress() const {
uint32_t Index = AddrOffset ? (Value.uval >> 32) : Value.uval;
if (!U)
return std::nullopt;
Optional<object::SectionedAddress> SA = U->getAddrOffsetSectionItem(Index);
std::optional<object::SectionedAddress> SA =
U->getAddrOffsetSectionItem(Index);
if (!SA)
return std::nullopt;
if (AddrOffset)
Expand All @@ -692,13 +695,14 @@ DWARFFormValue::getAsSectionedAddress() const {
return {{Value.uval, Value.SectionIndex}};
}

Optional<uint64_t> DWARFFormValue::getAsReference() const {
std::optional<uint64_t> DWARFFormValue::getAsReference() const {
if (auto R = getAsRelativeReference())
return R->Unit ? R->Unit->getOffset() + R->Offset : R->Offset;
return std::nullopt;
}

Optional<DWARFFormValue::UnitOffset> DWARFFormValue::getAsRelativeReference() const {
std::optional<DWARFFormValue::UnitOffset>
DWARFFormValue::getAsRelativeReference() const {
if (!isFormClass(FC_Reference))
return std::nullopt;
switch (Form) {
Expand All @@ -719,20 +723,20 @@ Optional<DWARFFormValue::UnitOffset> DWARFFormValue::getAsRelativeReference() co
}
}

Optional<uint64_t> DWARFFormValue::getAsSectionOffset() const {
std::optional<uint64_t> DWARFFormValue::getAsSectionOffset() const {
if (!isFormClass(FC_SectionOffset))
return std::nullopt;
return Value.uval;
}

Optional<uint64_t> DWARFFormValue::getAsUnsignedConstant() const {
std::optional<uint64_t> DWARFFormValue::getAsUnsignedConstant() const {
if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) ||
Form == DW_FORM_sdata)
return std::nullopt;
return Value.uval;
}

Optional<int64_t> DWARFFormValue::getAsSignedConstant() const {
std::optional<int64_t> DWARFFormValue::getAsSignedConstant() const {
if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) ||
(Form == DW_FORM_udata &&
uint64_t(std::numeric_limits<int64_t>::max()) < Value.uval))
Expand All @@ -751,26 +755,26 @@ Optional<int64_t> DWARFFormValue::getAsSignedConstant() const {
}
}

Optional<ArrayRef<uint8_t>> DWARFFormValue::getAsBlock() const {
std::optional<ArrayRef<uint8_t>> DWARFFormValue::getAsBlock() const {
if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc) &&
Form != DW_FORM_data16)
return std::nullopt;
return makeArrayRef(Value.data, Value.uval);
}

Optional<uint64_t> DWARFFormValue::getAsCStringOffset() const {
std::optional<uint64_t> DWARFFormValue::getAsCStringOffset() const {
if (!isFormClass(FC_String) && Form == DW_FORM_string)
return std::nullopt;
return Value.uval;
}

Optional<uint64_t> DWARFFormValue::getAsReferenceUVal() const {
std::optional<uint64_t> DWARFFormValue::getAsReferenceUVal() const {
if (!isFormClass(FC_Reference))
return std::nullopt;
return Value.uval;
}

Optional<std::string>
std::optional<std::string>
DWARFFormValue::getAsFile(DILineInfoSpecifier::FileLineInfoKind Kind) const {
if (U == nullptr || !isFormClass(FC_Constant))
return std::nullopt;
Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ void DWARFTypePrinter::appendArrayType(const DWARFDie &D) {
for (const DWARFDie &C : D.children()) {
if (C.getTag() != DW_TAG_subrange_type)
continue;
Optional<uint64_t> LB;
Optional<uint64_t> Count;
Optional<uint64_t> UB;
Optional<unsigned> DefaultLB;
if (Optional<DWARFFormValue> L = C.find(DW_AT_lower_bound))
std::optional<uint64_t> LB;
std::optional<uint64_t> Count;
std::optional<uint64_t> UB;
std::optional<unsigned> DefaultLB;
if (std::optional<DWARFFormValue> L = C.find(DW_AT_lower_bound))
LB = L->getAsUnsignedConstant();
if (Optional<DWARFFormValue> CountV = C.find(DW_AT_count))
if (std::optional<DWARFFormValue> CountV = C.find(DW_AT_count))
Count = CountV->getAsUnsignedConstant();
if (Optional<DWARFFormValue> UpperV = C.find(DW_AT_upper_bound))
if (std::optional<DWARFFormValue> UpperV = C.find(DW_AT_upper_bound))
UB = UpperV->getAsUnsignedConstant();
if (Optional<DWARFFormValue> LV =
if (std::optional<DWARFFormValue> LV =
D.getDwarfUnit()->getUnitDIE().find(DW_AT_language))
if (Optional<uint64_t> LC = LV->getAsUnsignedConstant())
if (std::optional<uint64_t> LC = LV->getAsUnsignedConstant())
if ((DefaultLB =
LanguageLowerBound(static_cast<dwarf::SourceLanguage>(*LC))))
if (LB && *LB == *DefaultLB)
Expand Down
34 changes: 18 additions & 16 deletions llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ DWARFDataExtractor DWARFUnit::getDebugInfoExtractor() const {
getAddressByteSize());
}

Optional<object::SectionedAddress>
std::optional<object::SectionedAddress>
DWARFUnit::getAddrOffsetSectionItem(uint32_t Index) const {
if (!AddrOffsetSectionBase) {
auto R = Context.info_section_units();
Expand Down Expand Up @@ -499,7 +499,8 @@ Error DWARFUnit::tryExtractDIEsIfNeeded(bool CUDieOnly) {
return Error::success();

DWARFDie UnitDie(this, &DieArray[0]);
if (Optional<uint64_t> DWOId = toUnsigned(UnitDie.find(DW_AT_GNU_dwo_id)))
if (std::optional<uint64_t> DWOId =
toUnsigned(UnitDie.find(DW_AT_GNU_dwo_id)))
Header.setDWOId(*DWOId);
if (!IsDWO) {
assert(AddrOffsetSectionBase == std::nullopt);
Expand Down Expand Up @@ -828,7 +829,7 @@ void DWARFUnit::updateVariableDieMap(DWARFDie Die) {
// exact address.
uint64_t GVSize = 1;
if (DWARFDie BaseType = Die.getAttributeValueAsReferencedDie(DW_AT_type))
if (Optional<uint64_t> Size = Die.getTypeSize(getAddressByteSize()))
if (std::optional<uint64_t> Size = Die.getTypeSize(getAddressByteSize()))
GVSize = *Size;

if (Address != UINT64_MAX)
Expand Down Expand Up @@ -898,7 +899,7 @@ DWARFUnit::getParentEntry(const DWARFDebugInfoEntry *Die) const {
return nullptr;
assert(Die >= DieArray.data() && Die < DieArray.data() + DieArray.size());

if (Optional<uint32_t> ParentIdx = Die->getParentIdx()) {
if (std::optional<uint32_t> ParentIdx = Die->getParentIdx()) {
assert(*ParentIdx < DieArray.size() &&
"ParentIdx is out of DieArray boundaries");
return getDebugInfoEntry(*ParentIdx);
Expand All @@ -920,7 +921,7 @@ DWARFUnit::getSiblingEntry(const DWARFDebugInfoEntry *Die) const {
return nullptr;
assert(Die >= DieArray.data() && Die < DieArray.data() + DieArray.size());

if (Optional<uint32_t> SiblingIdx = Die->getSiblingIdx()) {
if (std::optional<uint32_t> SiblingIdx = Die->getSiblingIdx()) {
assert(*SiblingIdx < DieArray.size() &&
"SiblingIdx is out of DieArray boundaries");
return &DieArray[*SiblingIdx];
Expand All @@ -942,7 +943,7 @@ DWARFUnit::getPreviousSiblingEntry(const DWARFDebugInfoEntry *Die) const {
return nullptr;
assert(Die >= DieArray.data() && Die < DieArray.data() + DieArray.size());

Optional<uint32_t> ParentIdx = Die->getParentIdx();
std::optional<uint32_t> ParentIdx = Die->getParentIdx();
if (!ParentIdx)
// Die is a root die, there is no previous sibling.
return nullptr;
Expand Down Expand Up @@ -1009,7 +1010,7 @@ DWARFUnit::getLastChildEntry(const DWARFDebugInfoEntry *Die) const {
if (!Die->hasChildren())
return nullptr;

if (Optional<uint32_t> SiblingIdx = Die->getSiblingIdx()) {
if (std::optional<uint32_t> SiblingIdx = Die->getSiblingIdx()) {
assert(*SiblingIdx < DieArray.size() &&
"SiblingIdx is out of DieArray boundaries");
assert(DieArray[*SiblingIdx - 1].getTag() == dwarf::DW_TAG_null &&
Expand Down Expand Up @@ -1044,12 +1045,13 @@ const DWARFAbbreviationDeclarationSet *DWARFUnit::getAbbreviations() const {
return Abbrevs;
}

llvm::Optional<object::SectionedAddress> DWARFUnit::getBaseAddress() {
std::optional<object::SectionedAddress> DWARFUnit::getBaseAddress() {
if (BaseAddr)
return BaseAddr;

DWARFDie UnitDie = getUnitDIE();
Optional<DWARFFormValue> PC = UnitDie.find({DW_AT_low_pc, DW_AT_entry_pc});
std::optional<DWARFFormValue> PC =
UnitDie.find({DW_AT_low_pc, DW_AT_entry_pc});
BaseAddr = toSectionedAddress(PC);
return BaseAddr;
}
Expand Down Expand Up @@ -1133,7 +1135,7 @@ parseDWARFStringOffsetsTableHeader(DWARFDataExtractor &DA,
return Desc.validateContributionSize(DA);
}

Expected<Optional<StrOffsetsContributionDescriptor>>
Expected<std::optional<StrOffsetsContributionDescriptor>>
DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor &DA) {
assert(!IsDWO);
auto OptOffset = toSectionOffset(getUnitDIE().find(DW_AT_str_offsets_base));
Expand All @@ -1146,8 +1148,8 @@ DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor &DA) {
return *DescOrError;
}

Expected<Optional<StrOffsetsContributionDescriptor>>
DWARFUnit::determineStringOffsetsTableContributionDWO(DWARFDataExtractor & DA) {
Expected<std::optional<StrOffsetsContributionDescriptor>>
DWARFUnit::determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA) {
assert(IsDWO);
uint64_t Offset = 0;
auto IndexEntry = Header.getIndexEntry();
Expand Down Expand Up @@ -1183,19 +1185,19 @@ DWARFUnit::determineStringOffsetsTableContributionDWO(DWARFDataExtractor & DA) {
return *DescOrError;
}

Optional<uint64_t> DWARFUnit::getRnglistOffset(uint32_t Index) {
std::optional<uint64_t> DWARFUnit::getRnglistOffset(uint32_t Index) {
DataExtractor RangesData(RangeSection->Data, IsLittleEndian,
getAddressByteSize());
DWARFDataExtractor RangesDA(Context.getDWARFObj(), *RangeSection,
IsLittleEndian, 0);
if (Optional<uint64_t> Off = llvm::DWARFListTableHeader::getOffsetEntry(
if (std::optional<uint64_t> Off = llvm::DWARFListTableHeader::getOffsetEntry(
RangesData, RangeSectionBase, getFormat(), Index))
return *Off + RangeSectionBase;
return std::nullopt;
}

Optional<uint64_t> DWARFUnit::getLoclistOffset(uint32_t Index) {
if (Optional<uint64_t> Off = llvm::DWARFListTableHeader::getOffsetEntry(
std::optional<uint64_t> DWARFUnit::getLoclistOffset(uint32_t Index) {
if (std::optional<uint64_t> Off = llvm::DWARFListTableHeader::getOffsetEntry(
LocTable->getData(), LocSectionBase, getFormat(), Index))
return *Off + LocSectionBase;
return std::nullopt;
Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace llvm {
class DWARFDebugInfoEntry;
}

Optional<DWARFAddressRange>
std::optional<DWARFAddressRange>
DWARFVerifier::DieRangeInfo::insert(const DWARFAddressRange &R) {
auto Begin = Ranges.begin();
auto End = Ranges.end();
Expand Down Expand Up @@ -284,11 +284,10 @@ unsigned DWARFVerifier::verifyDebugInfoCallSite(const DWARFDie &Die) {
return 1;
}

Optional<DWARFFormValue> CallAttr =
Curr.find({DW_AT_call_all_calls, DW_AT_call_all_source_calls,
DW_AT_call_all_tail_calls, DW_AT_GNU_all_call_sites,
DW_AT_GNU_all_source_call_sites,
DW_AT_GNU_all_tail_call_sites});
std::optional<DWARFFormValue> CallAttr = Curr.find(
{DW_AT_call_all_calls, DW_AT_call_all_source_calls,
DW_AT_call_all_tail_calls, DW_AT_GNU_all_call_sites,
DW_AT_GNU_all_source_call_sites, DW_AT_GNU_all_tail_call_sites});
if (!CallAttr) {
error() << "Subprogram with call site entry has no DW_AT_call attribute:";
Curr.dump(OS);
Expand Down Expand Up @@ -679,7 +678,8 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
if (LT) {
if (!LT->hasFileAtIndex(*FileIdx)) {
bool IsZeroIndexed = LT->Prologue.getVersion() >= 5;
if (Optional<uint64_t> LastFileIdx = LT->getLastValidFileIndex()) {
if (std::optional<uint64_t> LastFileIdx =
LT->getLastValidFileIndex()) {
ReportError("DIE has " + AttributeString(Attr) +
" with an invalid file index " +
llvm::formatv("{0}", *FileIdx) +
Expand Down Expand Up @@ -732,7 +732,7 @@ unsigned DWARFVerifier::verifyDebugInfoForm(const DWARFDie &Die,
case DW_FORM_ref8:
case DW_FORM_ref_udata: {
// Verify all CU relative references are valid CU offsets.
Optional<uint64_t> RefVal = AttrValue.Value.getAsReference();
std::optional<uint64_t> RefVal = AttrValue.Value.getAsReference();
assert(RefVal);
if (RefVal) {
auto CUSize = DieCU->getNextUnitOffset() - DieCU->getOffset();
Expand All @@ -756,7 +756,7 @@ unsigned DWARFVerifier::verifyDebugInfoForm(const DWARFDie &Die,
case DW_FORM_ref_addr: {
// Verify all absolute DIE references have valid offsets in the
// .debug_info section.
Optional<uint64_t> RefVal = AttrValue.Value.getAsReference();
std::optional<uint64_t> RefVal = AttrValue.Value.getAsReference();
assert(RefVal);
if (RefVal) {
if (*RefVal >= DieCU->getInfoSection().Data.size()) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ Error DwarfTransformer::convert(uint32_t NumThreads) {
size_t NumBefore = Gsym.getNumFunctionInfos();
auto getDie = [&](DWARFUnit &DwarfUnit) -> DWARFDie {
DWARFDie ReturnDie = DwarfUnit.getUnitDIE(false);
if (llvm::Optional<uint64_t> DWOId = DwarfUnit.getDWOId()) {
if (std::optional<uint64_t> DWOId = DwarfUnit.getDWOId()) {
DWARFUnit *DWOCU = DwarfUnit.getNonSkeletonUnitDIE(false).getDwarfUnit();
if (!DWOCU->isDWOUnit()) {
std::string DWOName = dwarf::toString(
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/GSYM/FunctionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ llvm::Expected<LookupResult> FunctionInfo::lookup(DataExtractor &Data,
return LR;
}

Optional<FileEntry> LineEntryFile = GR.getFile(LineEntry->File);
std::optional<FileEntry> LineEntryFile = GR.getFile(LineEntry->File);
if (!LineEntryFile)
return createStringError(std::errc::invalid_argument,
"failed to extract file[%" PRIu32 "]",
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/DebugInfo/GSYM/GsymReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const Header &GsymReader::getHeader() const {
return *Hdr;
}

Optional<uint64_t> GsymReader::getAddress(size_t Index) const {
std::optional<uint64_t> GsymReader::getAddress(size_t Index) const {
switch (Hdr->AddrOffSize) {
case 1: return addressForIndex<uint8_t>(Index);
case 2: return addressForIndex<uint16_t>(Index);
Expand All @@ -216,7 +216,7 @@ Optional<uint64_t> GsymReader::getAddress(size_t Index) const {
return std::nullopt;
}

Optional<uint64_t> GsymReader::getAddressInfoOffset(size_t Index) const {
std::optional<uint64_t> GsymReader::getAddressInfoOffset(size_t Index) const {
const auto NumAddrInfoOffsets = AddrInfoOffsets.size();
if (Index < NumAddrInfoOffsets)
return AddrInfoOffsets[Index];
Expand All @@ -227,7 +227,7 @@ Expected<uint64_t>
GsymReader::getAddressIndex(const uint64_t Addr) const {
if (Addr >= Hdr->BaseAddress) {
const uint64_t AddrOffset = Addr - Hdr->BaseAddress;
Optional<uint64_t> AddrOffsetIndex;
std::optional<uint64_t> AddrOffsetIndex;
switch (Hdr->AddrOffSize) {
case 1:
AddrOffsetIndex = getAddressOffsetIndex<uint8_t>(AddrOffset);
Expand Down Expand Up @@ -262,7 +262,7 @@ llvm::Expected<FunctionInfo> GsymReader::getFunctionInfo(uint64_t Addr) const {
assert(*AddressIndex < AddrInfoOffsets.size());
auto AddrInfoOffset = AddrInfoOffsets[*AddressIndex];
DataExtractor Data(MemBuffer->getBuffer().substr(AddrInfoOffset), Endian, 4);
if (Optional<uint64_t> OptAddr = getAddress(*AddressIndex)) {
if (std::optional<uint64_t> OptAddr = getAddress(*AddressIndex)) {
auto ExpectedFI = FunctionInfo::decode(Data, *OptAddr);
if (ExpectedFI) {
if (ExpectedFI->Range.contains(Addr) || ExpectedFI->Range.size() == 0)
Expand All @@ -284,7 +284,7 @@ llvm::Expected<LookupResult> GsymReader::lookup(uint64_t Addr) const {
assert(*AddressIndex < AddrInfoOffsets.size());
auto AddrInfoOffset = AddrInfoOffsets[*AddressIndex];
DataExtractor Data(MemBuffer->getBuffer().substr(AddrInfoOffset), Endian, 4);
if (Optional<uint64_t> OptAddr = getAddress(*AddressIndex))
if (std::optional<uint64_t> OptAddr = getAddress(*AddressIndex))
return FunctionInfo::lookup(Data, *this, *OptAddr, Addr);
return createStringError(std::errc::invalid_argument,
"failed to extract address[%" PRIu64 "]",
Expand Down Expand Up @@ -382,7 +382,7 @@ void GsymReader::dump(raw_ostream &OS, const InlineInfo &II, uint32_t Indent) {
dump(OS, ChildII, Indent + 2);
}

void GsymReader::dump(raw_ostream &OS, Optional<FileEntry> FE) {
void GsymReader::dump(raw_ostream &OS, std::optional<FileEntry> FE) {
if (FE) {
// IF we have the file from index 0, then don't print anything
if (FE->Dir == 0 && FE->Base == 0)
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/DebugInfo/GSYM/InlineInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ static bool getInlineStackHelper(const InlineInfo &II, uint64_t Addr,
return false;
}

llvm::Optional<InlineInfo::InlineArray> InlineInfo::getInlineStack(uint64_t Addr) const {
std::optional<InlineInfo::InlineArray>
InlineInfo::getInlineStack(uint64_t Addr) const {
InlineArray Result;
if (getInlineStackHelper(*this, Addr, Result))
return Result;
Expand Down Expand Up @@ -134,7 +135,7 @@ static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset,
Done = lookup(GR, Data, Offset, ChildBaseAddr, Addr, SrcLocs, Err);
}

Optional<FileEntry> CallFile = GR.getFile(Inline.CallFile);
std::optional<FileEntry> CallFile = GR.getFile(Inline.CallFile);
if (!CallFile) {
Err = createStringError(std::errc::invalid_argument,
"failed to extract file[%" PRIu32 "]",
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ void LVELFReader::processOneAttribute(const DWARFDie &Die, LVOffset *OffsetPtr,
// For toolchains that support the removal of unused code, the linker
// marks functions that have been removed, by setting the value for the
// low_pc to the max address.
if (Optional<uint64_t> Value = FormValue.getAsAddress()) {
if (std::optional<uint64_t> Value = FormValue.getAsAddress()) {
CurrentLowPC = Value.value();
} else {
uint64_t UValue = FormValue.getRawUValue();
Expand All @@ -424,10 +424,10 @@ void LVELFReader::processOneAttribute(const DWARFDie &Die, LVOffset *OffsetPtr,
case dwarf::DW_AT_high_pc:
if (options().getGeneralCollectRanges()) {
FoundHighPC = true;
if (Optional<uint64_t> Address = FormValue.getAsAddress())
if (std::optional<uint64_t> Address = FormValue.getAsAddress())
// High PC is an address.
CurrentHighPC = *Address;
if (Optional<uint64_t> Offset = FormValue.getAsUnsignedConstant())
if (std::optional<uint64_t> Offset = FormValue.getAsUnsignedConstant())
// High PC is an offset from LowPC.
CurrentHighPC = CurrentLowPC + *Offset;
// Store the real upper limit for the address range.
Expand Down Expand Up @@ -628,7 +628,7 @@ LVScope *LVELFReader::processOneDie(const DWARFDie &InputDIE, LVScope *Parent,
!CurrentScope->getLinkageNameIndex() &&
CurrentScope->getHasReferenceSpecification()) {
// Get the linkage name in order to search for a possible comdat.
Optional<DWARFFormValue> LinkageDIE =
std::optional<DWARFFormValue> LinkageDIE =
DIE.findRecursively(dwarf::DW_AT_linkage_name);
if (LinkageDIE.has_value()) {
StringRef Name(dwarf::toStringRef(LinkageDIE));
Expand Down Expand Up @@ -899,7 +899,7 @@ Error LVELFReader::createScopes() {
DWARFDie UnitDie = CU->getUnitDIE();
SmallString<16> DWOAlternativeLocation;
if (UnitDie) {
Optional<const char *> DWOFileName =
std::optional<const char *> DWOFileName =
CU->getVersion() >= 5
? dwarf::toString(UnitDie.find(dwarf::DW_AT_dwo_name))
: dwarf::toString(UnitDie.find(dwarf::DW_AT_GNU_dwo_name));
Expand Down Expand Up @@ -1002,13 +1002,13 @@ void LVELFReader::processLocationList(dwarf::Attribute Attr,
FormValue.isFormClass(DWARFFormValue::FC_SectionOffset)) {
uint64_t Offset = *FormValue.getAsSectionOffset();
if (FormValue.getForm() == dwarf::DW_FORM_loclistx) {
Optional<uint64_t> LoclistOffset = U->getLoclistOffset(Offset);
std::optional<uint64_t> LoclistOffset = U->getLoclistOffset(Offset);
if (!LoclistOffset)
return;
Offset = *LoclistOffset;
}
uint64_t BaseAddr = 0;
if (Optional<SectionedAddress> BA = U->getBaseAddress())
if (std::optional<SectionedAddress> BA = U->getBaseAddress())
BaseAddr = BA->Address;
LVAddress LowPC = 0;
LVAddress HighPC = 0;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/PDB/DIA/DIADataStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ std::string DIADataStream::getName() const {
return invokeBstrMethod(*StreamData, &IDiaEnumDebugStreamData::get_name);
}

llvm::Optional<DIADataStream::RecordType>
std::optional<DIADataStream::RecordType>
DIADataStream::getItemAtIndex(uint32_t Index) const {
RecordType Record;
DWORD RecordSize = 0;
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Error DbiStreamBuilder::addDbgStream(pdb::DbgHeaderType Type,
assert(Type != DbgHeaderType::NewFPO &&
"NewFPO data should be written via addFrameData()!");

DbgStreams[(int)Type].emplace();
DbgStreams[(int)Type] = DebugStream{};
DbgStreams[(int)Type]->Size = Data.size();
DbgStreams[(int)Type]->WriteFn = [Data](BinaryStreamWriter &Writer) {
return Writer.writeArray(Data);
Expand Down Expand Up @@ -286,7 +286,7 @@ Error DbiStreamBuilder::finalize() {

Error DbiStreamBuilder::finalizeMsfLayout() {
if (NewFpoData) {
DbgStreams[(int)DbgHeaderType::NewFPO].emplace();
DbgStreams[(int)DbgHeaderType::NewFPO] = DebugStream{};
DbgStreams[(int)DbgHeaderType::NewFPO]->Size =
NewFpoData->calculateSerializedSize();
DbgStreams[(int)DbgHeaderType::NewFPO]->WriteFn =
Expand All @@ -296,7 +296,7 @@ Error DbiStreamBuilder::finalizeMsfLayout() {
}

if (!OldFpoData.empty()) {
DbgStreams[(int)DbgHeaderType::FPO].emplace();
DbgStreams[(int)DbgHeaderType::FPO] = DebugStream{};
DbgStreams[(int)DbgHeaderType::FPO]->Size =
sizeof(object::FpoData) * OldFpoData.size();
DbgStreams[(int)DbgHeaderType::FPO]->WriteFn =
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/PDB/Native/NativeEnumTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ NativeEnumTypes::NativeEnumTypes(NativeSession &PDBSession,
LazyRandomTypeCollection &Types,
std::vector<codeview::TypeLeafKind> Kinds)
: Index(0), Session(PDBSession) {
Optional<TypeIndex> TI = Types.getFirst();
std::optional<TypeIndex> TI = Types.getFirst();
while (TI) {
CVType CVT = Types.getType(*TI);
TypeLeafKind K = CVT.kind();
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/DebugInfo/PDB/Native/NativeInlineSiteSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void NativeInlineSiteSymbol::dump(raw_ostream &OS, int Indent,
dumpSymbolField(OS, "name", getName(), Indent);
}

static Optional<InlineeSourceLine>
static std::optional<InlineeSourceLine>
findInlineeByTypeIndex(TypeIndex Id, ModuleDebugStreamRef &ModS) {
for (const auto &SS : ModS.getSubsectionsArray()) {
if (SS.kind() != DebugSubsectionKind::InlineeLines)
Expand Down Expand Up @@ -104,11 +104,11 @@ void NativeInlineSiteSymbol::getLineOffset(uint32_t OffsetInFunc,
LineOffset = 0;
FileOffset = 0;
uint32_t CodeOffset = 0;
Optional<uint32_t> CodeOffsetBase;
Optional<uint32_t> CodeOffsetEnd;
Optional<int32_t> CurLineOffset;
Optional<int32_t> NextLineOffset;
Optional<uint32_t> NextFileOffset;
std::optional<uint32_t> CodeOffsetBase;
std::optional<uint32_t> CodeOffsetEnd;
std::optional<int32_t> CurLineOffset;
std::optional<int32_t> NextLineOffset;
std::optional<uint32_t> NextFileOffset;
auto UpdateCodeOffset = [&](uint32_t Delta) {
if (!CodeOffsetBase)
CodeOffsetBase = CodeOffset;
Expand Down Expand Up @@ -209,7 +209,7 @@ NativeInlineSiteSymbol::findInlineeLinesByVA(uint64_t VA,
getLineOffset(VA - ParentAddr, SrcLineOffset, SrcFileOffset);

// Get line info from inlinee line table.
Optional<InlineeSourceLine> Inlinee =
std::optional<InlineeSourceLine> Inlinee =
findInlineeByTypeIndex(Sym.Inlinee, ModS.get());

if (!Inlinee)
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ Error PDBFileBuilder::commit(StringRef Filename, codeview::GUID *Guid) {
} else {
H->Age = Info->getAge();
H->Guid = Info->getGuid();
Optional<uint32_t> Sig = Info->getSignature();
std::optional<uint32_t> Sig = Info->getSignature();
H->Signature = Sig ? *Sig : time(nullptr);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void TpiStreamBuilder::updateTypeIndexOffsets(ArrayRef<uint16_t> Sizes) {
}

void TpiStreamBuilder::addTypeRecord(ArrayRef<uint8_t> Record,
Optional<uint32_t> Hash) {
std::optional<uint32_t> Hash) {
assert(((Record.size() & 3) == 0) &&
"The type record's size is not a multiple of 4 bytes which will "
"cause misalignment in the output TPI stream!");
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace symbolize {
class SourceCode {
std::unique_ptr<MemoryBuffer> MemBuf;

Optional<StringRef> load(StringRef FileName,
const Optional<StringRef> &EmbeddedSource) {
std::optional<StringRef>
load(StringRef FileName, const std::optional<StringRef> &EmbeddedSource) {
if (Lines <= 0)
return std::nullopt;

Expand All @@ -48,7 +48,7 @@ class SourceCode {
}
}

Optional<StringRef> pruneSource(const Optional<StringRef> &Source) {
std::optional<StringRef> pruneSource(const std::optional<StringRef> &Source) {
if (!Source)
return std::nullopt;
size_t FirstLinePos = StringRef::npos, Pos = 0;
Expand All @@ -71,11 +71,11 @@ class SourceCode {
const int Lines;
const int64_t FirstLine;
const int64_t LastLine;
const Optional<StringRef> PrunedSource;
const std::optional<StringRef> PrunedSource;

SourceCode(
StringRef FileName, int64_t Line, int Lines,
const Optional<StringRef> &EmbeddedSource = Optional<StringRef>())
SourceCode(StringRef FileName, int64_t Line, int Lines,
const std::optional<StringRef> &EmbeddedSource =
std::optional<StringRef>())
: Line(Line), Lines(Lines),
FirstLine(std::max(static_cast<int64_t>(1), Line - Lines / 2)),
LastLine(FirstLine + Lines - 1),
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/DebugInfo/Symbolize/Markup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void MarkupParser::parseLine(StringRef Line) {
this->Line = Line;
}

Optional<MarkupNode> MarkupParser::nextNode() {
std::optional<MarkupNode> MarkupParser::nextNode() {
// Pull something out of the buffer if possible.
if (!Buffer.empty()) {
if (NextIdx < Buffer.size())
Expand All @@ -57,7 +57,7 @@ Optional<MarkupNode> MarkupParser::nextNode() {
return std::nullopt;

if (!InProgressMultiline.empty()) {
if (Optional<StringRef> MultilineEnd = parseMultiLineEnd(Line)) {
if (std::optional<StringRef> MultilineEnd = parseMultiLineEnd(Line)) {
llvm::append_range(InProgressMultiline, *MultilineEnd);
assert(FinishedMultiline.empty() &&
"At most one multi-line element can be finished at a time.");
Expand All @@ -74,7 +74,7 @@ Optional<MarkupNode> MarkupParser::nextNode() {
}

// Find the first valid markup element, if any.
if (Optional<MarkupNode> Element = parseElement(Line)) {
if (std::optional<MarkupNode> Element = parseElement(Line)) {
parseTextOutsideMarkup(takeTo(Line, Element->Text.begin()));
Buffer.push_back(std::move(*Element));
advanceTo(Line, Element->Text.end());
Expand All @@ -83,7 +83,7 @@ Optional<MarkupNode> MarkupParser::nextNode() {

// Since there were no valid elements remaining, see if the line opens a
// multi-line element.
if (Optional<StringRef> MultilineBegin = parseMultiLineBegin(Line)) {
if (std::optional<StringRef> MultilineBegin = parseMultiLineBegin(Line)) {
// Emit any text before the element.
parseTextOutsideMarkup(takeTo(Line, MultilineBegin->begin()));

Expand Down Expand Up @@ -111,7 +111,7 @@ void MarkupParser::flush() {

// Finds and returns the next valid markup element in the given line. Returns
// None if the line contains no valid elements.
Optional<MarkupNode> MarkupParser::parseElement(StringRef Line) {
std::optional<MarkupNode> MarkupParser::parseElement(StringRef Line) {
while (true) {
// Find next element using begin and end markers.
size_t BeginPos = Line.find("{{{");
Expand Down Expand Up @@ -169,7 +169,7 @@ void MarkupParser::parseTextOutsideMarkup(StringRef Text) {

// Given that a line doesn't contain any valid markup, see if it ends with the
// start of a multi-line element. If so, returns the beginning.
Optional<StringRef> MarkupParser::parseMultiLineBegin(StringRef Line) {
std::optional<StringRef> MarkupParser::parseMultiLineBegin(StringRef Line) {
// A multi-line begin marker must be the last one on the line.
size_t BeginPos = Line.rfind("{{{");
if (BeginPos == StringRef::npos)
Expand All @@ -194,7 +194,7 @@ Optional<StringRef> MarkupParser::parseMultiLineBegin(StringRef Line) {

// See if the line begins with the ending of an in-progress multi-line element.
// If so, return the ending.
Optional<StringRef> MarkupParser::parseMultiLineEnd(StringRef Line) {
std::optional<StringRef> MarkupParser::parseMultiLineEnd(StringRef Line) {
size_t EndPos = Line.find("}}}");
if (EndPos == StringRef::npos)
return std::nullopt;
Expand Down
46 changes: 24 additions & 22 deletions llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using namespace llvm;
using namespace llvm::symbolize;

MarkupFilter::MarkupFilter(raw_ostream &OS, LLVMSymbolizer &Symbolizer,
Optional<bool> ColorsEnabled)
std::optional<bool> ColorsEnabled)
: OS(OS), Symbolizer(Symbolizer),
ColorsEnabled(
ColorsEnabled.value_or(WithColor::defaultAutoDetectFunction()(OS))) {}
Expand All @@ -51,7 +51,7 @@ void MarkupFilter::filter(StringRef Line) {
// See if the line is a contextual (i.e. contains a contextual element).
// In this case, anything after the contextual element is elided, or the whole
// line may be elided.
while (Optional<MarkupNode> Node = Parser.nextNode()) {
while (std::optional<MarkupNode> Node = Parser.nextNode()) {
// If this was a contextual line, then summarily stop processing.
if (tryContextualElement(*Node, DeferredNodes))
return;
Expand All @@ -67,7 +67,7 @@ void MarkupFilter::filter(StringRef Line) {

void MarkupFilter::finish() {
Parser.flush();
while (Optional<MarkupNode> Node = Parser.nextNode())
while (std::optional<MarkupNode> Node = Parser.nextNode())
filterNode(*Node);
endAnyModuleInfoLine();
resetColor();
Expand Down Expand Up @@ -96,7 +96,7 @@ bool MarkupFilter::tryMMap(const MarkupNode &Node,
const SmallVector<MarkupNode> &DeferredNodes) {
if (Node.Tag != "mmap")
return false;
Optional<MMap> ParsedMMap = parseMMap(Node);
std::optional<MMap> ParsedMMap = parseMMap(Node);
if (!ParsedMMap)
return true;

Expand Down Expand Up @@ -148,7 +148,7 @@ bool MarkupFilter::tryModule(const MarkupNode &Node,
const SmallVector<MarkupNode> &DeferredNodes) {
if (Node.Tag != "module")
return false;
Optional<Module> ParsedModule = parseModule(Node);
std::optional<Module> ParsedModule = parseModule(Node);
if (!ParsedModule)
return true;

Expand Down Expand Up @@ -243,15 +243,15 @@ bool MarkupFilter::tryPC(const MarkupNode &Node) {
if (!checkNumFieldsAtMost(Node, 2))
return true;

Optional<uint64_t> Addr = parseAddr(Node.Fields[0]);
std::optional<uint64_t> Addr = parseAddr(Node.Fields[0]);
if (!Addr)
return true;

// PC addresses that aren't part of a backtrace are assumed to be precise code
// locations.
PCType Type = PCType::PreciseCode;
if (Node.Fields.size() == 2) {
Optional<PCType> ParsedType = parsePCType(Node.Fields[1]);
std::optional<PCType> ParsedType = parsePCType(Node.Fields[1]);
if (!ParsedType)
return true;
Type = *ParsedType;
Expand Down Expand Up @@ -297,18 +297,18 @@ bool MarkupFilter::tryBackTrace(const MarkupNode &Node) {
if (!checkNumFieldsAtMost(Node, 3))
return true;

Optional<uint64_t> FrameNumber = parseFrameNumber(Node.Fields[0]);
std::optional<uint64_t> FrameNumber = parseFrameNumber(Node.Fields[0]);
if (!FrameNumber)
return true;

Optional<uint64_t> Addr = parseAddr(Node.Fields[1]);
std::optional<uint64_t> Addr = parseAddr(Node.Fields[1]);
if (!Addr)
return true;

// Backtrace addresses are assumed to be return addresses by default.
PCType Type = PCType::ReturnAddress;
if (Node.Fields.size() == 3) {
Optional<PCType> ParsedType = parsePCType(Node.Fields[2]);
std::optional<PCType> ParsedType = parsePCType(Node.Fields[2]);
if (!ParsedType)
return true;
Type = *ParsedType;
Expand Down Expand Up @@ -375,7 +375,7 @@ bool MarkupFilter::tryData(const MarkupNode &Node) {
return false;
if (!checkNumFields(Node, 1))
return true;
Optional<uint64_t> Addr = parseAddr(Node.Fields[0]);
std::optional<uint64_t> Addr = parseAddr(Node.Fields[0]);
if (!Addr)
return true;

Expand Down Expand Up @@ -499,7 +499,7 @@ void MarkupFilter::printValue(Twine Value) {
return std::nullopt; \
TYPE NAME = std::move(*NAME##Opt)

Optional<MarkupFilter::Module>
std::optional<MarkupFilter::Module>
MarkupFilter::parseModule(const MarkupNode &Element) const {
if (!checkNumFieldsAtLeast(Element, 3))
return std::nullopt;
Expand All @@ -518,7 +518,7 @@ MarkupFilter::parseModule(const MarkupNode &Element) const {
return Module{ID, Name.str(), std::move(BuildID)};
}

Optional<MarkupFilter::MMap>
std::optional<MarkupFilter::MMap>
MarkupFilter::parseMMap(const MarkupNode &Element) const {
if (!checkNumFieldsAtLeast(Element, 3))
return std::nullopt;
Expand Down Expand Up @@ -547,7 +547,7 @@ MarkupFilter::parseMMap(const MarkupNode &Element) const {
}

// Parse an address (%p in the spec).
Optional<uint64_t> MarkupFilter::parseAddr(StringRef Str) const {
std::optional<uint64_t> MarkupFilter::parseAddr(StringRef Str) const {
if (Str.empty()) {
reportTypeError(Str, "address");
return std::nullopt;
Expand All @@ -567,7 +567,7 @@ Optional<uint64_t> MarkupFilter::parseAddr(StringRef Str) const {
}

// Parse a module ID (%i in the spec).
Optional<uint64_t> MarkupFilter::parseModuleID(StringRef Str) const {
std::optional<uint64_t> MarkupFilter::parseModuleID(StringRef Str) const {
uint64_t ID;
if (Str.getAsInteger(0, ID)) {
reportTypeError(Str, "module ID");
Expand All @@ -577,7 +577,7 @@ Optional<uint64_t> MarkupFilter::parseModuleID(StringRef Str) const {
}

// Parse a size (%i in the spec).
Optional<uint64_t> MarkupFilter::parseSize(StringRef Str) const {
std::optional<uint64_t> MarkupFilter::parseSize(StringRef Str) const {
uint64_t ID;
if (Str.getAsInteger(0, ID)) {
reportTypeError(Str, "size");
Expand All @@ -587,7 +587,7 @@ Optional<uint64_t> MarkupFilter::parseSize(StringRef Str) const {
}

// Parse a frame number (%i in the spec).
Optional<uint64_t> MarkupFilter::parseFrameNumber(StringRef Str) const {
std::optional<uint64_t> MarkupFilter::parseFrameNumber(StringRef Str) const {
uint64_t ID;
if (Str.getAsInteger(10, ID)) {
reportTypeError(Str, "frame number");
Expand All @@ -597,7 +597,8 @@ Optional<uint64_t> MarkupFilter::parseFrameNumber(StringRef Str) const {
}

// Parse a build ID (%x in the spec).
Optional<SmallVector<uint8_t>> MarkupFilter::parseBuildID(StringRef Str) const {
std::optional<SmallVector<uint8_t>>
MarkupFilter::parseBuildID(StringRef Str) const {
std::string Bytes;
if (Str.empty() || Str.size() % 2 || !tryGetFromHex(Str, Bytes)) {
reportTypeError(Str, "build ID");
Expand All @@ -609,7 +610,7 @@ Optional<SmallVector<uint8_t>> MarkupFilter::parseBuildID(StringRef Str) const {
}

// Parses the mode string for an mmap element.
Optional<std::string> MarkupFilter::parseMode(StringRef Str) const {
std::optional<std::string> MarkupFilter::parseMode(StringRef Str) const {
if (Str.empty()) {
reportTypeError(Str, "mode");
return std::nullopt;
Expand All @@ -634,9 +635,10 @@ Optional<std::string> MarkupFilter::parseMode(StringRef Str) const {
return Str.lower();
}

Optional<MarkupFilter::PCType> MarkupFilter::parsePCType(StringRef Str) const {
Optional<MarkupFilter::PCType> Type =
StringSwitch<Optional<MarkupFilter::PCType>>(Str)
std::optional<MarkupFilter::PCType>
MarkupFilter::parsePCType(StringRef Str) const {
std::optional<MarkupFilter::PCType> Type =
StringSwitch<std::optional<MarkupFilter::PCType>>(Str)
.Case("ra", MarkupFilter::PCType::ReturnAddress)
.Case("pc", MarkupFilter::PCType::PreciseCode)
.Default(std::nullopt);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ProfileData/InstrProfCorrelator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ void DwarfInstrProfCorrelator<IntPtrT>::correlateProfileDataImpl(
if (!isDIEOfProbe(Die))
return;
Optional<const char *> FunctionName;
Optional<uint64_t> CFGHash;
std::optional<uint64_t> CFGHash;
Optional<uint64_t> CounterPtr = getLocation(Die);
auto FnDie = Die.getParent();
auto FunctionPtr = dwarf::toAddress(FnDie.find(dwarf::DW_AT_low_pc));
Optional<uint64_t> NumCounters;
std::optional<uint64_t> NumCounters;
for (const DWARFDie &Child : Die.children()) {
if (Child.getTag() != dwarf::DW_TAG_LLVM_annotation)
continue;
Expand Down
9 changes: 5 additions & 4 deletions llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ bool DwarfLinkerForBinary::AddressManager::isLiveVariable(
const DWARFDie &DIE, CompileUnit::DIEInfo &MyInfo) {
const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();

Optional<uint32_t> LocationIdx =
std::optional<uint32_t> LocationIdx =
Abbrev->findAttributeIndex(dwarf::DW_AT_location);
if (!LocationIdx)
return false;
Expand All @@ -999,7 +999,8 @@ bool DwarfLinkerForBinary::AddressManager::isLiveSubprogram(
const DWARFDie &DIE, CompileUnit::DIEInfo &MyInfo) {
const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();

Optional<uint32_t> LowPcIdx = Abbrev->findAttributeIndex(dwarf::DW_AT_low_pc);
std::optional<uint32_t> LowPcIdx =
Abbrev->findAttributeIndex(dwarf::DW_AT_low_pc);
if (!LowPcIdx)
return false;

Expand All @@ -1015,8 +1016,8 @@ bool DwarfLinkerForBinary::AddressManager::isLiveSubprogram(
}

if (Form == dwarf::DW_FORM_addrx) {
Optional<DWARFFormValue> AddrValue = DIE.find(dwarf::DW_AT_low_pc);
if (Optional<uint64_t> AddrOffsetSectionBase =
std::optional<DWARFFormValue> AddrValue = DIE.find(dwarf::DW_AT_low_pc);
if (std::optional<uint64_t> AddrOffsetSectionBase =
DIE.getDwarfUnit()->getAddrOffsetSectionBase()) {
uint64_t StartOffset = *AddrOffsetSectionBase + AddrValue->getRawUValue();
uint64_t EndOffset =
Expand Down
13 changes: 6 additions & 7 deletions llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ static alias DumpAllAlias("a", desc("Alias for --all"), aliasopt(DumpAll),

// Options for dumping specific sections.
static unsigned DumpType = DIDT_Null;
static std::array<llvm::Optional<uint64_t>, (unsigned)DIDT_ID_Count>
DumpOffsets;
static std::array<std::optional<uint64_t>, (unsigned)DIDT_ID_Count> DumpOffsets;
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \
static opt<OPTION> Dump##ENUM_NAME(CMDLINE_NAME, \
desc("Dump the " ELF_NAME " section"), \
Expand Down Expand Up @@ -386,7 +385,7 @@ static void filterByName(const StringSet<> &Names,
static void getDies(DWARFContext &DICtx, const AppleAcceleratorTable &Accel,
StringRef Name, SmallVectorImpl<DWARFDie> &Dies) {
for (const auto &Entry : Accel.equal_range(Name)) {
if (llvm::Optional<uint64_t> Off = Entry.getDIESectionOffset()) {
if (std::optional<uint64_t> Off = Entry.getDIESectionOffset()) {
if (DWARFDie Die = DICtx.getDIEForOffset(*Off))
Dies.push_back(Die);
}
Expand All @@ -395,16 +394,16 @@ static void getDies(DWARFContext &DICtx, const AppleAcceleratorTable &Accel,

static DWARFDie toDie(const DWARFDebugNames::Entry &Entry,
DWARFContext &DICtx) {
llvm::Optional<uint64_t> CUOff = Entry.getCUOffset();
llvm::Optional<uint64_t> Off = Entry.getDIEUnitOffset();
std::optional<uint64_t> CUOff = Entry.getCUOffset();
std::optional<uint64_t> Off = Entry.getDIEUnitOffset();
if (!CUOff || !Off)
return DWARFDie();

DWARFCompileUnit *CU = DICtx.getCompileUnitForOffset(*CUOff);
if (!CU)
return DWARFDie();

if (llvm::Optional<uint64_t> DWOId = CU->getDWOId()) {
if (std::optional<uint64_t> DWOId = CU->getDWOId()) {
// This is a skeleton unit. Look up the DIE in the DWO unit.
CU = DICtx.getDWOCompileUnitForHash(*DWOId);
if (!CU)
Expand Down Expand Up @@ -477,7 +476,7 @@ static bool collectLineTableSources(const DWARFDebugLine::LineTable &LT,
StringRef CompDir,
std::vector<std::string> &Sources) {
bool Result = true;
llvm::Optional<uint64_t> LastIndex = LT.getLastValidFileIndex();
std::optional<uint64_t> LastIndex = LT.getLastValidFileIndex();
for (uint64_t I = LT.hasFileAtIndex(0) ? 0 : 1,
E = LastIndex ? *LastIndex + 1 : 0;
I < E; ++I) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ObjFileAddressMap : public AddressesMap {
DIE.getTag() == dwarf::DW_TAG_label) &&
"Wrong type of input die");

if (Optional<uint64_t> LowPC =
if (std::optional<uint64_t> LowPC =
dwarf::toAddress(DIE.find(dwarf::DW_AT_low_pc))) {
if (!isDeadAddress(*LowPC, DIE.getDwarfUnit()->getVersion(),
Opts.Tombstone,
Expand Down
10 changes: 6 additions & 4 deletions llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ Error DumpOutputStyle::dumpTypeStats() {
StatCollection TypeStats;
LazyRandomTypeCollection &Types =
opts::dump::DumpTypeStats ? File.types() : File.ids();
for (Optional<TypeIndex> TI = Types.getFirst(); TI; TI = Types.getNext(*TI)) {
for (std::optional<TypeIndex> TI = Types.getFirst(); TI;
TI = Types.getNext(*TI)) {
CVType Type = Types.getType(*TI);
TypeStats.update(uint32_t(Type.kind()), Type.length());
}
Expand Down Expand Up @@ -692,7 +693,7 @@ Error DumpOutputStyle::dumpUdtStats() {
Kind = kNoneUdtKind;
else if (UDT.Type.isSimple())
Kind = kSimpleUdtKind;
else if (Optional<CVType> T = TpiTypes.tryGetType(UDT.Type)) {
else if (std::optional<CVType> T = TpiTypes.tryGetType(UDT.Type)) {
Kind = T->kind();
RecordSize = T->length();
} else
Expand Down Expand Up @@ -1250,7 +1251,7 @@ static void dumpPartialTypeStream(LinePrinter &Printer,
if (TI.isSimple()) {
Printer.formatLine("{0} | {1}", fmt_align(I, AlignStyle::Right, Width),
Types.getTypeName(TI));
} else if (Optional<CVType> Type = Types.tryGetType(TI)) {
} else if (std::optional<CVType> Type = Types.tryGetType(TI)) {
if (auto EC = codeview::visitTypeRecord(*Type, TI, V))
Printer.formatLine("An error occurred dumping type record {0}: {1}",
TI, toString(std::move(EC)));
Expand Down Expand Up @@ -1517,7 +1518,8 @@ Error DumpOutputStyle::dumpTypeRefStats() {
size_t TotalBytes = 0;
size_t RefBytes = 0;
auto &Types = File.types();
for (Optional<TypeIndex> TI = Types.getFirst(); TI; TI = Types.getNext(*TI)) {
for (std::optional<TypeIndex> TI = Types.getFirst(); TI;
TI = Types.getNext(*TI)) {
CVType Type = File.types().getType(*TI);
TotalBytes += Type.length();
if (RefTracker->isTypeReferenced(*TI)) {
Expand Down
9 changes: 5 additions & 4 deletions llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ using namespace llvm::codeview;
// just iterate up front to find out.
static uint32_t getNumRecordsInCollection(LazyRandomTypeCollection &Types) {
uint32_t NumTypes = 0;
for (Optional<TypeIndex> TI = Types.getFirst(); TI; TI = Types.getNext(*TI))
for (std::optional<TypeIndex> TI = Types.getFirst(); TI;
TI = Types.getNext(*TI))
++NumTypes;
return NumTypes;
}
Expand Down Expand Up @@ -129,9 +130,9 @@ void TypeReferenceTracker::markReferencedTypes() {
TiRefKind RefKind;
TypeIndex RefTI;
std::tie(RefKind, RefTI) = RefWorklist.pop_back_val();
Optional<CVType> Rec = (Ids && RefKind == TiRefKind::IndexRef)
? Ids->tryGetType(RefTI)
: Types.tryGetType(RefTI);
std::optional<CVType> Rec = (Ids && RefKind == TiRefKind::IndexRef)
? Ids->tryGetType(RefTI)
: Types.tryGetType(RefTI);
if (!Rec)
continue; // FIXME: Report a reference to a non-existant type.

Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-profgen/ProfiledBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ void ProfiledBinary::loadSymbolsFromDWARF(ObjectFile &Obj) {
// Handles DWO sections that can either be in .o, .dwo or .dwp files.
for (const auto &CompilationUnit : DebugContext->compile_units()) {
DWARFUnit *const DwarfUnit = CompilationUnit.get();
if (llvm::Optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
if (std::optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
DWARFUnit *DWOCU = DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit();
if (!DWOCU->isDWOUnit()) {
std::string DWOName = dwarf::toString(
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-readobj/COFFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ void COFFDumper::mergeCodeViewTypes(MergingTypeTableBuilder &CVIDs,
Obj->getFileName());
}
SmallVector<TypeIndex, 128> SourceToDest;
Optional<PCHMergerInfo> PCHInfo;
std::optional<PCHMergerInfo> PCHInfo;
if (GHash) {
std::vector<GloballyHashedType> Hashes =
GloballyHashedType::hashTypes(Types);
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ static FunctionNameKind decideHowToPrintFunctions(const opt::InputArgList &Args,
return IsAddr2Line ? FunctionNameKind::None : FunctionNameKind::LinkageName;
}

static Optional<bool> parseColorArg(const opt::InputArgList &Args) {
static std::optional<bool> parseColorArg(const opt::InputArgList &Args) {
if (Args.hasArg(OPT_color))
return true;
if (const opt::Arg *A = Args.getLastArg(OPT_color_EQ))
return StringSwitch<Optional<bool>>(A->getValue())
return StringSwitch<std::optional<bool>>(A->getValue())
.Case("always", true)
.Case("never", false)
.Case("auto", std::nullopt);
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/BinaryFormat/DwarfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ TEST(DwarfTest, getVirtuality) {
}

TEST(DwarfTest, FixedFormSizes) {
Optional<uint8_t> RefSize;
Optional<uint8_t> AddrSize;
std::optional<uint8_t> RefSize;
std::optional<uint8_t> AddrSize;

// Test 32 bit DWARF version 2 with 4 byte addresses.
FormParams Params_2_4_32 = {2, 4, DWARF32};
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/DebugInfo/DWARF/DWARFDebugFrameTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ TEST(DWARFDebugFrame, RegisterLocations) {
expectDumpResult(Locs, "reg12=[CFA+4], reg13=[CFA+8], reg14=same");

// Verify RegisterLocations::getRegisterLocation() works as expected.
Optional<dwarf::UnwindLocation> OptionalLoc;
std::optional<dwarf::UnwindLocation> OptionalLoc;
OptionalLoc = Locs.getRegisterLocation(0);
EXPECT_FALSE(OptionalLoc.has_value());

Expand Down
26 changes: 13 additions & 13 deletions llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ void TestAllForms() {
//----------------------------------------------------------------------
// Test block forms
//----------------------------------------------------------------------
Optional<DWARFFormValue> FormValue;
std::optional<DWARFFormValue> FormValue;
ArrayRef<uint8_t> ExtractedBlockData;
Optional<ArrayRef<uint8_t>> BlockDataOpt;
std::optional<ArrayRef<uint8_t>> BlockDataOpt;

FormValue = DieDG.find(Attr_DW_FORM_block);
EXPECT_TRUE((bool)FormValue);
Expand Down Expand Up @@ -937,7 +937,7 @@ template <uint16_t Version, class AddrType> void TestAddresses() {
EXPECT_TRUE(DieDG.isValid());

uint64_t LowPC, HighPC, SectionIndex;
Optional<uint64_t> OptU64;
std::optional<uint64_t> OptU64;
// Verify the that our subprogram with no PC value fails appropriately when
// asked for any PC values.
auto SubprogramDieNoPC = DieDG.getFirstChild();
Expand Down Expand Up @@ -1118,14 +1118,14 @@ TEST(DWARFDebugInfo, TestStringOffsets) {
ASSERT_TRUE((bool)Extracted1);
EXPECT_STREQ(String1, *Extracted1);

Optional<DWARFFormValue> Form2 = DieDG.find(Attr2);
std::optional<DWARFFormValue> Form2 = DieDG.find(Attr2);
ASSERT_TRUE((bool)Form2);
EXPECT_EQ(0u, Form2->getRawUValue());
auto Extracted2 = toString(Form2);
ASSERT_TRUE((bool)Extracted2);
EXPECT_STREQ(String2, *Extracted2);

Optional<DWARFFormValue> Form3 = DieDG.find(Attr3);
std::optional<DWARFFormValue> Form3 = DieDG.find(Attr3);
ASSERT_TRUE((bool)Form3);
EXPECT_EQ(1u, Form3->getRawUValue());
auto Extracted3 = toString(Form3);
Expand Down Expand Up @@ -1632,13 +1632,13 @@ TEST(DWARFDebugInfo, TestFindRecurse) {

TEST(DWARFDebugInfo, TestDwarfToFunctions) {
// Test all of the dwarf::toXXX functions that take a
// Optional<DWARFFormValue> and extract the values from it.
// std::optional<DWARFFormValue> and extract the values from it.
uint64_t InvalidU64 = 0xBADBADBADBADBADB;
int64_t InvalidS64 = 0xBADBADBADBADBADB;

// First test that we don't get valid values back when using an optional with
// no value.
Optional<DWARFFormValue> FormValOpt1 = DWARFFormValue();
std::optional<DWARFFormValue> FormValOpt1 = DWARFFormValue();
EXPECT_FALSE(toString(FormValOpt1).has_value());
EXPECT_FALSE(toUnsigned(FormValOpt1).has_value());
EXPECT_FALSE(toReference(FormValOpt1).has_value());
Expand All @@ -1655,7 +1655,7 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) {

// Test successful and unsuccessful address decoding.
uint64_t Address = 0x100000000ULL;
Optional<DWARFFormValue> FormValOpt2 =
std::optional<DWARFFormValue> FormValOpt2 =
DWARFFormValue::createFromUValue(DW_FORM_addr, Address);

EXPECT_FALSE(toString(FormValOpt2).has_value());
Expand All @@ -1674,7 +1674,7 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) {

// Test successful and unsuccessful unsigned constant decoding.
uint64_t UData8 = 0x1020304050607080ULL;
Optional<DWARFFormValue> FormValOpt3 =
std::optional<DWARFFormValue> FormValOpt3 =
DWARFFormValue::createFromUValue(DW_FORM_udata, UData8);

EXPECT_FALSE(toString(FormValOpt3).has_value());
Expand All @@ -1693,7 +1693,7 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) {

// Test successful and unsuccessful reference decoding.
uint32_t RefData = 0x11223344U;
Optional<DWARFFormValue> FormValOpt4 =
std::optional<DWARFFormValue> FormValOpt4 =
DWARFFormValue::createFromUValue(DW_FORM_ref_addr, RefData);

EXPECT_FALSE(toString(FormValOpt4).has_value());
Expand All @@ -1712,7 +1712,7 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) {

// Test successful and unsuccessful signed constant decoding.
int64_t SData8 = 0x1020304050607080ULL;
Optional<DWARFFormValue> FormValOpt5 =
std::optional<DWARFFormValue> FormValOpt5 =
DWARFFormValue::createFromSValue(DW_FORM_udata, SData8);

EXPECT_FALSE(toString(FormValOpt5).has_value());
Expand All @@ -1732,7 +1732,7 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) {
// Test successful and unsuccessful block decoding.
uint8_t Data[] = { 2, 3, 4 };
ArrayRef<uint8_t> Array(Data);
Optional<DWARFFormValue> FormValOpt6 =
std::optional<DWARFFormValue> FormValOpt6 =
DWARFFormValue::createFromBlockValue(DW_FORM_block1, Array);

EXPECT_FALSE(toString(FormValOpt6).has_value());
Expand Down Expand Up @@ -1873,7 +1873,7 @@ TEST(DWARFDebugInfo, TestImplicitConstAbbrevs) {
auto A = it->getAttrByIndex(0);
EXPECT_EQ(A, Attr);

Optional<uint32_t> AttrIndex = it->findAttributeIndex(A);
std::optional<uint32_t> AttrIndex = it->findAttributeIndex(A);
EXPECT_TRUE((bool)AttrIndex);
EXPECT_EQ(*AttrIndex, 0u);
uint64_t OffsetVal =
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ TEST(DWARFListTableHeader, OffsetEntryCount) {
/*ListTypeString=*/"range");
uint64_t Offset = 0;
EXPECT_FALSE(!!Header.extract(Extractor, &Offset));
Optional<uint64_t> Offset0 = Header.getOffsetEntry(Extractor, 0);
std::optional<uint64_t> Offset0 = Header.getOffsetEntry(Extractor, 0);
EXPECT_TRUE(!!Offset0);
EXPECT_EQ(Offset0, uint64_t(4));
Optional<uint64_t> Offset1 = Header.getOffsetEntry(Extractor, 1);
std::optional<uint64_t> Offset1 = Header.getOffsetEntry(Extractor, 1);
EXPECT_FALSE(!!Offset1);
EXPECT_EQ(Header.length(), sizeof(SecData) - 1);
}
Expand Down