@@ -7084,15 +7084,34 @@ TypeSourceInfo *ASTRecordReader::readTypeSourceInfo() {
70847084 return TInfo;
70857085}
70867086
7087+ static unsigned getIndexForTypeID (serialization::TypeID ID) {
7088+ return (ID & llvm::maskTrailingOnes<TypeID>(32 )) >> Qualifiers::FastWidth;
7089+ ;
7090+ }
7091+
7092+ static unsigned getModuleFileIndexForTypeID (serialization::TypeID ID) {
7093+ return ID >> 32 ;
7094+ }
7095+
7096+ static bool isPredefinedTypes (serialization::TypeID ID) {
7097+ // We don't need to erase the higher bits since if these bits are not 0,
7098+ // it must be larger than NUM_PREDEF_TYPE_IDS.
7099+ return (ID >> Qualifiers::FastWidth) < NUM_PREDEF_TYPE_IDS;
7100+ }
7101+
70877102std::pair<ModuleFile *, unsigned >
70887103ASTReader::translateTypeIDToIndex (serialization::TypeID ID) const {
7089- unsigned Index =
7090- (ID & llvm::maskTrailingOnes<TypeID>(32 )) >> Qualifiers::FastWidth;
7104+ assert (!isPredefinedTypes (ID) &&
7105+ " Predefined type shouldn't be in TypesLoaded" );
7106+ unsigned ModuleFileIndex = getModuleFileIndexForTypeID (ID);
7107+ assert (ModuleFileIndex && " Untranslated Local Decl?" );
70917108
7092- ModuleFile *OwningModuleFile = getOwningModuleFile (ID) ;
7109+ ModuleFile *OwningModuleFile = & getModuleManager ()[ModuleFileIndex - 1 ] ;
70937110 assert (OwningModuleFile &&
70947111 " untranslated type ID or local type ID shouldn't be in TypesLoaded" );
7095- return {OwningModuleFile, OwningModuleFile->BaseTypeIndex + Index};
7112+
7113+ return {OwningModuleFile,
7114+ OwningModuleFile->BaseTypeIndex + getIndexForTypeID (ID)};
70967115}
70977116
70987117QualType ASTReader::GetType (TypeID ID) {
@@ -7101,9 +7120,9 @@ QualType ASTReader::GetType(TypeID ID) {
71017120
71027121 unsigned FastQuals = ID & Qualifiers::FastMask;
71037122
7104- if (uint64_t Index = ID >> Qualifiers::FastWidth;
7105- Index < NUM_PREDEF_TYPE_IDS) {
7123+ if (isPredefinedTypes (ID)) {
71067124 QualType T;
7125+ unsigned Index = getIndexForTypeID (ID);
71077126 switch ((PredefinedTypeIDs)Index) {
71087127 case PREDEF_TYPE_LAST_ID:
71097128 // We should never use this one.
@@ -7394,13 +7413,13 @@ QualType ASTReader::getLocalType(ModuleFile &F, TypeID LocalID) {
73947413
73957414serialization::TypeID ASTReader::getGlobalTypeID (ModuleFile &F,
73967415 TypeID LocalID) const {
7397- if ((LocalID >> Qualifiers::FastWidth) < NUM_PREDEF_TYPE_IDS )
7416+ if (isPredefinedTypes (LocalID) )
73987417 return LocalID;
73997418
74007419 if (!F.ModuleOffsetMap .empty ())
74017420 ReadModuleOffsetMap (F);
74027421
7403- unsigned ModuleFileIndex = LocalID >> 32 ;
7422+ unsigned ModuleFileIndex = getModuleFileIndexForTypeID ( LocalID) ;
74047423 LocalID &= llvm::maskTrailingOnes<TypeID>(32 );
74057424
74067425 if (ModuleFileIndex == 0 )
@@ -7647,16 +7666,6 @@ ModuleFile *ASTReader::getOwningModuleFile(GlobalDeclID ID) const {
76477666 return &getModuleManager ()[ModuleFileIndex - 1 ];
76487667}
76497668
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-
76607669ModuleFile *ASTReader::getOwningModuleFile (const Decl *D) const {
76617670 if (!D->isFromASTFile ())
76627671 return nullptr ;
0 commit comments