aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2025-04-23 10:33:12 -0700
committerGitHub <noreply@github.com>2025-04-23 10:33:12 -0700
commit060f3f0dd1614b624b527e871019970e4303de11 (patch)
treeb55b9c6a2dba1245f0d8af9636ee80472b8a7802 /clang/lib/Frontend/CompilerInstance.cpp
parent1041d54bd4f693c1ac03077680ece67e03c99e22 (diff)
downloadllvm-060f3f0dd1614b624b527e871019970e4303de11.zip
llvm-060f3f0dd1614b624b527e871019970e4303de11.tar.gz
llvm-060f3f0dd1614b624b527e871019970e4303de11.tar.bz2
[clang][deps] Make dependency directives getter thread-safe (#136178)
This PR fixes two issues in one go: 1. The dependency directives getter (a `std::function`) was being stored in `PreprocessorOptions`. This goes against the principle where the options classes are supposed to be value-objects representing the `-cc1` command line arguments. This is fixed by moving the getter directly to `CompilerInstance` and propagating it explicitly. 2. The getter was capturing the `ScanInstance` VFS. That's fine in synchronous implicit module builds where the same VFS instance is used throughout, but breaks down once you try to build modules asynchronously (which forces the use of separate VFS instances). This is fixed by explicitly passing a `FileManager` into the getter and extracting the right instance of the scanning VFS out of it.
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index de633f0..8596dd0 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -536,6 +536,9 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
/*ShowAllHeaders=*/true, /*OutputPath=*/"",
/*ShowDepth=*/true, /*MSStyle=*/true);
}
+
+ if (GetDependencyDirectives)
+ PP->setDependencyDirectivesGetter(*GetDependencyDirectives);
}
std::string CompilerInstance::getSpecificModuleCachePath(StringRef ModuleHash) {
@@ -1246,6 +1249,10 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
// Make a copy for the new instance.
Instance.FailedModules = FailedModules;
+ if (GetDependencyDirectives)
+ Instance.GetDependencyDirectives =
+ GetDependencyDirectives->cloneFor(Instance.getFileManager());
+
// If we're collecting module dependencies, we need to share a collector
// between all of the module CompilerInstances. Other than that, we don't
// want to produce any dependency output from the module build.