diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:04 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:11 +0000 |
commit | e3b557809604d036af6e00c60f012c2025b59a5e (patch) | |
tree | 8a11ba2269a3b669601e2fd41145b174008f4da8 /llvm/lib/DebugInfo/CodeView | |
parent | 08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff) |
Diffstat (limited to 'llvm/lib/DebugInfo/CodeView')
21 files changed, 282 insertions, 160 deletions
diff --git a/llvm/lib/DebugInfo/CodeView/AppendingTypeTableBuilder.cpp b/llvm/lib/DebugInfo/CodeView/AppendingTypeTableBuilder.cpp index 3ab7f722eaee..dc32e8336927 100644 --- a/llvm/lib/DebugInfo/CodeView/AppendingTypeTableBuilder.cpp +++ b/llvm/lib/DebugInfo/CodeView/AppendingTypeTableBuilder.cpp @@ -29,16 +29,16 @@ AppendingTypeTableBuilder::AppendingTypeTableBuilder(BumpPtrAllocator &Storage) AppendingTypeTableBuilder::~AppendingTypeTableBuilder() = default; -Optional<TypeIndex> AppendingTypeTableBuilder::getFirst() { +std::optional<TypeIndex> AppendingTypeTableBuilder::getFirst() { if (empty()) - return None; + return std::nullopt; return TypeIndex(TypeIndex::FirstNonSimpleIndex); } -Optional<TypeIndex> AppendingTypeTableBuilder::getNext(TypeIndex Prev) { +std::optional<TypeIndex> AppendingTypeTableBuilder::getNext(TypeIndex Prev) { if (++Prev == nextTypeIndex()) - return None; + return std::nullopt; return Prev; } diff --git a/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp b/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp index 5da300f710d5..689c643a7006 100644 --- a/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp +++ b/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp @@ -157,7 +157,7 @@ Error CVTypeVisitor::visitTypeStream(CVTypeRange Types) { } Error CVTypeVisitor::visitTypeStream(TypeCollection &Types) { - Optional<TypeIndex> I = Types.getFirst(); + std::optional<TypeIndex> I = Types.getFirst(); while (I) { CVType Type = Types.getType(*I); if (auto EC = visitTypeRecord(Type, *I)) diff --git a/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp b/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp index a66f9af98835..aea672976017 100644 --- a/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp +++ b/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp @@ -17,7 +17,7 @@ using namespace llvm; using namespace llvm::codeview; -Error CodeViewRecordIO::beginRecord(Optional<uint32_t> MaxLength) { +Error CodeViewRecordIO::beginRecord(std::optional<uint32_t> MaxLength) { RecordLimit Limit; Limit.MaxLength = MaxLength; Limit.BeginOffset = getCurrentOffset(); @@ -67,9 +67,9 @@ uint32_t CodeViewRecordIO::maxFieldLength() const { // ever be at most 1 sub-record deep (in a FieldList), but this works for // the general case. uint32_t Offset = getCurrentOffset(); - Optional<uint32_t> Min = Limits.front().bytesRemaining(Offset); - for (auto X : makeArrayRef(Limits).drop_front()) { - Optional<uint32_t> ThisMin = X.bytesRemaining(Offset); + std::optional<uint32_t> Min = Limits.front().bytesRemaining(Offset); + for (auto X : ArrayRef(Limits).drop_front()) { + std::optional<uint32_t> ThisMin = X.bytesRemaining(Offset); if (ThisMin) Min = Min ? std::min(*Min, *ThisMin) : *ThisMin; } diff --git a/llvm/lib/DebugInfo/CodeView/ContinuationRecordBuilder.cpp b/llvm/lib/DebugInfo/CodeView/ContinuationRecordBuilder.cpp index a3dbb3954d5c..0adbdb596218 100644 --- a/llvm/lib/DebugInfo/CodeView/ContinuationRecordBuilder.cpp +++ b/llvm/lib/DebugInfo/CodeView/ContinuationRecordBuilder.cpp @@ -147,7 +147,7 @@ void ContinuationRecordBuilder::insertSegmentEnd(uint32_t Offset) { } CVType ContinuationRecordBuilder::createSegmentRecord( - uint32_t OffBegin, uint32_t OffEnd, Optional<TypeIndex> RefersTo) { + uint32_t OffBegin, uint32_t OffEnd, std::optional<TypeIndex> RefersTo) { assert(OffEnd - OffBegin <= USHRT_MAX); MutableArrayRef<uint8_t> Data = Buffer.data(); @@ -224,11 +224,11 @@ std::vector<CVType> ContinuationRecordBuilder::end(TypeIndex Index) { std::vector<CVType> Types; Types.reserve(SegmentOffsets.size()); - auto SO = makeArrayRef(SegmentOffsets); + ArrayRef SO = SegmentOffsets; uint32_t End = SegmentWriter.getOffset(); - Optional<TypeIndex> RefersTo; + std::optional<TypeIndex> RefersTo; for (uint32_t Offset : reverse(SO)) { Types.push_back(createSegmentRecord(Offset, End, RefersTo)); diff --git a/llvm/lib/DebugInfo/CodeView/DebugChecksumsSubsection.cpp b/llvm/lib/DebugInfo/CodeView/DebugChecksumsSubsection.cpp index 3d28bac00c44..30aa60b065bf 100644 --- a/llvm/lib/DebugInfo/CodeView/DebugChecksumsSubsection.cpp +++ b/llvm/lib/DebugInfo/CodeView/DebugChecksumsSubsection.cpp @@ -71,7 +71,7 @@ void DebugChecksumsSubsection::addChecksum(StringRef FileName, if (!Bytes.empty()) { uint8_t *Copy = Storage.Allocate<uint8_t>(Bytes.size()); ::memcpy(Copy, Bytes.data(), Bytes.size()); - Entry.Checksum = makeArrayRef(Copy, Bytes.size()); + Entry.Checksum = ArrayRef(Copy, Bytes.size()); } Entry.FileNameOffset = Strings.insert(FileName); @@ -99,7 +99,7 @@ Error DebugChecksumsSubsection::commit(BinaryStreamWriter &Writer) const { Header.FileNameOffset = FC.FileNameOffset; if (auto EC = Writer.writeObject(Header)) return EC; - if (auto EC = Writer.writeArray(makeArrayRef(FC.Checksum))) + if (auto EC = Writer.writeArray(ArrayRef(FC.Checksum))) return EC; if (auto EC = Writer.padToAlignment(4)) return EC; diff --git a/llvm/lib/DebugInfo/CodeView/DebugCrossImpSubsection.cpp b/llvm/lib/DebugInfo/CodeView/DebugCrossImpSubsection.cpp index dbadafd3aaf3..e5f82f9c37f4 100644 --- a/llvm/lib/DebugInfo/CodeView/DebugCrossImpSubsection.cpp +++ b/llvm/lib/DebugInfo/CodeView/DebugCrossImpSubsection.cpp @@ -89,7 +89,7 @@ Error DebugCrossModuleImportsSubsection::commit( Imp.Count = Item->getValue().size(); if (auto EC = Writer.writeObject(Imp)) return EC; - if (auto EC = Writer.writeArray(makeArrayRef(Item->getValue()))) + if (auto EC = Writer.writeArray(ArrayRef(Item->getValue()))) return EC; } return Error::success(); diff --git a/llvm/lib/DebugInfo/CodeView/DebugFrameDataSubsection.cpp b/llvm/lib/DebugInfo/CodeView/DebugFrameDataSubsection.cpp index c083c61d1595..bb3a838d3ec0 100644 --- a/llvm/lib/DebugInfo/CodeView/DebugFrameDataSubsection.cpp +++ b/llvm/lib/DebugInfo/CodeView/DebugFrameDataSubsection.cpp @@ -52,7 +52,7 @@ Error DebugFrameDataSubsection::commit(BinaryStreamWriter &Writer) const { llvm::sort(SortedFrames, [](const FrameData &LHS, const FrameData &RHS) { return LHS.RvaStart < RHS.RvaStart; }); - if (auto EC = Writer.writeArray(makeArrayRef(SortedFrames))) + if (auto EC = Writer.writeArray(ArrayRef(SortedFrames))) return EC; return Error::success(); } diff --git a/llvm/lib/DebugInfo/CodeView/DebugInlineeLinesSubsection.cpp b/llvm/lib/DebugInfo/CodeView/DebugInlineeLinesSubsection.cpp index 665511c592f9..620c9e53ad95 100644 --- a/llvm/lib/DebugInfo/CodeView/DebugInlineeLinesSubsection.cpp +++ b/llvm/lib/DebugInfo/CodeView/DebugInlineeLinesSubsection.cpp @@ -98,7 +98,7 @@ Error DebugInlineeLinesSubsection::commit(BinaryStreamWriter &Writer) const { if (auto EC = Writer.writeInteger<uint32_t>(E.ExtraFiles.size())) return EC; - if (auto EC = Writer.writeArray(makeArrayRef(E.ExtraFiles))) + if (auto EC = Writer.writeArray(ArrayRef(E.ExtraFiles))) return EC; } diff --git a/llvm/lib/DebugInfo/CodeView/DebugLinesSubsection.cpp b/llvm/lib/DebugInfo/CodeView/DebugLinesSubsection.cpp index ea16c0a6c671..28098373bf33 100644 --- a/llvm/lib/DebugInfo/CodeView/DebugLinesSubsection.cpp +++ b/llvm/lib/DebugInfo/CodeView/DebugLinesSubsection.cpp @@ -123,11 +123,11 @@ Error DebugLinesSubsection::commit(BinaryStreamWriter &Writer) const { if (auto EC = Writer.writeObject(BlockHeader)) return EC; - if (auto EC = Writer.writeArray(makeArrayRef(B.Lines))) + if (auto EC = Writer.writeArray(ArrayRef(B.Lines))) return EC; if (hasColumnInfo()) { - if (auto EC = Writer.writeArray(makeArrayRef(B.Columns))) + if (auto EC = Writer.writeArray(ArrayRef(B.Columns))) return EC; } } diff --git a/llvm/lib/DebugInfo/CodeView/DebugSymbolRVASubsection.cpp b/llvm/lib/DebugInfo/CodeView/DebugSymbolRVASubsection.cpp index 52328967357b..6fe72e84f4e7 100644 --- a/llvm/lib/DebugInfo/CodeView/DebugSymbolRVASubsection.cpp +++ b/llvm/lib/DebugInfo/CodeView/DebugSymbolRVASubsection.cpp @@ -27,7 +27,7 @@ DebugSymbolRVASubsection::DebugSymbolRVASubsection() : DebugSubsection(DebugSubsectionKind::CoffSymbolRVA) {} Error DebugSymbolRVASubsection::commit(BinaryStreamWriter &Writer) const { - return Writer.writeArray(makeArrayRef(RVAs)); + return Writer.writeArray(ArrayRef(RVAs)); } uint32_t DebugSymbolRVASubsection::calculateSerializedSize() const { diff --git a/llvm/lib/DebugInfo/CodeView/EnumTables.cpp b/llvm/lib/DebugInfo/CodeView/EnumTables.cpp index adf4ae519dae..78a258600696 100644 --- a/llvm/lib/DebugInfo/CodeView/EnumTables.cpp +++ b/llvm/lib/DebugInfo/CodeView/EnumTables.cpp @@ -14,7 +14,7 @@ using namespace llvm; using namespace codeview; #define CV_ENUM_CLASS_ENT(enum_class, enum) \ - { #enum, std::underlying_type < enum_class > ::type(enum_class::enum) } + { #enum, std::underlying_type_t<enum_class>(enum_class::enum) } #define CV_ENUM_ENT(ns, enum) \ { #enum, ns::enum } @@ -437,125 +437,125 @@ namespace llvm { namespace codeview { ArrayRef<EnumEntry<SymbolKind>> getSymbolTypeNames() { - return makeArrayRef(SymbolTypeNames); + return ArrayRef(SymbolTypeNames); } ArrayRef<EnumEntry<TypeLeafKind>> getTypeLeafNames() { - return makeArrayRef(TypeLeafNames); + return ArrayRef(TypeLeafNames); } ArrayRef<EnumEntry<uint16_t>> getRegisterNames(CPUType Cpu) { if (Cpu == CPUType::ARMNT) { - return makeArrayRef(RegisterNames_ARM); + return ArrayRef(RegisterNames_ARM); } else if (Cpu == CPUType::ARM64) { - return makeArrayRef(RegisterNames_ARM64); + return ArrayRef(RegisterNames_ARM64); } - return makeArrayRef(RegisterNames_X86); + return ArrayRef(RegisterNames_X86); } ArrayRef<EnumEntry<uint32_t>> getPublicSymFlagNames() { - return makeArrayRef(PublicSymFlagNames); + return ArrayRef(PublicSymFlagNames); } ArrayRef<EnumEntry<uint8_t>> getProcSymFlagNames() { - return makeArrayRef(ProcSymFlagNames); + return ArrayRef(ProcSymFlagNames); } ArrayRef<EnumEntry<uint16_t>> getLocalFlagNames() { - return makeArrayRef(LocalFlags); + return ArrayRef(LocalFlags); } ArrayRef<EnumEntry<uint8_t>> getFrameCookieKindNames() { - return makeArrayRef(FrameCookieKinds); + return ArrayRef(FrameCookieKinds); } ArrayRef<EnumEntry<SourceLanguage>> getSourceLanguageNames() { - return makeArrayRef(SourceLanguages); + return ArrayRef(SourceLanguages); } ArrayRef<EnumEntry<uint32_t>> getCompileSym2FlagNames() { - return makeArrayRef(CompileSym2FlagNames); + return ArrayRef(CompileSym2FlagNames); } ArrayRef<EnumEntry<uint32_t>> getCompileSym3FlagNames() { - return makeArrayRef(CompileSym3FlagNames); + return ArrayRef(CompileSym3FlagNames); } ArrayRef<EnumEntry<uint32_t>> getFileChecksumNames() { - return makeArrayRef(FileChecksumNames); + return ArrayRef(FileChecksumNames); } ArrayRef<EnumEntry<unsigned>> getCPUTypeNames() { - return makeArrayRef(CPUTypeNames); + return ArrayRef(CPUTypeNames); } ArrayRef<EnumEntry<uint32_t>> getFrameProcSymFlagNames() { - return makeArrayRef(FrameProcSymFlagNames); + return ArrayRef(FrameProcSymFlagNames); } ArrayRef<EnumEntry<uint16_t>> getExportSymFlagNames() { - return makeArrayRef(ExportSymFlagNames); + return ArrayRef(ExportSymFlagNames); } ArrayRef<EnumEntry<uint32_t>> getModuleSubstreamKindNames() { - return makeArrayRef(ModuleSubstreamKindNames); + return ArrayRef(ModuleSubstreamKindNames); } ArrayRef<EnumEntry<uint8_t>> getThunkOrdinalNames() { - return makeArrayRef(ThunkOrdinalNames); + return ArrayRef(ThunkOrdinalNames); } ArrayRef<EnumEntry<uint16_t>> getTrampolineNames() { - return makeArrayRef(TrampolineNames); + return ArrayRef(TrampolineNames); } ArrayRef<EnumEntry<COFF::SectionCharacteristics>> getImageSectionCharacteristicNames() { - return makeArrayRef(ImageSectionCharacteristicNames); + return ArrayRef(ImageSectionCharacteristicNames); } ArrayRef<EnumEntry<uint16_t>> getClassOptionNames() { - return makeArrayRef(ClassOptionNames); + return ArrayRef(ClassOptionNames); } ArrayRef<EnumEntry<uint8_t>> getMemberAccessNames() { - return makeArrayRef(MemberAccessNames); + return ArrayRef(MemberAccessNames); } ArrayRef<EnumEntry<uint16_t>> getMethodOptionNames() { - return makeArrayRef(MethodOptionNames); + return ArrayRef(MethodOptionNames); } ArrayRef<EnumEntry<uint16_t>> getMemberKindNames() { - return makeArrayRef(MemberKindNames); + return ArrayRef(MemberKindNames); } ArrayRef<EnumEntry<uint8_t>> getPtrKindNames() { - return makeArrayRef(PtrKindNames); + return ArrayRef(PtrKindNames); } ArrayRef<EnumEntry<uint8_t>> getPtrModeNames() { - return makeArrayRef(PtrModeNames); + return ArrayRef(PtrModeNames); } ArrayRef<EnumEntry<uint16_t>> getPtrMemberRepNames() { - return makeArrayRef(PtrMemberRepNames); + return ArrayRef(PtrMemberRepNames); } ArrayRef<EnumEntry<uint16_t>> getTypeModifierNames() { - return makeArrayRef(TypeModifierNames); + return ArrayRef(TypeModifierNames); } ArrayRef<EnumEntry<uint8_t>> getCallingConventions() { - return makeArrayRef(CallingConventions); + return ArrayRef(CallingConventions); } ArrayRef<EnumEntry<uint8_t>> getFunctionOptionEnum() { - return makeArrayRef(FunctionOptionEnum); + return ArrayRef(FunctionOptionEnum); } ArrayRef<EnumEntry<uint16_t>> getLabelTypeEnum() { - return makeArrayRef(LabelTypeEnum); + return ArrayRef(LabelTypeEnum); } } // end namespace codeview diff --git a/llvm/lib/DebugInfo/CodeView/Formatters.cpp b/llvm/lib/DebugInfo/CodeView/Formatters.cpp index 73a589212227..8c21764600b6 100644 --- a/llvm/lib/DebugInfo/CodeView/Formatters.cpp +++ b/llvm/lib/DebugInfo/CodeView/Formatters.cpp @@ -20,7 +20,7 @@ using namespace llvm::codeview; using namespace llvm::codeview::detail; GuidAdapter::GuidAdapter(StringRef Guid) - : FormatAdapter(makeArrayRef(Guid.bytes_begin(), Guid.bytes_end())) {} + : FormatAdapter(ArrayRef(Guid.bytes_begin(), Guid.bytes_end())) {} GuidAdapter::GuidAdapter(ArrayRef<uint8_t> Guid) : FormatAdapter(std::move(Guid)) {} diff --git a/llvm/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp b/llvm/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp index 142af382efba..6435e83d7d06 100644 --- a/llvm/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp +++ b/llvm/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp @@ -8,7 +8,6 @@ #include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/None.h" #include "llvm/DebugInfo/CodeView/CodeView.h" #include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h" #include "llvm/DebugInfo/CodeView/TypeIndex.h" @@ -32,16 +31,16 @@ GlobalTypeTableBuilder::GlobalTypeTableBuilder(BumpPtrAllocator &Storage) GlobalTypeTableBuilder::~GlobalTypeTableBuilder() = default; -Optional<TypeIndex> GlobalTypeTableBuilder::getFirst() { +std::optional<TypeIndex> GlobalTypeTableBuilder::getFirst() { if (empty()) - return None; + return std::nullopt; return TypeIndex(TypeIndex::FirstNonSimpleIndex); } -Optional<TypeIndex> GlobalTypeTableBuilder::getNext(TypeIndex Prev) { +std::optional<TypeIndex> GlobalTypeTableBuilder::getNext(TypeIndex Prev) { if (++Prev == nextTypeIndex()) - return None; + return std::nullopt; return Prev; } @@ -82,7 +81,7 @@ static inline ArrayRef<uint8_t> stabilize(BumpPtrAllocator &Alloc, ArrayRef<uint8_t> Data) { uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size()); memcpy(Stable, Data.data(), Data.size()); - return makeArrayRef(Stable, Data.size()); + return ArrayRef(Stable, Data.size()); } TypeIndex GlobalTypeTableBuilder::insertRecordBytes(ArrayRef<uint8_t> Record) { diff --git a/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp b/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp index 1d49a1ed4712..460f95d96a29 100644 --- a/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp +++ b/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp @@ -8,7 +8,6 @@ #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/None.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/DebugInfo/CodeView/CodeView.h" @@ -50,9 +49,8 @@ LazyRandomTypeCollection::LazyRandomTypeCollection(ArrayRef<uint8_t> Data, LazyRandomTypeCollection::LazyRandomTypeCollection(StringRef Data, uint32_t RecordCountHint) - : LazyRandomTypeCollection( - makeArrayRef(Data.bytes_begin(), Data.bytes_end()), RecordCountHint) { -} + : LazyRandomTypeCollection(ArrayRef(Data.bytes_begin(), Data.bytes_end()), + RecordCountHint) {} LazyRandomTypeCollection::LazyRandomTypeCollection(const CVTypeArray &Types, uint32_t NumRecords) @@ -98,13 +96,13 @@ CVType LazyRandomTypeCollection::getType(TypeIndex Index) { return Records[Index.toArrayIndex()].Type; } -Optional<CVType> LazyRandomTypeCollection::tryGetType(TypeIndex Index) { +std::optional<CVType> LazyRandomTypeCollection::tryGetType(TypeIndex Index) { if (Index.isSimple()) - return None; + return std::nullopt; if (auto EC = ensureTypeExists(Index)) { consumeError(std::move(EC)); - return None; + return std::nullopt; } assert(contains(Index)); @@ -202,22 +200,22 @@ Error LazyRandomTypeCollection::visitRangeForType(TypeIndex TI) { return Error::success(); } -Optional<TypeIndex> LazyRandomTypeCollection::getFirst() { +std::optional<TypeIndex> LazyRandomTypeCollection::getFirst() { TypeIndex TI = TypeIndex::fromArrayIndex(0); if (auto EC = ensureTypeExists(TI)) { consumeError(std::move(EC)); - return None; + return std::nullopt; } return TI; } -Optional<TypeIndex> LazyRandomTypeCollection::getNext(TypeIndex Prev) { +std::optional<TypeIndex> LazyRandomTypeCollection::getNext(TypeIndex Prev) { // We can't be sure how long this type stream is, given that the initial count // given to the constructor is just a hint. So just try to make sure the next // record exists, and if anything goes wrong, we must be at the end. if (auto EC = ensureTypeExists(Prev + 1)) { consumeError(std::move(EC)); - return None; + return std::nullopt; } return Prev + 1; diff --git a/llvm/lib/DebugInfo/CodeView/MergingTypeTableBuilder.cpp b/llvm/lib/DebugInfo/CodeView/MergingTypeTableBuilder.cpp index 62d228599eae..67f5d6b00686 100644 --- a/llvm/lib/DebugInfo/CodeView/MergingTypeTableBuilder.cpp +++ b/llvm/lib/DebugInfo/CodeView/MergingTypeTableBuilder.cpp @@ -8,7 +8,6 @@ #include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/None.h" #include "llvm/DebugInfo/CodeView/CodeView.h" #include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h" #include "llvm/DebugInfo/CodeView/TypeHashing.h" @@ -33,16 +32,16 @@ MergingTypeTableBuilder::MergingTypeTableBuilder(BumpPtrAllocator &Storage) MergingTypeTableBuilder::~MergingTypeTableBuilder() = default; -Optional<TypeIndex> MergingTypeTableBuilder::getFirst() { +std::optional<TypeIndex> MergingTypeTableBuilder::getFirst() { if (empty()) - return None; + return std::nullopt; return TypeIndex(TypeIndex::FirstNonSimpleIndex); } -Optional<TypeIndex> MergingTypeTableBuilder::getNext(TypeIndex Prev) { +std::optional<TypeIndex> MergingTypeTableBuilder::getNext(TypeIndex Prev) { if (++Prev == nextTypeIndex()) - return None; + return std::nullopt; return Prev; } @@ -79,7 +78,7 @@ static inline ArrayRef<uint8_t> stabilize(BumpPtrAllocator &Alloc, ArrayRef<uint8_t> Data) { uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size()); memcpy(Stable, Data.data(), Data.size()); - return makeArrayRef(Stable, Data.size()); + return ArrayRef(Stable, Data.size()); } TypeIndex MergingTypeTableBuilder::insertRecordAs(hash_code Hash, diff --git a/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp b/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp index 5d27c9f29984..df7e42df1afc 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp @@ -27,7 +27,7 @@ static const EnumEntry<TypeLeafKind> LeafTypeNames[] = { }; #define ENUM_ENTRY(enum_class, enum) \ - { #enum, std::underlying_type < enum_class > ::type(enum_class::enum) } + { #enum, std::underlying_type_t<enum_class>(enum_class::enum) } static const EnumEntry<uint16_t> ClassOptionNames[] = { ENUM_ENTRY(ClassOptions, Packed), @@ -177,7 +177,7 @@ Error TypeDumpVisitor::visitTypeBegin(CVType &Record, TypeIndex Index) { W->getOStream() << " {\n"; W->indent(); W->printEnum("TypeLeafKind", unsigned(Record.kind()), - makeArrayRef(LeafTypeNames)); + ArrayRef(LeafTypeNames)); return Error::success(); } @@ -194,8 +194,7 @@ Error TypeDumpVisitor::visitMemberBegin(CVMemberRecord &Record) { W->startLine() << getLeafTypeName(Record.Kind); W->getOStream() << " {\n"; W->indent(); - W->printEnum("TypeLeafKind", unsigned(Record.Kind), - makeArrayRef(LeafTypeNames)); + W->printEnum("TypeLeafKind", unsigned(Record.Kind), ArrayRef(LeafTypeNames)); return Error::success(); } @@ -247,7 +246,7 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, StringListRecord &Strs) { Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ClassRecord &Class) { uint16_t Props = static_cast<uint16_t>(Class.getOptions()); W->printNumber("MemberCount", Class.getMemberCount()); - W->printFlags("Properties", Props, makeArrayRef(ClassOptionNames)); + W->printFlags("Properties", Props, ArrayRef(ClassOptionNames)); printTypeIndex("FieldList", Class.getFieldList()); printTypeIndex("DerivedFrom", Class.getDerivationList()); printTypeIndex("VShape", Class.getVTableShape()); @@ -261,7 +260,7 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ClassRecord &Class) { Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, UnionRecord &Union) { uint16_t Props = static_cast<uint16_t>(Union.getOptions()); W->printNumber("MemberCount", Union.getMemberCount()); - W->printFlags("Properties", Props, makeArrayRef(ClassOptionNames)); + W->printFlags("Properties", Props, ArrayRef(ClassOptionNames)); printTypeIndex("FieldList", Union.getFieldList()); W->printNumber("SizeOf", Union.getSize()); W->printString("Name", Union.getName()); @@ -274,7 +273,7 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, EnumRecord &Enum) { uint16_t Props = static_cast<uint16_t>(Enum.getOptions()); W->printNumber("NumEnumerators", Enum.getMemberCount()); W->printFlags("Properties", uint16_t(Enum.getOptions()), - makeArrayRef(ClassOptionNames)); + ArrayRef(ClassOptionNames)); printTypeIndex("UnderlyingType", Enum.getUnderlyingType()); printTypeIndex("FieldListType", Enum.getFieldList()); W->printString("Name", Enum.getName()); @@ -311,9 +310,9 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, MemberFuncIdRecord &Id) { Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ProcedureRecord &Proc) { printTypeIndex("ReturnType", Proc.getReturnType()); W->printEnum("CallingConvention", uint8_t(Proc.getCallConv()), - makeArrayRef(CallingConventions)); + ArrayRef(CallingConventions)); W->printFlags("FunctionOptions", uint8_t(Proc.getOptions()), - makeArrayRef(FunctionOptionEnum)); + ArrayRef(FunctionOptionEnum)); W->printNumber("NumParameters", Proc.getParameterCount()); printTypeIndex("ArgListType", Proc.getArgumentList()); return Error::success(); @@ -324,9 +323,9 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, MemberFunctionRecord &MF) { printTypeIndex("ClassType", MF.getClassType()); printTypeIndex("ThisType", MF.getThisType()); W->printEnum("CallingConvention", uint8_t(MF.getCallConv()), - makeArrayRef(CallingConventions)); + ArrayRef(CallingConventions)); W->printFlags("FunctionOptions", uint8_t(MF.getOptions()), - makeArrayRef(FunctionOptionEnum)); + ArrayRef(FunctionOptionEnum)); W->printNumber("NumParameters", MF.getParameterCount()); printTypeIndex("ArgListType", MF.getArgumentList()); W->printNumber("ThisAdjustment", MF.getThisPointerAdjustment()); @@ -335,7 +334,7 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, MemberFunctionRecord &MF) { Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, MethodOverloadListRecord &MethodList) { - for (auto &M : MethodList.getMethods()) { + for (const auto &M : MethodList.getMethods()) { ListScope S(*W, "Method"); printMemberAttributes(M.getAccess(), M.getMethodKind(), M.getOptions()); printTypeIndex("Type", M.getType()); @@ -362,8 +361,8 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, TypeServer2Record &TS) { Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) { printTypeIndex("PointeeType", Ptr.getReferentType()); W->printEnum("PtrType", unsigned(Ptr.getPointerKind()), - makeArrayRef(PtrKindNames)); - W->printEnum("PtrMode", unsigned(Ptr.getMode()), makeArrayRef(PtrModeNames)); + ArrayRef(PtrKindNames)); + W->printEnum("PtrMode", unsigned(Ptr.getMode()), ArrayRef(PtrModeNames)); W->printNumber("IsFlat", Ptr.isFlat()); W->printNumber("IsConst", Ptr.isConst()); @@ -379,7 +378,7 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) { printTypeIndex("ClassType", MI.getContainingType()); W->printEnum("Representation", uint16_t(MI.getRepresentation()), - makeArrayRef(PtrMemberRepNames)); + ArrayRef(PtrMemberRepNames)); } return Error::success(); @@ -388,7 +387,7 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) { Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ModifierRecord &Mod) { uint16_t Mods = static_cast<uint16_t>(Mod.getModifiers()); printTypeIndex("ModifiedType", Mod.getModifiedType()); - W->printFlags("Modifiers", Mods, makeArrayRef(TypeModifierNames)); + W->printFlags("Modifiers", Mods, ArrayRef(TypeModifierNames)); return Error::success(); } @@ -441,14 +440,13 @@ void TypeDumpVisitor::printMemberAttributes(MemberAttributes Attrs) { void TypeDumpVisitor::printMemberAttributes(MemberAccess Access, MethodKind Kind, MethodOptions Options) { - W->printEnum("AccessSpecifier", uint8_t(Access), - makeArrayRef(MemberAccessNames)); + W->printEnum("AccessSpecifier", uint8_t(Access), ArrayRef(MemberAccessNames)); // Data members will be vanilla. Don't try to print a method kind for them. if (Kind != MethodKind::Vanilla) - W->printEnum("MethodKind", unsigned(Kind), makeArrayRef(MemberKindNames)); + W->printEnum("MethodKind", unsigned(Kind), ArrayRef(MemberKindNames)); if (Options != MethodOptions::None) { W->printFlags("MethodOptions", unsigned(Options), - makeArrayRef(MethodOptionNames)); + ArrayRef(MethodOptionNames)); } } @@ -458,7 +456,7 @@ Error TypeDumpVisitor::visitUnknownMember(CVMemberRecord &Record) { } Error TypeDumpVisitor::visitUnknownType(CVType &Record) { - W->printEnum("Kind", uint16_t(Record.kind()), makeArrayRef(LeafTypeNames)); + W->printEnum("Kind", uint16_t(Record.kind()), ArrayRef(LeafTypeNames)); W->printNumber("Length", uint32_t(Record.content().size())); return Error::success(); } @@ -551,7 +549,7 @@ Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, } Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, LabelRecord &LR) { - W->printEnum("Mode", uint16_t(LR.Mode), makeArrayRef(LabelTypeEnum)); + W->printEnum("Mode", uint16_t(LR.Mode), ArrayRef(LabelTypeEnum)); return Error::success(); } diff --git a/llvm/lib/DebugInfo/CodeView/TypeHashing.cpp b/llvm/lib/DebugInfo/CodeView/TypeHashing.cpp index fc85d8186eaa..931a2cb358d9 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeHashing.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeHashing.cpp @@ -9,7 +9,7 @@ #include "llvm/DebugInfo/CodeView/TypeHashing.h" #include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h" -#include "llvm/Support/SHA1.h" +#include "llvm/Support/BLAKE3.h" using namespace llvm; using namespace llvm::codeview; @@ -35,7 +35,7 @@ GloballyHashedType::hashType(ArrayRef<uint8_t> RecordData, ArrayRef<GloballyHashedType> PreviousIds) { SmallVector<TiReference, 4> Refs; discoverTypeIndices(RecordData, Refs); - SHA1 S; + TruncatedBLAKE3<8> S; S.init(); uint32_t Off = 0; S.update(RecordData.take_front(sizeof(RecordPrefix))); @@ -56,7 +56,7 @@ GloballyHashedType::hashType(ArrayRef<uint8_t> RecordData, ArrayRef<uint8_t> BytesToHash; if (TI.isSimple() || TI.isNoneType()) { const uint8_t *IndexBytes = reinterpret_cast<const uint8_t *>(&TI); - BytesToHash = makeArrayRef(IndexBytes, sizeof(TypeIndex)); + BytesToHash = ArrayRef(IndexBytes, sizeof(TypeIndex)); } else { if (TI.toArrayIndex() >= Prev.size() || Prev[TI.toArrayIndex()].empty()) { @@ -76,6 +76,5 @@ GloballyHashedType::hashType(ArrayRef<uint8_t> RecordData, auto TrailingBytes = RecordData.drop_front(Off); S.update(TrailingBytes); - std::array<uint8_t, 20> Hash = S.final(); - return {ArrayRef<uint8_t>(Hash).take_back(8)}; + return {S.final()}; } diff --git a/llvm/lib/DebugInfo/CodeView/TypeRecordHelpers.cpp b/llvm/lib/DebugInfo/CodeView/TypeRecordHelpers.cpp index 8e632f3be460..e44dec6d6396 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeRecordHelpers.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeRecordHelpers.cpp @@ -9,8 +9,8 @@ #include "llvm/DebugInfo/CodeView/TypeRecordHelpers.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h" #include "llvm/DebugInfo/CodeView/TypeDeserializer.h" +#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h" using namespace llvm; using namespace llvm::codeview; @@ -50,3 +50,133 @@ TypeIndex llvm::codeview::getModifiedType(const CVType &CVT) { discoverTypeIndices(CVT, Refs); return Refs.front(); } + +uint64_t llvm::codeview::getSizeInBytesForTypeIndex(TypeIndex TI) { + if (!TI.isSimple()) + return 0; + if (TI.getSimpleMode() != SimpleTypeMode::Direct) { + // We have a native pointer. + switch (TI.getSimpleMode()) { + case SimpleTypeMode::NearPointer: + case SimpleTypeMode::FarPointer: + case SimpleTypeMode::HugePointer: + return 2; + case SimpleTypeMode::NearPointer32: + case SimpleTypeMode::FarPointer32: + return 4; + case SimpleTypeMode::NearPointer64: + return 8; + case SimpleTypeMode::NearPointer128: + return 16; + default: + assert(false && "invalid simple type mode!"); + } + } + switch (TI.getSimpleKind()) { + case SimpleTypeKind::None: + case SimpleTypeKind::Void: + return 0; + case SimpleTypeKind::HResult: + return 4; + case SimpleTypeKind::SByte: + case SimpleTypeKind::Byte: + return 1; + + // Signed/unsigned integer. + case SimpleTypeKind::Int16Short: + case SimpleTypeKind::UInt16Short: + case SimpleTypeKind::Int16: + case SimpleTypeKind::UInt16: + return 2; + case SimpleTypeKind::Int32Long: + case SimpleTypeKind::UInt32Long: + case SimpleTypeKind::Int32: + case SimpleTypeKind::UInt32: + return 4; + case SimpleTypeKind::Int64Quad: + case SimpleTypeKind::UInt64Quad: + case SimpleTypeKind::Int64: + case SimpleTypeKind::UInt64: + return 8; + case SimpleTypeKind::Int128Oct: + case SimpleTypeKind::UInt128Oct: + case SimpleTypeKind::Int128: + case SimpleTypeKind::UInt128: + return 16; + + // Signed/Unsigned character. + case SimpleTypeKind::Character8: + case SimpleTypeKind::SignedCharacter: + case SimpleTypeKind::UnsignedCharacter: + case SimpleTypeKind::NarrowCharacter: + return 1; + case SimpleTypeKind::WideCharacter: + case SimpleTypeKind::Character16: + return 2; + case SimpleTypeKind::Character32: + return 4; + + // Float. + case SimpleTypeKind::Float16: + return 2; + case SimpleTypeKind::Float32: + return 4; + case SimpleTypeKind::Float48: + return 6; + case SimpleTypeKind::Float64: + return 8; + case SimpleTypeKind::Float80: + return 10; + case SimpleTypeKind::Float128: + return 16; + + // Boolean. + case SimpleTypeKind::Boolean8: + return 1; + case SimpleTypeKind::Boolean16: + return 2; + case SimpleTypeKind::Boolean32: + return 4; + case SimpleTypeKind::Boolean64: + return 8; + case SimpleTypeKind::Boolean128: + return 16; + + // Complex float. + case SimpleTypeKind::Complex16: + return 2; + case SimpleTypeKind::Complex32: + return 4; + case SimpleTypeKind::Complex64: + return 8; + case SimpleTypeKind::Complex80: + return 10; + case SimpleTypeKind::Complex128: + return 16; + + default: + return 0; + } +} + +template <typename RecordT> static uint64_t getUdtSize(CVType CVT) { + RecordT Record; + if (auto EC = TypeDeserializer::deserializeAs<RecordT>(CVT, Record)) { + consumeError(std::move(EC)); + return 0; + } + return Record.getSize(); +} + +uint64_t llvm::codeview::getSizeInBytesForTypeRecord(CVType CVT) { + switch (CVT.kind()) { + case LF_STRUCTURE: + case LF_CLASS: + case LF_INTERFACE: + return getUdtSize<ClassRecord>(std::move(CVT)); + case LF_UNION: + return getUdtSize<UnionRecord>(std::move(CVT)); + default: + return CVT.length(); + } +} diff --git a/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp b/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp index 7f4511258c64..0bc65f8d0359 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp @@ -122,16 +122,16 @@ static std::string getMemberAttributes(CodeViewRecordIO &IO, if (!IO.isStreaming()) return ""; std::string AccessSpecifier = std::string( - getEnumName(IO, uint8_t(Access), makeArrayRef(getMemberAccessNames()))); + getEnumName(IO, uint8_t(Access), ArrayRef(getMemberAccessNames()))); std::string MemberAttrs(AccessSpecifier); if (Kind != MethodKind::Vanilla) { std::string MethodKind = std::string( - getEnumName(IO, unsigned(Kind), makeArrayRef(getMemberKindNames()))); + getEnumName(IO, unsigned(Kind), ArrayRef(getMemberKindNames()))); MemberAttrs += ", " + MethodKind; } if (Options != MethodOptions::None) { - std::string MethodOptions = getFlagNames( - IO, unsigned(Options), makeArrayRef(getMethodOptionNames())); + std::string MethodOptions = + getFlagNames(IO, unsigned(Options), ArrayRef(getMethodOptionNames())); MemberAttrs += ", " + MethodOptions; } return MemberAttrs; @@ -236,7 +236,7 @@ Error TypeRecordMapping::visitTypeBegin(CVType &CVR) { // FieldList and MethodList records can be any length because they can be // split with continuation records. All other record types cannot be // longer than the maximum record length. - Optional<uint32_t> MaxLen; + std::optional<uint32_t> MaxLen; if (CVR.kind() != TypeLeafKind::LF_FIELDLIST && CVR.kind() != TypeLeafKind::LF_METHODLIST) MaxLen = MaxRecordLength - sizeof(RecordPrefix); @@ -247,7 +247,7 @@ Error TypeRecordMapping::visitTypeBegin(CVType &CVR) { auto RecordKind = CVR.kind(); uint16_t RecordLen = CVR.length() - 2; std::string RecordKindName = std::string( - getEnumName(IO, unsigned(RecordKind), makeArrayRef(LeafTypeNames))); + getEnumName(IO, unsigned(RecordKind), ArrayRef(LeafTypeNames))); error(IO.mapInteger(RecordLen, "Record length")); error(IO.mapEnum(RecordKind, "Record kind: " + RecordKindName)); } @@ -289,7 +289,7 @@ Error TypeRecordMapping::visitMemberBegin(CVMemberRecord &Record) { std::string MemberKindName = std::string(getLeafTypeName(Record.Kind)); MemberKindName += " ( " + - (getEnumName(IO, unsigned(Record.Kind), makeArrayRef(LeafTypeNames))) + (getEnumName(IO, unsigned(Record.Kind), ArrayRef(LeafTypeNames))) .str() + " )"; error(IO.mapEnum(Record.Kind, "Member kind: " + MemberKindName)); @@ -314,7 +314,7 @@ Error TypeRecordMapping::visitMemberEnd(CVMemberRecord &Record) { Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ModifierRecord &Record) { std::string ModifierNames = getFlagNames(IO, static_cast<uint16_t>(Record.Modifiers), - makeArrayRef(getTypeModifierNames())); + ArrayRef(getTypeModifierNames())); error(IO.mapInteger(Record.ModifiedType, "ModifiedType")); error(IO.mapEnum(Record.Modifiers, "Modifiers" + ModifierNames)); return Error::success(); @@ -323,10 +323,10 @@ Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ModifierRecord &Record) { Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ProcedureRecord &Record) { std::string CallingConvName = std::string(getEnumName( - IO, uint8_t(Record.CallConv), makeArrayRef(getCallingConventions()))); + IO, uint8_t(Record.CallConv), ArrayRef(getCallingConventions()))); std::string FuncOptionNames = getFlagNames(IO, static_cast<uint16_t>(Record.Options), - makeArrayRef(getFunctionOptionEnum())); + ArrayRef(getFunctionOptionEnum())); error(IO.mapInteger(Record.ReturnType, "ReturnType")); error(IO.mapEnum(Record.CallConv, "CallingConvention: " + CallingConvName)); error(IO.mapEnum(Record.Options, "FunctionOptions" + FuncOptionNames)); @@ -339,10 +339,10 @@ Error TypeRecordMapping::visitKnownRecord(CVType &CVR, Error TypeRecordMapping::visitKnownRecord(CVType &CVR, MemberFunctionRecord &Record) { std::string CallingConvName = std::string(getEnumName( - IO, uint8_t(Record.CallConv), makeArrayRef(getCallingConventions()))); + IO, uint8_t(Record.CallConv), ArrayRef(getCallingConventions()))); std::string FuncOptionNames = getFlagNames(IO, static_cast<uint16_t>(Record.Options), - makeArrayRef(getFunctionOptionEnum())); + ArrayRef(getFunctionOptionEnum())); error(IO.mapInteger(Record.ReturnType, "ReturnType")); error(IO.mapInteger(Record.ClassType, "ClassType")); error(IO.mapInteger(Record.ThisType, "ThisType")); @@ -382,13 +382,12 @@ Error TypeRecordMapping::visitKnownRecord(CVType &CVR, PointerRecord &Record) { SmallString<128> Attr("Attrs: "); if (IO.isStreaming()) { - std::string PtrType = - std::string(getEnumName(IO, unsigned(Record.getPointerKind()), - makeArrayRef(getPtrKindNames()))); + std::string PtrType = std::string(getEnumName( + IO, unsigned(Record.getPointerKind()), ArrayRef(getPtrKindNames()))); Attr += "[ Type: " + PtrType; std::string PtrMode = std::string(getEnumName( - IO, unsigned(Record.getMode()), makeArrayRef(getPtrModeNames()))); + IO, unsigned(Record.getMode()), ArrayRef(getPtrModeNames()))); Attr += ", Mode: " + PtrMode; auto PtrSizeOf = Record.getSize(); @@ -421,7 +420,7 @@ Error TypeRecordMapping::visitKnownRecord(CVType &CVR, PointerRecord &Record) { MemberPointerInfo &M = *Record.MemberInfo; error(IO.mapInteger(M.ContainingType, "ClassType")); std::string PtrMemberGetRepresentation = std::string(getEnumName( - IO, uint16_t(M.Representation), makeArrayRef(getPtrMemberRepNames()))); + IO, uint16_t(M.Representation), ArrayRef(getPtrMemberRepNames()))); error(IO.mapEnum(M.Representation, "Representation: " + PtrMemberGetRepresentation)); } @@ -445,7 +444,7 @@ Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ClassRecord &Record) { std::string PropertiesNames = getFlagNames(IO, static_cast<uint16_t>(Record.Options), - makeArrayRef(getClassOptionNames())); + ArrayRef(getClassOptionNames())); error(IO.mapInteger(Record.MemberCount, "MemberCount")); error(IO.mapEnum(Record.Options, "Properties" + PropertiesNames)); error(IO.mapInteger(Record.FieldList, "FieldList")); @@ -461,7 +460,7 @@ Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ClassRecord &Record) { Error TypeRecordMapping::visitKnownRecord(CVType &CVR, UnionRecord &Record) { std::string PropertiesNames = getFlagNames(IO, static_cast<uint16_t>(Record.Options), - makeArrayRef(getClassOptionNames())); + ArrayRef(getClassOptionNames())); error(IO.mapInteger(Record.MemberCount, "MemberCount")); error(IO.mapEnum(Record.Options, "Properties" + PropertiesNames)); error(IO.mapInteger(Record.FieldList, "FieldList")); @@ -475,7 +474,7 @@ Error TypeRecordMapping::visitKnownRecord(CVType &CVR, UnionRecord &Record) { Error TypeRecordMapping::visitKnownRecord(CVType &CVR, EnumRecord &Record) { std::string PropertiesNames = getFlagNames(IO, static_cast<uint16_t>(Record.Options), - makeArrayRef(getClassOptionNames())); + ArrayRef(getClassOptionNames())); error(IO.mapInteger(Record.MemberCount, "NumEnumerators")); error(IO.mapEnum(Record.Options, "Properties" + PropertiesNames)); error(IO.mapInteger(Record.UnderlyingType, "UnderlyingType")); @@ -628,7 +627,7 @@ Error TypeRecordMapping::visitKnownRecord(CVType &CVR, Error TypeRecordMapping::visitKnownRecord(CVType &CVR, LabelRecord &Record) { std::string ModeName = std::string( - getEnumName(IO, uint16_t(Record.Mode), makeArrayRef(getLabelTypeEnum()))); + getEnumName(IO, uint16_t(Record.Mode), ArrayRef(getLabelTypeEnum()))); error(IO.mapEnum(Record.Mode, "Mode: " + ModeName)); return Error::success(); } diff --git a/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp b/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp index 7ddfb7ab2f8d..b9aaa3146c9c 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/CodeView/TypeStreamMerger.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h" #include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h" @@ -17,6 +16,7 @@ #include "llvm/DebugInfo/CodeView/TypeRecord.h" #include "llvm/DebugInfo/CodeView/TypeRecordHelpers.h" #include "llvm/Support/Error.h" +#include <optional> using namespace llvm; using namespace llvm::codeview; @@ -77,7 +77,8 @@ public: // Local hashing entry points Error mergeTypesAndIds(MergingTypeTableBuilder &DestIds, MergingTypeTableBuilder &DestTypes, - const CVTypeArray &IdsAndTypes, Optional<uint32_t> &S); + const CVTypeArray &IdsAndTypes, + std::optional<PCHMergerInfo> &PCHInfo); Error mergeIdRecords(MergingTypeTableBuilder &Dest, ArrayRef<TypeIndex> TypeSourceToDest, const CVTypeArray &Ids); @@ -89,14 +90,14 @@ public: GlobalTypeTableBuilder &DestTypes, const CVTypeArray &IdsAndTypes, ArrayRef<GloballyHashedType> Hashes, - Optional<uint32_t> &S); + std::optional<PCHMergerInfo> &PCHInfo); Error mergeIdRecords(GlobalTypeTableBuilder &Dest, ArrayRef<TypeIndex> TypeSourceToDest, const CVTypeArray &Ids, ArrayRef<GloballyHashedType> Hashes); Error mergeTypeRecords(GlobalTypeTableBuilder &Dest, const CVTypeArray &Types, ArrayRef<GloballyHashedType> Hashes, - Optional<uint32_t> &S); + std::optional<PCHMergerInfo> &PCHInfo); private: Error doit(const CVTypeArray &Types); @@ -166,7 +167,7 @@ private: Expected<bool> shouldRemapType(const CVType &Type); - Optional<Error> LastError; + std::optional<Error> LastError; bool UseGlobalHashes = false; @@ -196,7 +197,7 @@ private: /// its type indices. SmallVector<uint8_t, 256> RemapStorage; - Optional<uint32_t> PCHSignature; + std::optional<PCHMergerInfo> PCHInfo; }; } // end anonymous namespace @@ -256,28 +257,27 @@ Error TypeStreamMerger::mergeIdRecords(MergingTypeTableBuilder &Dest, return doit(Ids); } -Error TypeStreamMerger::mergeTypesAndIds(MergingTypeTableBuilder &DestIds, - MergingTypeTableBuilder &DestTypes, - const CVTypeArray &IdsAndTypes, - Optional<uint32_t> &S) { +Error TypeStreamMerger::mergeTypesAndIds( + MergingTypeTableBuilder &DestIds, MergingTypeTableBuilder &DestTypes, + const CVTypeArray &IdsAndTypes, std::optional<PCHMergerInfo> &PCHInfo) { DestIdStream = &DestIds; DestTypeStream = &DestTypes; UseGlobalHashes = false; auto Err = doit(IdsAndTypes); - S = PCHSignature; + PCHInfo = this->PCHInfo; return Err; } // Global hashing entry points -Error TypeStreamMerger::mergeTypeRecords(GlobalTypeTableBuilder &Dest, - const CVTypeArray &Types, - ArrayRef<GloballyHashedType> Hashes, - Optional<uint32_t> &S) { +Error TypeStreamMerger::mergeTypeRecords( + GlobalTypeTableBuilder &Dest, const CVTypeArray &Types, + ArrayRef<GloballyHashedType> Hashes, + std::optional<PCHMergerInfo> &PCHInfo) { DestGlobalTypeStream = &Dest; UseGlobalHashes = true; GlobalHashes = Hashes; auto Err = doit(Types); - S = PCHSignature; + PCHInfo = this->PCHInfo; return Err; } @@ -293,17 +293,16 @@ Error TypeStreamMerger::mergeIdRecords(GlobalTypeTableBuilder &Dest, return doit(Ids); } -Error TypeStreamMerger::mergeTypesAndIds(GlobalTypeTableBuilder &DestIds, - GlobalTypeTableBuilder &DestTypes, - const CVTypeArray &IdsAndTypes, - ArrayRef<GloballyHashedType> Hashes, - Optional<uint32_t> &S) { +Error TypeStreamMerger::mergeTypesAndIds( + GlobalTypeTableBuilder &DestIds, GlobalTypeTableBuilder &DestTypes, + const CVTypeArray &IdsAndTypes, ArrayRef<GloballyHashedType> Hashes, + std::optional<PCHMergerInfo> &PCHInfo) { DestGlobalIdStream = &DestIds; DestGlobalTypeStream = &DestTypes; UseGlobalHashes = true; GlobalHashes = Hashes; auto Err = doit(IdsAndTypes); - S = PCHSignature; + PCHInfo = this->PCHInfo; return Err; } @@ -446,27 +445,27 @@ Error llvm::codeview::mergeIdRecords(MergingTypeTableBuilder &Dest, Error llvm::codeview::mergeTypeAndIdRecords( MergingTypeTableBuilder &DestIds, MergingTypeTableBuilder &DestTypes, SmallVectorImpl<TypeIndex> &SourceToDest, const CVTypeArray &IdsAndTypes, - Optional<uint32_t> &PCHSignature) { + std::optional<PCHMergerInfo> &PCHInfo) { TypeStreamMerger M(SourceToDest); - return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes, PCHSignature); + return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes, PCHInfo); } Error llvm::codeview::mergeTypeAndIdRecords( GlobalTypeTableBuilder &DestIds, GlobalTypeTableBuilder &DestTypes, SmallVectorImpl<TypeIndex> &SourceToDest, const CVTypeArray &IdsAndTypes, - ArrayRef<GloballyHashedType> Hashes, Optional<uint32_t> &PCHSignature) { + ArrayRef<GloballyHashedType> Hashes, + std::optional<PCHMergerInfo> &PCHInfo) { TypeStreamMerger M(SourceToDest); - return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes, Hashes, - PCHSignature); + return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes, Hashes, PCHInfo); } Error llvm::codeview::mergeTypeRecords(GlobalTypeTableBuilder &Dest, SmallVectorImpl<TypeIndex> &SourceToDest, const CVTypeArray &Types, ArrayRef<GloballyHashedType> Hashes, - Optional<uint32_t> &PCHSignature) { + std::optional<PCHMergerInfo> &PCHInfo) { TypeStreamMerger M(SourceToDest); - return M.mergeTypeRecords(Dest, Types, Hashes, PCHSignature); + return M.mergeTypeRecords(Dest, Types, Hashes, PCHInfo); } Error llvm::codeview::mergeIdRecords(GlobalTypeTableBuilder &Dest, @@ -487,9 +486,10 @@ Expected<bool> TypeStreamMerger::shouldRemapType(const CVType &Type) { if (auto EC = TypeDeserializer::deserializeAs(const_cast<CVType &>(Type), EP)) return joinErrors(std::move(EC), errorCorruptRecord()); - if (PCHSignature) + // Only one record of this kind can appear in a OBJ. + if (PCHInfo) return errorCorruptRecord(); - PCHSignature.emplace(EP.getSignature()); + PCHInfo.emplace(PCHMergerInfo{EP.getSignature(), CurIndex.toArrayIndex()}); return false; } return true; diff --git a/llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp b/llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp index 910a32730e39..50ac6fc5906d 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp @@ -21,17 +21,17 @@ TypeTableCollection::TypeTableCollection(ArrayRef<ArrayRef<uint8_t>> Records) Names.resize(Records.size()); } -Optional<TypeIndex> TypeTableCollection::getFirst() { +std::optional<TypeIndex> TypeTableCollection::getFirst() { if (empty()) - return None; + return std::nullopt; return TypeIndex::fromArrayIndex(0); } -Optional<TypeIndex> TypeTableCollection::getNext(TypeIndex Prev) { +std::optional<TypeIndex> TypeTableCollection::getNext(TypeIndex Prev) { assert(contains(Prev)); ++Prev; if (Prev.toArrayIndex() == size()) - return None; + return std::nullopt; return Prev; } |