[clang-tools-extra] r346219 - [clang-tidy] run() doesn't update the SourceManager.

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 6 01:28:23 PST 2018

Author: sammccall
Date: Tue Nov  6 01:28:23 2018
New Revision: 346219

URL: http://llvm.org/viewvc/llvm-project?rev=346219&view=rev
[clang-tidy] run() doesn't update the SourceManager.

By now the context's SourceManager is now initialized everywhere that
ClangTidyCheck::registerMatcher() is called, so the call from run() seems
entirely redundant, and indeed all the tests pass.

This solves a problem with embedding clang-tidy: if using a DiagnosticsEngine
which already has file state, re-setting its SourceManager (to the same value)
causes an assertion.
(There are other ways to solve this problem, but this is the simplest).

Reviewers: hokein, alexfh

Subscribers: xazax.hun, cfe-commits

Differential Revision: https://reviews.llvm.org/D54061


Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=346219&r1=346218&r2=346219&view=diff
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Tue Nov  6 01:28:23 2018
@@ -441,7 +441,9 @@ DiagnosticBuilder ClangTidyCheck::diag(S
 void ClangTidyCheck::run(const ast_matchers::MatchFinder::MatchResult &Result) {
-  Context->setSourceManager(Result.SourceManager);
+  // For historical reasons, checks don't implement the MatchFinder run()
+  // callback directly. We keep the run()/check() distinction to avoid interface
+  // churn, and to allow us to add cross-cutting logic in the future.

More information about the cfe-commits mailing list