[clang] [Clang] Add new -header-include-filtering=direct-per-file option (PR #137087)

Michael Spencer via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 28 21:04:37 PDT 2025


================
@@ -322,3 +372,81 @@ void HeaderIncludesJSONCallback::FileSkipped(
 
   IncludedHeaders.push_back(SkippedFile.getName().str());
 }
+
+void HeaderIncludesDirectPerFileCallback::EndOfMainFile() {
+  if (Dependencies.empty())
+    return;
+
+  // Sort the files so that the output does not depend on the DenseMap order.
+  SmallVector<FileEntryRef> SourceFiles;
+  for (auto F = Dependencies.begin(), FEnd = Dependencies.end(); F != FEnd;
+       ++F) {
+    SourceFiles.push_back(F->first);
+  }
+  llvm::sort(SourceFiles, [](const FileEntryRef &LHS, const FileEntryRef &RHS) {
+    return LHS.getUID() < RHS.getUID();
----------------
Bigcheese wrote:

This is stable in the order of files opened. That's probably fine, but can change order if the source code changes.

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


More information about the cfe-commits mailing list