From 80a3c561a7ea8072a984bc14a09b041667781f52 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Tue, 6 Nov 2018 09:28:23 +0000 Subject: [PATCH] [clang-tidy] run() doesn't update the SourceManager. Summary: 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 llvm-svn: 346219 --- clang-tools-extra/clang-tidy/ClangTidy.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index f0126e8668bd..ed48de9196ce 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -441,7 +441,9 @@ DiagnosticBuilder ClangTidyCheck::diag(SourceLocation Loc, StringRef Message, } 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. check(Result); }