aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2022-08-22 15:42:52 -0700
committerBen Langmuir <blangmuir@apple.com>2022-08-23 08:18:14 -0700
commit3708a148421fd0449081b9a91fba28f51f1dfb12 (patch)
tree76a651ef3d22c609cb09dc46558a4a8be3f640b6 /clang/lib
parent86bfab2723618772f5c4ffc2a68eedca592c6928 (diff)
downloadllvm-3708a148421fd0449081b9a91fba28f51f1dfb12.zip
llvm-3708a148421fd0449081b9a91fba28f51f1dfb12.tar.gz
llvm-3708a148421fd0449081b9a91fba28f51f1dfb12.tar.bz2
[clang] Pull some utility functions into CompilerInvocation NFC
Move copying compiler arguments to a vector<string> and modifying common module-related options into CompilerInvocation in preparation for using some of them in more places and to avoid duplicating this code accidentally in the future. Differential Revision: https://reviews.llvm.org/D132419
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp3
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp31
-rw-r--r--clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp33
3 files changed, 35 insertions, 32 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index e3b5447..03b5d04 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1150,8 +1150,7 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc,
// For any options that aren't intended to affect how a module is built,
// reset them to their default values.
- Invocation->getLangOpts()->resetNonModularOptions();
- PPOpts.resetNonModularOptions();
+ Invocation->resetNonModularOptions();
// Remove any macro definitions that are explicitly ignored by the module.
// They aren't supposed to affect how the module is built anyway.
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 9731d40..7e6d0cd 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4672,6 +4672,37 @@ void CompilerInvocation::generateCC1CommandLine(
GenerateDependencyOutputArgs(DependencyOutputOpts, Args, SA);
}
+std::vector<std::string> CompilerInvocation::getCC1CommandLine() const {
+ // Set up string allocator.
+ llvm::BumpPtrAllocator Alloc;
+ llvm::StringSaver Strings(Alloc);
+ auto SA = [&Strings](const Twine &Arg) { return Strings.save(Arg).data(); };
+
+ // Synthesize full command line from the CompilerInvocation, including "-cc1".
+ SmallVector<const char *, 32> Args{"-cc1"};
+ generateCC1CommandLine(Args, SA);
+
+ // Convert arguments to the return type.
+ return std::vector<std::string>{Args.begin(), Args.end()};
+}
+
+void CompilerInvocation::resetNonModularOptions() {
+ getLangOpts()->resetNonModularOptions();
+ getPreprocessorOpts().resetNonModularOptions();
+}
+
+void CompilerInvocation::clearImplicitModuleBuildOptions() {
+ getLangOpts()->ImplicitModules = false;
+ getHeaderSearchOpts().ImplicitModuleMaps = false;
+ getHeaderSearchOpts().ModuleCachePath.clear();
+ getHeaderSearchOpts().ModulesValidateOncePerBuildSession = false;
+ getHeaderSearchOpts().BuildSessionTimestamp = 0;
+ // The specific values we canonicalize to for pruning don't affect behaviour,
+ /// so use the default values so they may be dropped from the command-line.
+ getHeaderSearchOpts().ModuleCachePruneInterval = 7 * 24 * 60 * 60;
+ getHeaderSearchOpts().ModuleCachePruneAfter = 31 * 24 * 60 * 60;
+}
+
IntrusiveRefCntPtr<llvm::vfs::FileSystem>
clang::createVFSFromCompilerInvocation(const CompilerInvocation &CI,
DiagnosticsEngine &Diags) {
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index db1489f..f2de018 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -98,8 +98,8 @@ ModuleDepCollector::makeInvocationForModuleBuildWithoutOutputs(
// Make a deep copy of the original Clang invocation.
CompilerInvocation CI(OriginalInvocation);
- CI.getLangOpts()->resetNonModularOptions();
- CI.getPreprocessorOpts().resetNonModularOptions();
+ CI.resetNonModularOptions();
+ CI.clearImplicitModuleBuildOptions();
// Remove options incompatible with explicit module build or are likely to
// differ between identical modules discovered from different translation
@@ -120,18 +120,6 @@ ModuleDepCollector::makeInvocationForModuleBuildWithoutOutputs(
CI.getLangOpts()->ModuleName = Deps.ID.ModuleName;
CI.getFrontendOpts().IsSystemModule = Deps.IsSystem;
- // Disable implicit modules and canonicalize options that are only used by
- // implicit modules.
- CI.getLangOpts()->ImplicitModules = false;
- CI.getHeaderSearchOpts().ImplicitModuleMaps = false;
- CI.getHeaderSearchOpts().ModuleCachePath.clear();
- CI.getHeaderSearchOpts().ModulesValidateOncePerBuildSession = false;
- CI.getHeaderSearchOpts().BuildSessionTimestamp = 0;
- // The specific values we canonicalize to for pruning don't affect behaviour,
- /// so use the default values so they will be dropped from the command-line.
- CI.getHeaderSearchOpts().ModuleCachePruneInterval = 7 * 24 * 60 * 60;
- CI.getHeaderSearchOpts().ModuleCachePruneAfter = 31 * 24 * 60 * 60;
-
// Inputs
InputKind ModuleMapInputKind(CI.getFrontendOpts().DashX.getLanguage(),
InputKind::Format::ModuleMap);
@@ -182,23 +170,8 @@ ModuleDepCollector::makeInvocationForModuleBuildWithoutOutputs(
return CI;
}
-static std::vector<std::string>
-serializeCompilerInvocation(const CompilerInvocation &CI) {
- // Set up string allocator.
- llvm::BumpPtrAllocator Alloc;
- llvm::StringSaver Strings(Alloc);
- auto SA = [&Strings](const Twine &Arg) { return Strings.save(Arg).data(); };
-
- // Synthesize full command line from the CompilerInvocation, including "-cc1".
- SmallVector<const char *, 32> Args{"-cc1"};
- CI.generateCC1CommandLine(Args, SA);
-
- // Convert arguments to the return type.
- return std::vector<std::string>{Args.begin(), Args.end()};
-}
-
std::vector<std::string> ModuleDeps::getCanonicalCommandLine() const {
- return serializeCompilerInvocation(BuildInvocation);
+ return BuildInvocation.getCC1CommandLine();
}
static std::string getModuleContextHash(const ModuleDeps &MD,