[all-commits] [llvm/llvm-project] 85aaaf: [clang-tidy] EndSourceFile() for preprocessor befo...
Dave Bartolomeo via All-commits
all-commits at lists.llvm.org
Thu Jul 3 21:37:19 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 85aaaf6e7409999842782f9fbcde3b5be4aa0c79
https://github.com/llvm/llvm-project/commit/85aaaf6e7409999842782f9fbcde3b5be4aa0c79
Author: Dave Bartolomeo <dave_bartolomeo at apple.com>
Date: 2025-07-04 (Fri, 04 Jul 2025)
Changed paths:
M clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
M clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
M clang/lib/Frontend/FrontendAction.cpp
Log Message:
-----------
[clang-tidy] EndSourceFile() for preprocessor before diagnostic client (#145784)
The comment for `DiagnosticConsumer::BeginSourceFile()` states that
"diagnostics with source range information are required to only be
emitted in between BeginSourceFile() and EndSourceFile().". While
working on some upcoming changes to the static analyzer, we hit some
crashes when diagnostics were reported from the `EndOfMainFile` callback
in the preprocessor. This turned out to be because
`FrontEndAction::EndSourceFile()` notifies the diagnostic clients of the
end of the source file before it notifies the preprocessor. Thus, the
diagnostics from the preprocessor callback are reported when the
diagnostic client is no longer expecting any diagnostics.
The fix is to swap the order of the `EndSourceFile()` calls so that the
preprocessor is notified first.
I've added asserts to the `ClangTidyDiagnosticConsumer` to catch
unexpected diagnostics outside of a source file. Before swapping the
order of the calls as described above, this causes several failures in
the clang-tidy regression tests. With the swap, there are no failures in
`check-all`.
rdar://141230583
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list