Index: llvm/include/llvm/DebugInfo/CodeView/TypeSerializer.h =================================================================== --- llvm/include/llvm/DebugInfo/CodeView/TypeSerializer.h +++ llvm/include/llvm/DebugInfo/CodeView/TypeSerializer.h @@ -75,6 +75,8 @@ explicit TypeSerializer(BumpPtrAllocator &Storage, bool Hash = true); ~TypeSerializer(); + void reset(); + ArrayRef> records() const; TypeIndex insertRecordBytes(ArrayRef Record); TypeIndex insertRecord(const RemappedType &Record); Index: llvm/include/llvm/DebugInfo/CodeView/TypeTableBuilder.h =================================================================== --- llvm/include/llvm/DebugInfo/CodeView/TypeTableBuilder.h +++ llvm/include/llvm/DebugInfo/CodeView/TypeTableBuilder.h @@ -97,6 +97,8 @@ } void begin() { + TempSerializer.reset(); + if (auto EC = TempSerializer.visitTypeBegin(Type)) consumeError(std::move(EC)); } @@ -112,23 +114,19 @@ consumeError(std::move(EC)); } - TypeIndex end() { + TypeIndex end(bool Write) { + TypeIndex Index; if (auto EC = TempSerializer.visitTypeEnd(Type)) { consumeError(std::move(EC)); return TypeIndex(); } - TypeIndex Index; - for (auto Record : TempSerializer.records()) { - Index = TypeTable.writeSerializedRecord(Record); + if (Write) { + for (auto Record : TempSerializer.records()) + Index = TypeTable.writeSerializedRecord(Record); } - return Index; - } - /// Stop building the record. - void reset() { - if (auto EC = TempSerializer.visitTypeEnd(Type)) - consumeError(std::move(EC)); + return Index; } }; Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -1562,7 +1562,7 @@ EnumeratorCount++; } } - FTI = FLRB.end(); + FTI = FLRB.end(true); } std::string FullName = getFullyQualifiedName(Ty); @@ -1869,7 +1869,7 @@ MemberCount++; } - TypeIndex FieldTI = FLBR.end(); + TypeIndex FieldTI = FLBR.end(true); return std::make_tuple(FieldTI, Info.VShapeTI, MemberCount, !Info.NestedClasses.empty()); } Index: llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp =================================================================== --- llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp +++ llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp @@ -88,6 +88,11 @@ ArrayRef> records() const { return SeenRecords; } + void reset() { + SeenRecords.clear(); + HashedRecords.clear(); + } + /// Takes the bytes of type record, inserts them into the hash table, saves /// them, and returns a pointer to an identical stable type record along with /// its type index in the destination stream. @@ -221,6 +226,15 @@ return Hasher->records(); } +void TypeSerializer::reset() { + Hasher->reset(); + Writer.setOffset(0); + CurrentSegment = RecordSegment(); + FieldListSegments.clear(); + TypeKind.reset(); + MemberKind.reset(); +} + TypeIndex TypeSerializer::insertRecordBytes(ArrayRef Record) { assert(!TypeKind.hasValue() && "Already in a type mapping!"); assert(Writer.getOffset() == 0 && "Stream has data already!"); Index: llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp =================================================================== --- llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp +++ llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp @@ -492,21 +492,18 @@ assert(DestTypeStream); // Visit the members inside the field list. HadUntranslatedMember = false; - FieldListBuilder = llvm::make_unique(*DestTypeStream); + if (!FieldListBuilder) + FieldListBuilder = + llvm::make_unique(*DestTypeStream); FieldListBuilder->begin(); if (auto EC = codeview::visitMemberRecordStream(CVR.content(), *this)) return EC; // Write the record if we translated all field list members. - TypeIndex DestIdx = Untranslated; - if (!HadUntranslatedMember) - DestIdx = FieldListBuilder->end(); - else - FieldListBuilder->reset(); - addMapping(DestIdx); - - FieldListBuilder.reset(); + TypeIndex DestIdx = FieldListBuilder->end(!HadUntranslatedMember); + addMapping(HadUntranslatedMember ? Untranslated : DestIdx); + return Error::success(); }