[clang] [clang][deps] Store common, partially-formed invocation (PR #65677)

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 7 14:53:30 PDT 2023


================
@@ -117,14 +112,37 @@ ModuleDepCollector::makeInvocationForModuleBuildWithoutOutputs(
   CI.getFrontendOpts().ARCMTAction = FrontendOptions::ARCMT_None;
   CI.getFrontendOpts().ObjCMTAction = FrontendOptions::ObjCMT_None;
   CI.getFrontendOpts().MTMigrateDir.clear();
-  CI.getLangOpts().ModuleName = Deps.ID.ModuleName;
-  CI.getFrontendOpts().IsSystemModule = Deps.IsSystem;
+
+  // Remove any macro definitions that are explicitly ignored.
+  if (!CI.getHeaderSearchOpts().ModulesIgnoreMacros.empty()) {
+    llvm::erase_if(
+        CI.getPreprocessorOpts().Macros,
+        [&CI](const std::pair<std::string, bool> &Def) {
+          StringRef MacroDef = Def.first;
+          return CI.getHeaderSearchOpts().ModulesIgnoreMacros.contains(
+              llvm::CachedHashString(MacroDef.split('=').first));
+        });
+    // Remove the now unused option.
+    CI.getHeaderSearchOpts().ModulesIgnoreMacros.clear();
+  }
+
+  return CI;
----------------
benlangmuir wrote:

This is going through `CowCompilerInvocation(const CompilerInvocation &X)`, right?  Could we add an `&&` version that steals the sub objects without copying them? Obviously less important than avoiding the per-module copies.

https://github.com/llvm/llvm-project/pull/65677


More information about the cfe-commits mailing list