You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EndSourceFile() for preprocessor before diagnstic client
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, which catches the problem in current tests.
assert(InSourceFile || Info.getLocation().isInvalid()); // A diagnostic should not be reported outside of a BeginSourceFile()/EndSourceFile() pair if it has a source location.
364
+
363
365
if (LastErrorWasIgnored && DiagLevel == DiagnosticsEngine::Note)
0 commit comments