@@ -3357,20 +3357,11 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
3357
3357
" duplicate TYPE_OFFSET record in AST file" );
3358
3358
F.TypeOffsets = reinterpret_cast <const UnalignedUInt64 *>(Blob.data ());
3359
3359
F.LocalNumTypes = Record[0 ];
3360
- unsigned LocalBaseTypeIndex = Record[1 ];
3361
3360
F.BaseTypeIndex = getTotalNumTypes ();
3362
3361
3363
- if (F.LocalNumTypes > 0 ) {
3364
- // Introduce the global -> local mapping for types within this module.
3365
- GlobalTypeMap.insert (std::make_pair (getTotalNumTypes (), &F));
3366
-
3367
- // Introduce the local -> global mapping for types within this module.
3368
- F.TypeRemap .insertOrReplace (
3369
- std::make_pair (LocalBaseTypeIndex,
3370
- F.BaseTypeIndex - LocalBaseTypeIndex));
3371
-
3362
+ if (F.LocalNumTypes > 0 )
3372
3363
TypesLoaded.resize (TypesLoaded.size () + F.LocalNumTypes );
3373
- }
3364
+
3374
3365
break ;
3375
3366
}
3376
3367
@@ -4033,7 +4024,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4033
4024
RemapBuilder PreprocessedEntityRemap (F.PreprocessedEntityRemap );
4034
4025
RemapBuilder SubmoduleRemap (F.SubmoduleRemap );
4035
4026
RemapBuilder SelectorRemap (F.SelectorRemap );
4036
- RemapBuilder TypeRemap (F.TypeRemap );
4037
4027
4038
4028
auto &ImportedModuleVector = F.DependentModules ;
4039
4029
assert (ImportedModuleVector.empty ());
@@ -4069,8 +4059,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4069
4059
endian::readNext<uint32_t , llvm::endianness::little>(Data);
4070
4060
uint32_t SelectorIDOffset =
4071
4061
endian::readNext<uint32_t , llvm::endianness::little>(Data);
4072
- uint32_t TypeIndexOffset =
4073
- endian::readNext<uint32_t , llvm::endianness::little>(Data);
4074
4062
4075
4063
auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset,
4076
4064
RemapBuilder &Remap) {
@@ -4085,7 +4073,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4085
4073
PreprocessedEntityRemap);
4086
4074
mapOffset (SubmoduleIDOffset, OM->BaseSubmoduleID , SubmoduleRemap);
4087
4075
mapOffset (SelectorIDOffset, OM->BaseSelectorID , SelectorRemap);
4088
- mapOffset (TypeIndexOffset, OM->BaseTypeIndex , TypeRemap);
4089
4076
}
4090
4077
}
4091
4078
@@ -5064,12 +5051,12 @@ void ASTReader::InitializeContext() {
5064
5051
5065
5052
// Load the special types.
5066
5053
if (SpecialTypes.size () >= NumSpecialTypeIDs) {
5067
- if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
5054
+ if (TypeID String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
5068
5055
if (!Context.CFConstantStringTypeDecl )
5069
5056
Context.setCFConstantStringType (GetType (String));
5070
5057
}
5071
5058
5072
- if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) {
5059
+ if (TypeID File = SpecialTypes[SPECIAL_TYPE_FILE]) {
5073
5060
QualType FileType = GetType (File);
5074
5061
if (FileType.isNull ()) {
5075
5062
Error (" FILE type is NULL" );
@@ -5090,7 +5077,7 @@ void ASTReader::InitializeContext() {
5090
5077
}
5091
5078
}
5092
5079
5093
- if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) {
5080
+ if (TypeID Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) {
5094
5081
QualType Jmp_bufType = GetType (Jmp_buf);
5095
5082
if (Jmp_bufType.isNull ()) {
5096
5083
Error (" jmp_buf type is NULL" );
@@ -5111,7 +5098,7 @@ void ASTReader::InitializeContext() {
5111
5098
}
5112
5099
}
5113
5100
5114
- if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) {
5101
+ if (TypeID Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) {
5115
5102
QualType Sigjmp_bufType = GetType (Sigjmp_buf);
5116
5103
if (Sigjmp_bufType.isNull ()) {
5117
5104
Error (" sigjmp_buf type is NULL" );
@@ -5129,25 +5116,24 @@ void ASTReader::InitializeContext() {
5129
5116
}
5130
5117
}
5131
5118
5132
- if (unsigned ObjCIdRedef
5133
- = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) {
5119
+ if (TypeID ObjCIdRedef = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) {
5134
5120
if (Context.ObjCIdRedefinitionType .isNull ())
5135
5121
Context.ObjCIdRedefinitionType = GetType (ObjCIdRedef);
5136
5122
}
5137
5123
5138
- if (unsigned ObjCClassRedef
5139
- = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) {
5124
+ if (TypeID ObjCClassRedef =
5125
+ SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) {
5140
5126
if (Context.ObjCClassRedefinitionType .isNull ())
5141
5127
Context.ObjCClassRedefinitionType = GetType (ObjCClassRedef);
5142
5128
}
5143
5129
5144
- if (unsigned ObjCSelRedef
5145
- = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) {
5130
+ if (TypeID ObjCSelRedef =
5131
+ SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) {
5146
5132
if (Context.ObjCSelRedefinitionType .isNull ())
5147
5133
Context.ObjCSelRedefinitionType = GetType (ObjCSelRedef);
5148
5134
}
5149
5135
5150
- if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) {
5136
+ if (TypeID Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) {
5151
5137
QualType Ucontext_tType = GetType (Ucontext_t);
5152
5138
if (Ucontext_tType.isNull ()) {
5153
5139
Error (" ucontext_t type is NULL" );
@@ -6632,10 +6618,8 @@ void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) {
6632
6618
}
6633
6619
6634
6620
// / Get the correct cursor and offset for loading a type.
6635
- ASTReader::RecordLocation ASTReader::TypeCursorForIndex (unsigned Index) {
6636
- GlobalTypeMapType::iterator I = GlobalTypeMap.find (Index);
6637
- assert (I != GlobalTypeMap.end () && " Corrupted global type map" );
6638
- ModuleFile *M = I->second ;
6621
+ ASTReader::RecordLocation ASTReader::TypeCursorForIndex (TypeID ID) {
6622
+ auto [M, Index] = translateTypeIDToIndex (ID);
6639
6623
return RecordLocation (M, M->TypeOffsets [Index - M->BaseTypeIndex ].get () +
6640
6624
M->DeclsBlockStartOffset );
6641
6625
}
@@ -6656,10 +6640,10 @@ static std::optional<Type::TypeClass> getTypeClassForCode(TypeCode code) {
6656
6640
// / routine actually reads the record corresponding to the type at the given
6657
6641
// / location. It is a helper routine for GetType, which deals with reading type
6658
6642
// / IDs.
6659
- QualType ASTReader::readTypeRecord (unsigned Index ) {
6643
+ QualType ASTReader::readTypeRecord (TypeID ID ) {
6660
6644
assert (ContextObj && " reading type with no AST context" );
6661
6645
ASTContext &Context = *ContextObj;
6662
- RecordLocation Loc = TypeCursorForIndex (Index );
6646
+ RecordLocation Loc = TypeCursorForIndex (ID );
6663
6647
BitstreamCursor &DeclsCursor = Loc.F ->DeclsCursor ;
6664
6648
6665
6649
// Keep track of where we are in the stream, then jump back there
@@ -7100,14 +7084,25 @@ TypeSourceInfo *ASTRecordReader::readTypeSourceInfo() {
7100
7084
return TInfo;
7101
7085
}
7102
7086
7087
+ std::pair<ModuleFile *, unsigned >
7088
+ ASTReader::translateTypeIDToIndex (serialization::TypeID ID) const {
7089
+ unsigned Index =
7090
+ (ID & llvm::maskTrailingOnes<TypeID>(32 )) >> Qualifiers::FastWidth;
7091
+
7092
+ ModuleFile *OwningModuleFile = getOwningModuleFile (ID);
7093
+ assert (OwningModuleFile &&
7094
+ " untranslated type ID or local type ID shouldn't be in TypesLoaded" );
7095
+ return {OwningModuleFile, OwningModuleFile->BaseTypeIndex + Index};
7096
+ }
7097
+
7103
7098
QualType ASTReader::GetType (TypeID ID) {
7104
7099
assert (ContextObj && " reading type with no AST context" );
7105
7100
ASTContext &Context = *ContextObj;
7106
7101
7107
7102
unsigned FastQuals = ID & Qualifiers::FastMask;
7108
- unsigned Index = ID >> Qualifiers::FastWidth;
7109
7103
7110
- if (Index < NUM_PREDEF_TYPE_IDS) {
7104
+ if (uint64_t Index = ID >> Qualifiers::FastWidth;
7105
+ Index < NUM_PREDEF_TYPE_IDS) {
7111
7106
QualType T;
7112
7107
switch ((PredefinedTypeIDs)Index) {
7113
7108
case PREDEF_TYPE_LAST_ID:
@@ -7376,10 +7371,11 @@ QualType ASTReader::GetType(TypeID ID) {
7376
7371
return T.withFastQualifiers (FastQuals);
7377
7372
}
7378
7373
7379
- Index -= NUM_PREDEF_TYPE_IDS;
7374
+ unsigned Index = translateTypeIDToIndex (ID).second ;
7375
+
7380
7376
assert (Index < TypesLoaded.size () && " Type index out-of-range" );
7381
7377
if (TypesLoaded[Index].isNull ()) {
7382
- TypesLoaded[Index] = readTypeRecord (Index );
7378
+ TypesLoaded[Index] = readTypeRecord (ID );
7383
7379
if (TypesLoaded[Index].isNull ())
7384
7380
return QualType ();
7385
7381
@@ -7392,27 +7388,28 @@ QualType ASTReader::GetType(TypeID ID) {
7392
7388
return TypesLoaded[Index].withFastQualifiers (FastQuals);
7393
7389
}
7394
7390
7395
- QualType ASTReader::getLocalType (ModuleFile &F, unsigned LocalID) {
7391
+ QualType ASTReader::getLocalType (ModuleFile &F, TypeID LocalID) {
7396
7392
return GetType (getGlobalTypeID (F, LocalID));
7397
7393
}
7398
7394
7399
- serialization::TypeID
7400
- ASTReader::getGlobalTypeID (ModuleFile &F, unsigned LocalID) const {
7401
- unsigned FastQuals = LocalID & Qualifiers::FastMask;
7402
- unsigned LocalIndex = LocalID >> Qualifiers::FastWidth;
7403
-
7404
- if (LocalIndex < NUM_PREDEF_TYPE_IDS)
7395
+ serialization::TypeID ASTReader::getGlobalTypeID (ModuleFile &F,
7396
+ TypeID LocalID) const {
7397
+ if ((LocalID >> Qualifiers::FastWidth) < NUM_PREDEF_TYPE_IDS)
7405
7398
return LocalID;
7406
7399
7407
7400
if (!F.ModuleOffsetMap .empty ())
7408
7401
ReadModuleOffsetMap (F);
7409
7402
7410
- ContinuousRangeMap<uint32_t , int , 2 >::iterator I
7411
- = F.TypeRemap .find (LocalIndex - NUM_PREDEF_TYPE_IDS);
7412
- assert (I != F.TypeRemap .end () && " Invalid index into type index remap" );
7403
+ unsigned ModuleFileIndex = LocalID >> 32 ;
7404
+ LocalID &= llvm::maskTrailingOnes<TypeID>(32 );
7413
7405
7414
- unsigned GlobalIndex = LocalIndex + I->second ;
7415
- return (GlobalIndex << Qualifiers::FastWidth) | FastQuals;
7406
+ if (ModuleFileIndex == 0 )
7407
+ LocalID -= NUM_PREDEF_TYPE_IDS << Qualifiers::FastWidth;
7408
+
7409
+ ModuleFile &MF =
7410
+ ModuleFileIndex ? *F.DependentModules [ModuleFileIndex - 1 ] : F;
7411
+ ModuleFileIndex = MF.Index + 1 ;
7412
+ return ((uint64_t )ModuleFileIndex << 32 ) | LocalID;
7416
7413
}
7417
7414
7418
7415
TemplateArgumentLocInfo
@@ -7650,6 +7647,16 @@ ModuleFile *ASTReader::getOwningModuleFile(GlobalDeclID ID) const {
7650
7647
return &getModuleManager ()[ModuleFileIndex - 1 ];
7651
7648
}
7652
7649
7650
+ ModuleFile *ASTReader::getOwningModuleFile (TypeID ID) const {
7651
+ if (ID < NUM_PREDEF_TYPE_IDS)
7652
+ return nullptr ;
7653
+
7654
+ uint64_t ModuleFileIndex = ID >> 32 ;
7655
+ assert (ModuleFileIndex && " Untranslated Local Decl?" );
7656
+
7657
+ return &getModuleManager ()[ModuleFileIndex - 1 ];
7658
+ }
7659
+
7653
7660
ModuleFile *ASTReader::getOwningModuleFile (const Decl *D) const {
7654
7661
if (!D->isFromASTFile ())
7655
7662
return nullptr ;
@@ -8167,7 +8174,6 @@ LLVM_DUMP_METHOD void ASTReader::dump() {
8167
8174
llvm::errs () << " *** PCH/ModuleFile Remappings:\n " ;
8168
8175
dumpModuleIDMap (" Global bit offset map" , GlobalBitOffsetsMap);
8169
8176
dumpModuleIDMap (" Global source location entry map" , GlobalSLocEntryMap);
8170
- dumpModuleIDMap (" Global type map" , GlobalTypeMap);
8171
8177
dumpModuleIDMap (" Global macro map" , GlobalMacroMap);
8172
8178
dumpModuleIDMap (" Global submodule map" , GlobalSubmoduleMap);
8173
8179
dumpModuleIDMap (" Global selector map" , GlobalSelectorMap);
0 commit comments