Skip to content

Commit d49ef2d

Browse files
committed
[clang] Move VFS overlays from HeaderSearchOptions to FileSystemOptions
1 parent 3c02fea commit d49ef2d

File tree

12 files changed

+167
-162
lines changed

12 files changed

+167
-162
lines changed

clang/include/clang/Basic/FileSystemOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class FileSystemOptions {
2424
/// If set, paths are resolved as if the working directory was
2525
/// set to the value of WorkingDir.
2626
std::string WorkingDir;
27+
28+
/// The set of user-provided virtual filesystem overlay files.
29+
std::vector<std::string> VFSOverlayFiles;
2730
};
2831

2932
} // end namespace clang

clang/include/clang/Lex/HeaderSearchOptions.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ class HeaderSearchOptions {
187187
/// of computing the module hash.
188188
llvm::SmallSetVector<llvm::CachedHashString, 16> ModulesIgnoreMacros;
189189

190-
/// The set of user-provided virtual filesystem overlay files.
191-
std::vector<std::string> VFSOverlayFiles;
192-
193190
/// Include the compiler builtin includes.
194191
LLVM_PREFERRED_TYPE(bool)
195192
unsigned UseBuiltinIncludes : 1;
@@ -307,10 +304,6 @@ class HeaderSearchOptions {
307304
SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
308305
}
309306

310-
void AddVFSOverlayFile(StringRef Name) {
311-
VFSOverlayFiles.push_back(std::string(Name));
312-
}
313-
314307
void AddPrebuiltModulePath(StringRef Name) {
315308
PrebuiltModulePaths.push_back(std::string(Name));
316309
}

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,6 @@ enum OptionsRecordTypes {
392392
/// Record code for the target options table.
393393
TARGET_OPTIONS,
394394

395-
/// Record code for the filesystem options table.
396-
FILE_SYSTEM_OPTIONS,
397-
398395
/// Record code for the headers search options table.
399396
HEADER_SEARCH_OPTIONS,
400397

@@ -413,6 +410,9 @@ enum UnhashedControlBlockRecordTypes {
413410
/// Record code for the diagnostic options table.
414411
DIAGNOSTIC_OPTIONS,
415412

413+
/// Record code for the filesystem options table.
414+
FILE_SYSTEM_OPTIONS,
415+
416416
/// Record code for the headers search paths.
417417
HEADER_SEARCH_PATHS,
418418

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -517,24 +517,25 @@ namespace {
517517
class ASTInfoCollector : public ASTReaderListener {
518518
Preprocessor &PP;
519519
ASTContext *Context;
520+
FileSystemOptions &FSOpts;
520521
HeaderSearchOptions &HSOpts;
521522
PreprocessorOptions &PPOpts;
522523
LangOptions &LangOpt;
523524
std::shared_ptr<TargetOptions> &TargetOpts;
524525
IntrusiveRefCntPtr<TargetInfo> &Target;
525526
unsigned &Counter;
526527
bool InitializedLanguage = false;
527-
bool InitializedHeaderSearchPaths = false;
528+
bool InitializedFileSystem = false;
528529

529530
public:
530531
ASTInfoCollector(Preprocessor &PP, ASTContext *Context,
531-
HeaderSearchOptions &HSOpts, PreprocessorOptions &PPOpts,
532-
LangOptions &LangOpt,
532+
FileSystemOptions &FSOpts, HeaderSearchOptions &HSOpts,
533+
PreprocessorOptions &PPOpts, LangOptions &LangOpt,
533534
std::shared_ptr<TargetOptions> &TargetOpts,
534535
IntrusiveRefCntPtr<TargetInfo> &Target, unsigned &Counter)
535-
: PP(PP), Context(Context), HSOpts(HSOpts), PPOpts(PPOpts),
536-
LangOpt(LangOpt), TargetOpts(TargetOpts), Target(Target),
537-
Counter(Counter) {}
536+
: PP(PP), Context(Context), FSOpts(FSOpts), HSOpts(HSOpts),
537+
PPOpts(PPOpts), LangOpt(LangOpt), TargetOpts(TargetOpts),
538+
Target(Target), Counter(Counter) {}
538539

539540
bool ReadLanguageOptions(const LangOptions &LangOpts,
540541
StringRef ModuleFilename, bool Complain,
@@ -568,7 +569,6 @@ class ASTInfoCollector : public ASTReaderListener {
568569
this->HSOpts.ForceCheckCXX20ModulesInputFiles;
569570
llvm::SaveAndRestore X(this->HSOpts.UserEntries);
570571
llvm::SaveAndRestore Y(this->HSOpts.SystemHeaderPrefixes);
571-
llvm::SaveAndRestore Z(this->HSOpts.VFSOverlayFiles);
572572

573573
this->HSOpts = HSOpts;
574574
this->HSOpts.ForceCheckCXX20ModulesInputFiles =
@@ -577,24 +577,29 @@ class ASTInfoCollector : public ASTReaderListener {
577577
return false;
578578
}
579579

580-
bool ReadHeaderSearchPaths(const HeaderSearchOptions &HSOpts,
580+
bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
581581
bool Complain) override {
582-
if (InitializedHeaderSearchPaths)
582+
if (InitializedFileSystem)
583583
return false;
584584

585-
this->HSOpts.UserEntries = HSOpts.UserEntries;
586-
this->HSOpts.SystemHeaderPrefixes = HSOpts.SystemHeaderPrefixes;
587-
this->HSOpts.VFSOverlayFiles = HSOpts.VFSOverlayFiles;
585+
this->FSOpts.VFSOverlayFiles = FSOpts.VFSOverlayFiles;
588586

589587
// Initialize the FileManager. We can't do this in update(), since that
590588
// performs the initialization too late (once both target and language
591589
// options are read).
592590
PP.getFileManager().setVirtualFileSystem(createVFSFromOverlayFiles(
593-
HSOpts.VFSOverlayFiles, PP.getDiagnostics(),
591+
FSOpts.VFSOverlayFiles, PP.getDiagnostics(),
594592
PP.getFileManager().getVirtualFileSystemPtr()));
595593

596-
InitializedHeaderSearchPaths = true;
594+
InitializedFileSystem = true;
595+
596+
return false;
597+
}
597598

599+
bool ReadHeaderSearchPaths(const HeaderSearchOptions &HSOpts,
600+
bool Complain) override {
601+
this->HSOpts.UserEntries = HSOpts.UserEntries;
602+
this->HSOpts.SystemHeaderPrefixes = HSOpts.SystemHeaderPrefixes;
598603
return false;
599604
}
600605

@@ -867,8 +872,8 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
867872

868873
unsigned Counter = 0;
869874
AST->Reader->setListener(std::make_unique<ASTInfoCollector>(
870-
*AST->PP, AST->Ctx.get(), *AST->HSOpts, *AST->PPOpts, *AST->LangOpts,
871-
AST->TargetOpts, AST->Target, Counter));
875+
*AST->PP, AST->Ctx.get(), AST->FileSystemOpts, *AST->HSOpts, *AST->PPOpts,
876+
*AST->LangOpts, AST->TargetOpts, AST->Target, Counter));
872877

873878
// Attach the AST reader to the AST context as an external AST
874879
// source, so that declarations will be deserialized from the

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ static void collectIncludePCH(CompilerInstance &CI,
261261

262262
static void collectVFSEntries(CompilerInstance &CI,
263263
std::shared_ptr<ModuleDependencyCollector> MDC) {
264-
if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty())
264+
if (CI.getFileSystemOpts().VFSOverlayFiles.empty())
265265
return;
266266

267267
// Collect all VFS found.
268268
SmallVector<llvm::vfs::YAMLVFSEntry, 16> VFSEntries;
269-
for (const std::string &VFSFile : CI.getHeaderSearchOpts().VFSOverlayFiles) {
269+
for (const std::string &VFSFile : CI.getFileSystemOpts().VFSOverlayFiles) {
270270
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
271271
llvm::MemoryBuffer::getFile(VFSFile);
272272
if (!Buffer)

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,9 @@ static void GenerateFileSystemArgs(const FileSystemOptions &Opts,
24212421
GENERATE_OPTION_WITH_MARSHALLING(Consumer, __VA_ARGS__)
24222422
#include "clang/Driver/Options.inc"
24232423
#undef FILE_SYSTEM_OPTION_WITH_MARSHALLING
2424+
2425+
for (const std::string &F : Opts.VFSOverlayFiles)
2426+
GenerateArg(Consumer, OPT_ivfsoverlay, F);
24242427
}
24252428

24262429
static bool ParseFileSystemArgs(FileSystemOptions &Opts, const ArgList &Args,
@@ -2434,6 +2437,9 @@ static bool ParseFileSystemArgs(FileSystemOptions &Opts, const ArgList &Args,
24342437
#include "clang/Driver/Options.inc"
24352438
#undef FILE_SYSTEM_OPTION_WITH_MARSHALLING
24362439

2440+
for (const auto *A : Args.filtered(OPT_ivfsoverlay, OPT_vfsoverlay))
2441+
Opts.VFSOverlayFiles.push_back(std::string(A->getValue()));
2442+
24372443
return Diags.getNumErrors() == NumErrorsBefore;
24382444
}
24392445

@@ -3270,9 +3276,6 @@ static void GenerateHeaderSearchArgs(const HeaderSearchOptions &Opts,
32703276
: OPT_no_system_header_prefix;
32713277
GenerateArg(Consumer, Opt, P.Prefix);
32723278
}
3273-
3274-
for (const std::string &F : Opts.VFSOverlayFiles)
3275-
GenerateArg(Consumer, OPT_ivfsoverlay, F);
32763279
}
32773280

32783281
static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
@@ -3411,9 +3414,6 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
34113414
Opts.AddSystemHeaderPrefix(
34123415
A->getValue(), A->getOption().matches(OPT_system_header_prefix));
34133416

3414-
for (const auto *A : Args.filtered(OPT_ivfsoverlay, OPT_vfsoverlay))
3415-
Opts.AddVFSOverlayFile(A->getValue());
3416-
34173417
return Diags.getNumErrors() == NumErrorsBefore;
34183418
}
34193419

@@ -4959,7 +4959,7 @@ bool CompilerInvocation::CreateFromArgsImpl(
49594959
// to determine the PGO type.
49604960
if (!Res.getCodeGenOpts().ProfileInstrumentUsePath.empty()) {
49614961
auto FS =
4962-
createVFSFromOverlayFiles(Res.getHeaderSearchOpts().VFSOverlayFiles,
4962+
createVFSFromOverlayFiles(Res.getFileSystemOpts().VFSOverlayFiles,
49634963
Diags, llvm::vfs::getRealFileSystem());
49644964
setPGOUseInstrumentor(Res.getCodeGenOpts(),
49654965
Res.getCodeGenOpts().ProfileInstrumentUsePath, *FS,
@@ -5051,7 +5051,7 @@ std::string CompilerInvocation::getModuleHash() const {
50515051
if (hsOpts.ModulesStrictContextHash) {
50525052
HBuilder.addRange(hsOpts.SystemHeaderPrefixes);
50535053
HBuilder.addRange(hsOpts.UserEntries);
5054-
HBuilder.addRange(hsOpts.VFSOverlayFiles);
5054+
HBuilder.addRange(getFileSystemOpts().VFSOverlayFiles);
50555055

50565056
const DiagnosticOptions &diagOpts = getDiagnosticOpts();
50575057
#define DIAGOPT(Name, Bits, Default) HBuilder.add(diagOpts.Name);
@@ -5171,7 +5171,7 @@ IntrusiveRefCntPtr<llvm::vfs::FileSystem>
51715171
clang::createVFSFromCompilerInvocation(
51725172
const CompilerInvocation &CI, DiagnosticsEngine &Diags,
51735173
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS) {
5174-
return createVFSFromOverlayFiles(CI.getHeaderSearchOpts().VFSOverlayFiles,
5174+
return createVFSFromOverlayFiles(CI.getFileSystemOpts().VFSOverlayFiles,
51755175
Diags, std::move(BaseFS));
51765176
}
51775177

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,15 @@ namespace {
706706
return false;
707707
}
708708

709+
bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
710+
bool Complain) override {
711+
Out.indent(2) << "File system options:\n";
712+
Out.indent(4) << "VFS overlay files:\n";
713+
for (const auto &Overlay : FSOpts.VFSOverlayFiles)
714+
Out.indent(6) << Overlay << "\n";
715+
return false;
716+
}
717+
709718
bool ReadHeaderSearchPaths(const HeaderSearchOptions &HSOpts,
710719
bool Complain) override {
711720
Out.indent(2) << "Header search paths:\n";
@@ -715,9 +724,6 @@ namespace {
715724
Out.indent(4) << "System header prefixes:\n";
716725
for (const auto &Prefix : HSOpts.SystemHeaderPrefixes)
717726
Out.indent(6) << Prefix.Prefix << "\n";
718-
Out.indent(4) << "VFS overlay files:\n";
719-
for (const auto &Overlay : HSOpts.VFSOverlayFiles)
720-
Out.indent(6) << Overlay << "\n";
721727
return false;
722728
}
723729

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ std::vector<bool> HeaderSearch::collectVFSUsageAndClear() const {
157157
RFS->clearHasBeenUsed();
158158
}
159159
});
160-
assert(VFSUsage.size() == getHeaderSearchOpts().VFSOverlayFiles.size() &&
160+
assert(VFSUsage.size() ==
161+
FileMgr.getFileSystemOpts().VFSOverlayFiles.size() &&
161162
"A different number of RedirectingFileSystem's were present than "
162163
"-ivfsoverlay options passed to Clang!");
163164
// VFS visit order is the opposite of VFSOverlayFiles order.

clang/lib/Serialization/ASTReader.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,14 +2844,6 @@ ASTReader::ASTReadResult ASTReader::ReadOptionsBlock(
28442844
break;
28452845
}
28462846

2847-
case FILE_SYSTEM_OPTIONS: {
2848-
bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
2849-
if (!AllowCompatibleConfigurationMismatch &&
2850-
ParseFileSystemOptions(Record, Complain, Listener))
2851-
Result = ConfigurationMismatch;
2852-
break;
2853-
}
2854-
28552847
case HEADER_SEARCH_OPTIONS: {
28562848
bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
28572849
if (!AllowCompatibleConfigurationMismatch &&
@@ -5015,6 +5007,13 @@ ASTReader::ASTReadResult ASTReader::readUnhashedControlBlockImpl(
50155007
Result = OutOfDate; // Don't return early. Read the signature.
50165008
break;
50175009
}
5010+
case FILE_SYSTEM_OPTIONS: {
5011+
bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
5012+
if (Listener && !AllowCompatibleConfigurationMismatch &&
5013+
ParseFileSystemOptions(Record, Complain, *Listener))
5014+
Result = ConfigurationMismatch;
5015+
break;
5016+
}
50185017
case HEADER_SEARCH_PATHS: {
50195018
bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0;
50205019
if (Listener && !AllowCompatibleConfigurationMismatch &&
@@ -6155,7 +6154,12 @@ bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain,
61556154
ASTReaderListener &Listener) {
61566155
FileSystemOptions FSOpts;
61576156
unsigned Idx = 0;
6157+
61586158
FSOpts.WorkingDir = ReadString(Record, Idx);
6159+
6160+
for (unsigned N = Record[Idx++]; N; --N)
6161+
FSOpts.VFSOverlayFiles.emplace_back(ReadString(Record, Idx));
6162+
61596163
return Listener.ReadFileSystemOptions(FSOpts, Complain);
61606164
}
61616165

@@ -6207,12 +6211,6 @@ bool ASTReader::ParseHeaderSearchPaths(const RecordData &Record, bool Complain,
62076211
HSOpts.SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader);
62086212
}
62096213

6210-
// VFS overlay files.
6211-
for (unsigned N = Record[Idx++]; N; --N) {
6212-
std::string VFSOverlayFile = ReadString(Record, Idx);
6213-
HSOpts.VFSOverlayFiles.emplace_back(std::move(VFSOverlayFile));
6214-
}
6215-
62166214
return Listener.ReadHeaderSearchPaths(HSOpts, Complain);
62176215
}
62186216

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,6 @@ void ASTWriter::WriteBlockInfoBlock() {
868868
BLOCK(OPTIONS_BLOCK);
869869
RECORD(LANGUAGE_OPTIONS);
870870
RECORD(TARGET_OPTIONS);
871-
RECORD(FILE_SYSTEM_OPTIONS);
872871
RECORD(HEADER_SEARCH_OPTIONS);
873872
RECORD(PREPROCESSOR_OPTIONS);
874873

@@ -1113,6 +1112,7 @@ void ASTWriter::WriteBlockInfoBlock() {
11131112
RECORD(SIGNATURE);
11141113
RECORD(AST_BLOCK_HASH);
11151114
RECORD(DIAGNOSTIC_OPTIONS);
1115+
RECORD(FILE_SYSTEM_OPTIONS);
11161116
RECORD(HEADER_SEARCH_PATHS);
11171117
RECORD(DIAG_PRAGMA_MAPPINGS);
11181118

@@ -1342,6 +1342,19 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
13421342
Record.clear();
13431343
}
13441344

1345+
// File system options.
1346+
const FileSystemOptions &FSOpts =
1347+
Context.getSourceManager().getFileManager().getFileSystemOpts();
1348+
1349+
AddString(FSOpts.WorkingDir, Record);
1350+
1351+
Record.push_back(FSOpts.VFSOverlayFiles.size());
1352+
for (StringRef VFSOverlayFile : FSOpts.VFSOverlayFiles)
1353+
AddString(VFSOverlayFile, Record);
1354+
1355+
Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record);
1356+
Record.clear();
1357+
13451358
// Header search paths.
13461359
if (!HSOpts.ModulesSkipHeaderSearchPaths) {
13471360
// Include entries.
@@ -1361,11 +1374,6 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
13611374
Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader);
13621375
}
13631376

1364-
// VFS overlay files.
1365-
Record.push_back(HSOpts.VFSOverlayFiles.size());
1366-
for (StringRef VFSOverlayFile : HSOpts.VFSOverlayFiles)
1367-
AddString(VFSOverlayFile, Record);
1368-
13691377
Stream.EmitRecord(HEADER_SEARCH_PATHS, Record);
13701378
}
13711379

@@ -1607,13 +1615,6 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
16071615
}
16081616
Stream.EmitRecord(TARGET_OPTIONS, Record);
16091617

1610-
// File system options.
1611-
Record.clear();
1612-
const FileSystemOptions &FSOpts =
1613-
Context.getSourceManager().getFileManager().getFileSystemOpts();
1614-
AddString(FSOpts.WorkingDir, Record);
1615-
Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record);
1616-
16171618
// Header search options.
16181619
Record.clear();
16191620
const HeaderSearchOptions &HSOpts =
@@ -5019,8 +5020,7 @@ void ASTWriter::computeNonAffectingInputFiles() {
50195020
FileManager &FileMgr = PP->getFileManager();
50205021
FileMgr.trackVFSUsage(true);
50215022
// Lookup the paths in the VFS to trigger `-ivfsoverlay` usage tracking.
5022-
for (StringRef Path :
5023-
PP->getHeaderSearchInfo().getHeaderSearchOpts().VFSOverlayFiles)
5023+
for (StringRef Path : FileMgr.getFileSystemOpts().VFSOverlayFiles)
50245024
FileMgr.getVirtualFileSystem().exists(Path);
50255025
for (unsigned I = 1; I != N; ++I) {
50265026
if (IsSLocAffecting[I]) {

0 commit comments

Comments
 (0)