[clang] [clang] NFCI: Mutate `HeaderSearchOptions` earlier (PR #130823)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 11 13:22:18 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-modules

Author: Jan Svoboda (jansvoboda11)

<details>
<summary>Changes</summary>

I would like to ensure that `CompilerInvocation` and its constituents are not mutated late during the compilation. This PR moves adjustment of the `HeaderSearchOptions::ModulesSkip{DiagnosticOptions,HeaderSearchPaths}` bits from somewhere deep in the serialization library into `CompilerInvocation::CreateFromArgs()`.

---
Full diff: https://github.com/llvm/llvm-project/pull/130823.diff


3 Files Affected:

- (modified) clang/include/clang/Lex/HeaderSearchOptions.h (+1) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+6) 
- (modified) clang/lib/Serialization/GeneratePCH.cpp (-7) 


``````````diff
diff --git a/clang/include/clang/Lex/HeaderSearchOptions.h b/clang/include/clang/Lex/HeaderSearchOptions.h
index 7a16926c186d2..68308f5693ac6 100644
--- a/clang/include/clang/Lex/HeaderSearchOptions.h
+++ b/clang/include/clang/Lex/HeaderSearchOptions.h
@@ -235,6 +235,7 @@ class HeaderSearchOptions {
 
   /// Whether to entirely skip writing diagnostic options.
   /// Primarily used to speed up deserialization during dependency scanning.
+  /// FIXME: Consider moving these into separate `SerializationOptions` class.
   LLVM_PREFERRED_TYPE(bool)
   unsigned ModulesSkipDiagnosticOptions : 1;
 
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 4eb743acf327f..34821d9f8dd30 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4964,6 +4964,12 @@ bool CompilerInvocation::CreateFromArgsImpl(
   llvm::Triple T(Res.getTargetOpts().Triple);
   ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args, Diags,
                         Res.getFileSystemOpts().WorkingDir);
+  if (Res.getFrontendOpts().GenReducedBMI ||
+      Res.getFrontendOpts().ProgramAction ==
+          frontend::GenerateReducedModuleInterface) {
+    Res.getHeaderSearchOpts().ModulesSkipDiagnosticOptions = true;
+    Res.getHeaderSearchOpts().ModulesSkipHeaderSearchPaths = true;
+  }
   ParseAPINotesArgs(Res.getAPINotesOpts(), Args, Diags);
 
   ParsePointerAuthArgs(LangOpts, Args, Diags);
diff --git a/clang/lib/Serialization/GeneratePCH.cpp b/clang/lib/Serialization/GeneratePCH.cpp
index 12751beb8d715..512d5050d6520 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -120,13 +120,6 @@ Module *CXX20ModulesGenerator::getEmittingModule(ASTContext &Ctx) {
 }
 
 void CXX20ModulesGenerator::HandleTranslationUnit(ASTContext &Ctx) {
-  // FIMXE: We'd better to wrap such options to a new class ASTWriterOptions
-  // since this is not about searching header really.
-  HeaderSearchOptions &HSOpts =
-      getPreprocessor().getHeaderSearchInfo().getHeaderSearchOpts();
-  HSOpts.ModulesSkipDiagnosticOptions = true;
-  HSOpts.ModulesSkipHeaderSearchPaths = true;
-
   PCHGenerator::HandleTranslationUnit(Ctx);
 
   if (!isComplete())

``````````

</details>


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


More information about the cfe-commits mailing list