[clang] [Clang] Support includes translated to module imports in -header-include-filtering=direct-per-file (PR #156756)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 18 08:49:39 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions c,cpp -- clang/lib/Frontend/HeaderIncludeGen.cpp clang/test/Preprocessor/print-header-json.c
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Frontend/HeaderIncludeGen.cpp b/clang/lib/Frontend/HeaderIncludeGen.cpp
index 8ce7a1a85..a6e6f38f0 100644
--- a/clang/lib/Frontend/HeaderIncludeGen.cpp
+++ b/clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -117,7 +117,8 @@ class HeaderIncludesDirectPerFileCallback : public PPCallbacks {
     FileEntryRef File;
     const Module *ImportedModule;
 
-    HeaderIncludeInfo(SourceLocation Location, FileEntryRef File, const Module *ImportedModule)
+    HeaderIncludeInfo(SourceLocation Location, FileEntryRef File,
+                      const Module *ImportedModule)
         : Location(Location), File(File), ImportedModule(ImportedModule) {}
   };
 
@@ -125,7 +126,8 @@ class HeaderIncludesDirectPerFileCallback : public PPCallbacks {
   HeaderSearch &HSI;
   raw_ostream *OutputFile;
   bool OwnsOutputFile;
-  using DependencyMap = llvm::DenseMap<FileEntryRef, SmallVector<HeaderIncludeInfo>>;
+  using DependencyMap =
+      llvm::DenseMap<FileEntryRef, SmallVector<HeaderIncludeInfo>>;
   DependencyMap Dependencies;
 
 public:
@@ -421,7 +423,9 @@ void HeaderIncludesDirectPerFileCallback::EndOfMainFile() {
               if (Deps[I].ImportedModule) {
                 JOS.object([&] {
                   JOS.attribute("location", Deps[I].Location.printToString(SM));
-                  JOS.attribute("module", Deps[I].ImportedModule->getTopLevelModuleName());
+                  JOS.attribute(
+                      "module",
+                      Deps[I].ImportedModule->getTopLevelModuleName());
                   JOS.attribute("file", Deps[I].File.getName());
                 });
               }
@@ -431,7 +435,7 @@ void HeaderIncludesDirectPerFileCallback::EndOfMainFile() {
       }
     });
   });
-  
+
   OS << "\n";
 
   if (OutputFile->get_kind() == raw_ostream::OStreamKind::OK_FDStream) {
@@ -459,13 +463,15 @@ void HeaderIncludesDirectPerFileCallback::InclusionDirective(
 
   FileEntryRef HeaderOrModuleMapFile = *File;
   if (ModuleImported && SuggestedModule) {
-    OptionalFileEntryRef ModuleMapFile = HSI.getModuleMap().getModuleMapFileForUniquing(SuggestedModule);
+    OptionalFileEntryRef ModuleMapFile =
+        HSI.getModuleMap().getModuleMapFileForUniquing(SuggestedModule);
     if (ModuleMapFile) {
       HeaderOrModule = *ModuleMapFile;
     }
   }
 
-  HeaderIncludeInfo DependenciesEntry(Loc, HeaderOrModule, (ModuleImported ? SuggestedModule : nullptr));
+  HeaderIncludeInfo DependenciesEntry(
+      Loc, HeaderOrModule, (ModuleImported ? SuggestedModule : nullptr));
   Dependencies[*FromFile].push_back(DependenciesEntry);
 }
 

``````````

</details>


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


More information about the cfe-commits mailing list