@@ -3092,98 +3092,97 @@ ASTReader::ReadControlBlock(ModuleFile &F,
3092
3092
break;
3093
3093
}
3094
3094
3095
- case IMPORTS : {
3095
+ case IMPORT : {
3096
3096
// Validate the AST before processing any imports (otherwise, untangling
3097
3097
// them can be error-prone and expensive). A module will have a name and
3098
3098
// will already have been validated, but this catches the PCH case.
3099
3099
if (ASTReadResult Result = readUnhashedControlBlockOnce())
3100
3100
return Result;
3101
3101
3102
- // Load each of the imported PCH files.
3103
- unsigned Idx = 0, N = Record.size();
3104
- while (Idx < N) {
3105
- // Read information about the AST file.
3106
- ModuleKind ImportedKind = (ModuleKind)Record[Idx++];
3107
- // Whether we're importing a standard c++ module.
3108
- bool IsImportingStdCXXModule = Record[Idx++];
3109
- // The import location will be the local one for now; we will adjust
3110
- // all import locations of module imports after the global source
3111
- // location info are setup, in ReadAST.
3112
- auto [ImportLoc, ImportModuleFileIndex] =
3113
- ReadUntranslatedSourceLocation(Record[Idx++]);
3114
- // The import location must belong to the current module file itself.
3115
- assert(ImportModuleFileIndex == 0);
3116
- off_t StoredSize = !IsImportingStdCXXModule ? (off_t)Record[Idx++] : 0;
3117
- time_t StoredModTime =
3118
- !IsImportingStdCXXModule ? (time_t)Record[Idx++] : 0;
3119
-
3120
- ASTFileSignature StoredSignature;
3121
- if (!IsImportingStdCXXModule) {
3122
- auto FirstSignatureByte = Record.begin() + Idx;
3123
- StoredSignature = ASTFileSignature::create(
3124
- FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
3125
- Idx += ASTFileSignature::size;
3126
- }
3102
+ unsigned Idx = 0;
3103
+ // Read information about the AST file.
3104
+ ModuleKind ImportedKind = (ModuleKind)Record[Idx++];
3105
+
3106
+ // The import location will be the local one for now; we will adjust
3107
+ // all import locations of module imports after the global source
3108
+ // location info are setup, in ReadAST.
3109
+ auto [ImportLoc, ImportModuleFileIndex] =
3110
+ ReadUntranslatedSourceLocation(Record[Idx++]);
3111
+ // The import location must belong to the current module file itself.
3112
+ assert(ImportModuleFileIndex == 0);
3113
+
3114
+ StringRef ImportedName = ReadStringBlob(Record, Idx, Blob);
3115
+
3116
+ bool IsImportingStdCXXModule = Record[Idx++];
3117
+
3118
+ off_t StoredSize = 0;
3119
+ time_t StoredModTime = 0;
3120
+ ASTFileSignature StoredSignature;
3121
+ std::string ImportedFile;
3122
+
3123
+ // For prebuilt and explicit modules first consult the file map for
3124
+ // an override. Note that here we don't search prebuilt module
3125
+ // directories if we're not importing standard c++ module, only the
3126
+ // explicit name to file mappings. Also, we will still verify the
3127
+ // size/signature making sure it is essentially the same file but
3128
+ // perhaps in a different location.
3129
+ if (ImportedKind == MK_PrebuiltModule || ImportedKind == MK_ExplicitModule)
3130
+ ImportedFile = PP.getHeaderSearchInfo().getPrebuiltModuleFileName(
3131
+ ImportedName, /*FileMapOnly*/ !IsImportingStdCXXModule);
3132
+
3133
+ if (IsImportingStdCXXModule && ImportedFile.empty()) {
3134
+ Diag(diag::err_failed_to_find_module_file) << ImportedName;
3135
+ return Missing;
3136
+ }
3127
3137
3128
- std::string ImportedName = ReadString(Record, Idx);
3129
- std::string ImportedFile;
3130
-
3131
- // For prebuilt and explicit modules first consult the file map for
3132
- // an override. Note that here we don't search prebuilt module
3133
- // directories if we're not importing standard c++ module, only the
3134
- // explicit name to file mappings. Also, we will still verify the
3135
- // size/signature making sure it is essentially the same file but
3136
- // perhaps in a different location.
3137
- if (ImportedKind == MK_PrebuiltModule || ImportedKind == MK_ExplicitModule)
3138
- ImportedFile = PP.getHeaderSearchInfo().getPrebuiltModuleFileName(
3139
- ImportedName, /*FileMapOnly*/ !IsImportingStdCXXModule);
3140
-
3141
- // For C++20 Modules, we won't record the path to the imported modules
3142
- // in the BMI
3143
- if (!IsImportingStdCXXModule) {
3144
- if (ImportedFile.empty()) {
3145
- // Use BaseDirectoryAsWritten to ensure we use the same path in the
3146
- // ModuleCache as when writing.
3147
- ImportedFile = ReadPath(BaseDirectoryAsWritten, Record, Idx);
3148
- } else
3149
- SkipPath(Record, Idx);
3150
- } else if (ImportedFile.empty()) {
3151
- Diag(clang::diag::err_failed_to_find_module_file) << ImportedName;
3152
- return Missing;
3153
- }
3138
+ if (!IsImportingStdCXXModule) {
3139
+ StoredSize = (off_t)Record[Idx++];
3140
+ StoredModTime = (time_t)Record[Idx++];
3154
3141
3155
- // If our client can't cope with us being out of date, we can't cope with
3156
- // our dependency being missing.
3157
- unsigned Capabilities = ClientLoadCapabilities;
3158
- if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3159
- Capabilities &= ~ARR_Missing;
3160
-
3161
- // Load the AST file.
3162
- auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F,
3163
- Loaded, StoredSize, StoredModTime,
3164
- StoredSignature, Capabilities);
3165
-
3166
- // If we diagnosed a problem, produce a backtrace.
3167
- bool recompilingFinalized =
3168
- Result == OutOfDate && (Capabilities & ARR_OutOfDate) &&
3169
- getModuleManager().getModuleCache().isPCMFinal(F.FileName);
3170
- if (isDiagnosedResult(Result, Capabilities) || recompilingFinalized)
3171
- Diag(diag::note_module_file_imported_by)
3172
- << F.FileName << !F.ModuleName.empty() << F.ModuleName;
3173
- if (recompilingFinalized)
3174
- Diag(diag::note_module_file_conflict);
3175
-
3176
- switch (Result) {
3177
- case Failure: return Failure;
3178
- // If we have to ignore the dependency, we'll have to ignore this too.
3179
- case Missing:
3180
- case OutOfDate: return OutOfDate;
3181
- case VersionMismatch: return VersionMismatch;
3182
- case ConfigurationMismatch: return ConfigurationMismatch;
3183
- case HadErrors: return HadErrors;
3184
- case Success: break;
3142
+ StringRef SignatureBytes = Blob.substr(0, ASTFileSignature::size);
3143
+ StoredSignature = ASTFileSignature::create(SignatureBytes.begin(),
3144
+ SignatureBytes.end());
3145
+ Blob = Blob.substr(ASTFileSignature::size);
3146
+
3147
+ if (ImportedFile.empty()) {
3148
+ // Use BaseDirectoryAsWritten to ensure we use the same path in the
3149
+ // ModuleCache as when writing.
3150
+ ImportedFile =
3151
+ ReadPathBlob(BaseDirectoryAsWritten, Record, Idx, Blob);
3185
3152
}
3186
3153
}
3154
+
3155
+ // If our client can't cope with us being out of date, we can't cope with
3156
+ // our dependency being missing.
3157
+ unsigned Capabilities = ClientLoadCapabilities;
3158
+ if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
3159
+ Capabilities &= ~ARR_Missing;
3160
+
3161
+ // Load the AST file.
3162
+ auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F,
3163
+ Loaded, StoredSize, StoredModTime,
3164
+ StoredSignature, Capabilities);
3165
+
3166
+ // If we diagnosed a problem, produce a backtrace.
3167
+ bool recompilingFinalized =
3168
+ Result == OutOfDate && (Capabilities & ARR_OutOfDate) &&
3169
+ getModuleManager().getModuleCache().isPCMFinal(F.FileName);
3170
+ if (isDiagnosedResult(Result, Capabilities) || recompilingFinalized)
3171
+ Diag(diag::note_module_file_imported_by)
3172
+ << F.FileName << !F.ModuleName.empty() << F.ModuleName;
3173
+ if (recompilingFinalized)
3174
+ Diag(diag::note_module_file_conflict);
3175
+
3176
+ switch (Result) {
3177
+ case Failure: return Failure;
3178
+ // If we have to ignore the dependency, we'll have to ignore this too.
3179
+ case Missing:
3180
+ case OutOfDate: return OutOfDate;
3181
+ case VersionMismatch: return VersionMismatch;
3182
+ case ConfigurationMismatch: return ConfigurationMismatch;
3183
+ case HadErrors: return HadErrors;
3184
+ case Success: break;
3185
+ }
3187
3186
break;
3188
3187
}
3189
3188
@@ -5624,36 +5623,38 @@ bool ASTReader::readASTFileControlBlock(
5624
5623
break;
5625
5624
}
5626
5625
5627
- case IMPORTS : {
5626
+ case IMPORT : {
5628
5627
if (!NeedsImports)
5629
5628
break;
5630
5629
5631
- unsigned Idx = 0, N = Record.size();
5632
- while (Idx < N) {
5633
- // Read information about the AST file.
5630
+ unsigned Idx = 0;
5631
+ // Read information about the AST file.
5632
+
5633
+ // Skip Kind
5634
+ Idx++;
5634
5635
5635
- // Skip Kind
5636
- Idx++;
5637
- bool IsStandardCXXModule = Record[Idx++];
5636
+ // Skip ImportLoc
5637
+ Idx++;
5638
5638
5639
- // Skip ImportLoc
5640
- Idx++;
5639
+ StringRef ModuleName = ReadStringBlob(Record, Idx, Blob);
5641
5640
5642
- // In C++20 Modules, we don't record the path to imported
5643
- // modules in the BMI files.
5644
- if (IsStandardCXXModule) {
5645
- std::string ModuleName = ReadString(Record, Idx);
5646
- Listener.visitImport(ModuleName, /*Filename=*/"");
5647
- continue;
5648
- }
5641
+ bool IsStandardCXXModule = Record[Idx++];
5649
5642
5650
- // Skip Size, ModTime and Signature
5651
- Idx += 1 + 1 + ASTFileSignature::size;
5652
- std::string ModuleName = ReadString(Record, Idx);
5653
- std::string FilenameStr = ReadString(Record, Idx);
5654
- auto Filename = ResolveImportedPath(PathBuf, FilenameStr, ModuleDir);
5655
- Listener.visitImport(ModuleName, *Filename);
5643
+ // In C++20 Modules, we don't record the path to imported
5644
+ // modules in the BMI files.
5645
+ if (IsStandardCXXModule) {
5646
+ Listener.visitImport(ModuleName, /*Filename=*/"");
5647
+ continue;
5656
5648
}
5649
+
5650
+ // Skip Size and ModTime.
5651
+ Idx += 1 + 1;
5652
+ // Skip signature.
5653
+ Blob = Blob.substr(ASTFileSignature::size);
5654
+
5655
+ StringRef FilenameStr = ReadStringBlob(Record, Idx, Blob);
5656
+ auto Filename = ResolveImportedPath(PathBuf, FilenameStr, ModuleDir);
5657
+ Listener.visitImport(ModuleName, *Filename);
5657
5658
break;
5658
5659
}
5659
5660
@@ -9602,6 +9603,14 @@ std::string ASTReader::ReadString(const RecordDataImpl &Record, unsigned &Idx) {
9602
9603
return Result;
9603
9604
}
9604
9605
9606
+ StringRef ASTReader::ReadStringBlob(const RecordDataImpl &Record, unsigned &Idx,
9607
+ StringRef &Blob) {
9608
+ unsigned Len = Record[Idx++];
9609
+ StringRef Result = Blob.substr(0, Len);
9610
+ Blob = Blob.substr(Len);
9611
+ return Result;
9612
+ }
9613
+
9605
9614
std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record,
9606
9615
unsigned &Idx) {
9607
9616
return ReadPath(F.BaseDirectory, Record, Idx);
@@ -9613,6 +9622,13 @@ std::string ASTReader::ReadPath(StringRef BaseDirectory,
9613
9622
return ResolveImportedPathAndAllocate(PathBuf, Filename, BaseDirectory);
9614
9623
}
9615
9624
9625
+ std::string ASTReader::ReadPathBlob(StringRef BaseDirectory,
9626
+ const RecordData &Record, unsigned &Idx,
9627
+ StringRef &Blob) {
9628
+ StringRef Filename = ReadStringBlob(Record, Idx, Blob);
9629
+ return ResolveImportedPathAndAllocate(PathBuf, Filename, BaseDirectory);
9630
+ }
9631
+
9616
9632
VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record,
9617
9633
unsigned &Idx) {
9618
9634
unsigned Major = Record[Idx++];
0 commit comments