@@ -949,9 +949,13 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
949
949
// If we have no includer, that means we're processing a #include
950
950
// from a module build. We should treat this as a system header if we're
951
951
// building a [system] module.
952
- bool IncluderIsSystemHeader =
953
- Includer ? getFileInfo (Includer).DirInfo != SrcMgr::C_User :
954
- BuildSystemModule;
952
+ bool IncluderIsSystemHeader = [&]() {
953
+ if (!Includer)
954
+ return BuildSystemModule;
955
+ const HeaderFileInfo *HFI = getExistingFileInfo (Includer);
956
+ assert (HFI && " includer without file info" );
957
+ return HFI->DirInfo != SrcMgr::C_User;
958
+ }();
955
959
if (OptionalFileEntryRef FE = getFileAndSuggestModule (
956
960
TmpDir, IncludeLoc, IncluderAndDir.second , IncluderIsSystemHeader,
957
961
RequestingModule, SuggestedModule)) {
@@ -966,10 +970,11 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
966
970
// Note that we only use one of FromHFI/ToHFI at once, due to potential
967
971
// reallocation of the underlying vector potentially making the first
968
972
// reference binding dangling.
969
- HeaderFileInfo &FromHFI = getFileInfo (Includer);
970
- unsigned DirInfo = FromHFI.DirInfo ;
971
- bool IndexHeaderMapHeader = FromHFI.IndexHeaderMapHeader ;
972
- StringRef Framework = FromHFI.Framework ;
973
+ const HeaderFileInfo *FromHFI = getExistingFileInfo (Includer);
974
+ assert (FromHFI && " includer without file info" );
975
+ unsigned DirInfo = FromHFI->DirInfo ;
976
+ bool IndexHeaderMapHeader = FromHFI->IndexHeaderMapHeader ;
977
+ StringRef Framework = FromHFI->Framework ;
973
978
974
979
HeaderFileInfo &ToHFI = getFileInfo (&FE->getFileEntry ());
975
980
ToHFI.DirInfo = DirInfo;
@@ -1158,10 +1163,12 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
1158
1163
// "Foo" is the name of the framework in which the including header was found.
1159
1164
if (!Includers.empty () && Includers.front ().first && !isAngled &&
1160
1165
!Filename.contains (' /' )) {
1161
- HeaderFileInfo &IncludingHFI = getFileInfo (Includers.front ().first );
1162
- if (IncludingHFI.IndexHeaderMapHeader ) {
1166
+ const HeaderFileInfo *IncludingHFI =
1167
+ getExistingFileInfo (Includers.front ().first );
1168
+ assert (IncludingHFI && " includer without file info" );
1169
+ if (IncludingHFI->IndexHeaderMapHeader ) {
1163
1170
SmallString<128 > ScratchFilename;
1164
- ScratchFilename += IncludingHFI. Framework ;
1171
+ ScratchFilename += IncludingHFI-> Framework ;
1165
1172
ScratchFilename += ' /' ;
1166
1173
ScratchFilename += Filename;
1167
1174
@@ -1294,11 +1301,11 @@ OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader(
1294
1301
}
1295
1302
1296
1303
// This file is a system header or C++ unfriendly if the old file is.
1297
- //
1298
- // Note that the temporary 'DirInfo' is required here, as either call to
1299
- // getFileInfo could resize the vector and we don't want to rely on order
1300
- // of evaluation .
1301
- unsigned DirInfo = getFileInfo (ContextFileEnt). DirInfo ;
1304
+ const HeaderFileInfo *ContextHFI = getExistingFileInfo (ContextFileEnt);
1305
+ assert (ContextHFI && " context file without file info " );
1306
+ // Note that the temporary 'DirInfo' is required here, as the call to
1307
+ // getFileInfo could resize the vector and might invalidate 'ContextHFI' .
1308
+ unsigned DirInfo = ContextHFI-> DirInfo ;
1302
1309
getFileInfo (&File->getFileEntry ()).DirInfo = DirInfo;
1303
1310
1304
1311
FrameworkName.pop_back (); // remove the trailing '/'
@@ -1356,8 +1363,6 @@ static void mergeHeaderFileInfo(HeaderFileInfo &HFI,
1356
1363
HFI.Framework = OtherHFI.Framework ;
1357
1364
}
1358
1365
1359
- // / getFileInfo - Return the HeaderFileInfo structure for the specified
1360
- // / FileEntry.
1361
1366
HeaderFileInfo &HeaderSearch::getFileInfo (const FileEntry *FE) {
1362
1367
if (FE->getUID () >= FileInfo.size ())
1363
1368
FileInfo.resize (FE->getUID () + 1 );
@@ -1374,28 +1379,20 @@ HeaderFileInfo &HeaderSearch::getFileInfo(const FileEntry *FE) {
1374
1379
}
1375
1380
1376
1381
HFI->IsValid = true ;
1377
- // We have local information about this header file, so it's no longer
1378
- // strictly external.
1382
+ // We assume the caller has local information about this header file, so it's
1383
+ // no longer strictly external.
1379
1384
HFI->External = false ;
1380
1385
return *HFI;
1381
1386
}
1382
1387
1383
- const HeaderFileInfo *
1384
- HeaderSearch::getExistingFileInfo (const FileEntry *FE,
1385
- bool WantExternal) const {
1386
- // If we have an external source, ensure we have the latest information.
1387
- // FIXME: Use a generation count to check whether this is really up to date.
1388
+ const HeaderFileInfo *HeaderSearch::getExistingFileInfo (const FileEntry *FE) const {
1388
1389
HeaderFileInfo *HFI;
1389
1390
if (ExternalSource) {
1390
- if (FE->getUID () >= FileInfo.size ()) {
1391
- if (!WantExternal)
1392
- return nullptr ;
1391
+ if (FE->getUID () >= FileInfo.size ())
1393
1392
FileInfo.resize (FE->getUID () + 1 );
1394
- }
1395
1393
1396
1394
HFI = &FileInfo[FE->getUID ()];
1397
- if (!WantExternal && (!HFI->IsValid || HFI->External ))
1398
- return nullptr ;
1395
+ // FIXME: Use a generation count to check whether this is really up to date.
1399
1396
if (!HFI->Resolved ) {
1400
1397
auto ExternalHFI = ExternalSource->GetHeaderFileInfo (FE);
1401
1398
if (ExternalHFI.IsValid ) {
@@ -1404,16 +1401,25 @@ HeaderSearch::getExistingFileInfo(const FileEntry *FE,
1404
1401
mergeHeaderFileInfo (*HFI, ExternalHFI);
1405
1402
}
1406
1403
}
1407
- } else if (FE->getUID () >= FileInfo.size ()) {
1408
- return nullptr ;
1409
- } else {
1404
+ } else if (FE->getUID () < FileInfo.size ()) {
1410
1405
HFI = &FileInfo[FE->getUID ()];
1406
+ } else {
1407
+ HFI = nullptr ;
1411
1408
}
1412
1409
1413
- if (!HFI->IsValid || (HFI->External && !WantExternal))
1414
- return nullptr ;
1410
+ return (HFI && HFI->IsValid ) ? HFI : nullptr ;
1411
+ }
1412
+
1413
+ const HeaderFileInfo *
1414
+ HeaderSearch::getExistingLocalFileInfo (const FileEntry *FE) const {
1415
+ HeaderFileInfo *HFI;
1416
+ if (FE->getUID () < FileInfo.size ()) {
1417
+ HFI = &FileInfo[FE->getUID ()];
1418
+ } else {
1419
+ HFI = nullptr ;
1420
+ }
1415
1421
1416
- return HFI;
1422
+ return ( HFI && HFI-> IsValid && !HFI-> External ) ? HFI : nullptr ;
1417
1423
}
1418
1424
1419
1425
bool HeaderSearch::isFileMultipleIncludeGuarded (const FileEntry *File) const {
0 commit comments