[clang] [clang-tools-extra] [clang-tidy] EndSourceFile() for preprocessor before diagnostic client (PR #145784)

Dave Bartolomeo via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 3 09:07:32 PDT 2025


================
@@ -1243,13 +1243,15 @@ llvm::Error FrontendAction::Execute() {
 void FrontendAction::EndSourceFile() {
   CompilerInstance &CI = getCompilerInstance();
 
-  // Inform the diagnostic client we are done with this source file.
-  CI.getDiagnosticClient().EndSourceFile();
-
   // Inform the preprocessor we are done.
   if (CI.hasPreprocessor())
     CI.getPreprocessor().EndSourceFile();
 
+  // Inform the diagnostic client we are done with this source file.
+  // Do this after notifying the preprocessor, so that end-of-file preprocessor
+  // callbacks can report diagnostics.
+  CI.getDiagnosticClient().EndSourceFile();
----------------
dbartol wrote:

This is already covered by several existing clang-tidy tests. Any check that fires a warning from the `EndOfMainFile` preprocessor event will trigger the assert that I added. These tests fail if I remove the change to `FrontendAction.cpp`.


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


More information about the cfe-commits mailing list