aboutsummaryrefslogtreecommitdiff
path: root/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp')
-rw-r--r--lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp37
1 files changed, 12 insertions, 25 deletions
diff --git a/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp b/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp
index 3ecd684c1e39..e76f9e12f0af 100644
--- a/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp
+++ b/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp
@@ -55,9 +55,12 @@ Optional<TypeIndex> GlobalTypeTableBuilder::getNext(TypeIndex Prev) {
CVType GlobalTypeTableBuilder::getType(TypeIndex Index) {
CVType Type;
Type.RecordData = SeenRecords[Index.toArrayIndex()];
- const RecordPrefix *P =
- reinterpret_cast<const RecordPrefix *>(Type.RecordData.data());
- Type.Type = static_cast<TypeLeafKind>(uint16_t(P->RecordKind));
+ if (!Type.RecordData.empty()) {
+ assert(Type.RecordData.size() >= sizeof(RecordPrefix));
+ const RecordPrefix *P =
+ reinterpret_cast<const RecordPrefix *>(Type.RecordData.data());
+ Type.Type = static_cast<TypeLeafKind>(uint16_t(P->RecordKind));
+ }
return Type;
}
@@ -89,31 +92,15 @@ void GlobalTypeTableBuilder::reset() {
SeenRecords.clear();
}
-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());
-}
-
-TypeIndex GlobalTypeTableBuilder::insertRecordAs(GloballyHashedType Hash,
- CreateRecord Create) {
- auto Result = HashedRecords.try_emplace(Hash, nextTypeIndex());
-
- if (Result.second) {
- ArrayRef<uint8_t> RecordData = stabilize(RecordStorage, Create());
- SeenRecords.push_back(RecordData);
- SeenHashes.push_back(Hash);
- }
-
- // Update the caller's copy of Record to point a stable copy.
- return Result.first->second;
-}
-
TypeIndex GlobalTypeTableBuilder::insertRecordBytes(ArrayRef<uint8_t> Record) {
GloballyHashedType GHT =
GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
- return insertRecordAs(GHT, [Record]() { return Record; });
+ return insertRecordAs(GHT, Record.size(),
+ [Record](MutableArrayRef<uint8_t> Data) {
+ assert(Data.size() == Record.size());
+ ::memcpy(Data.data(), Record.data(), Record.size());
+ return Data;
+ });
}
TypeIndex