diff options
| author | Yitzhak Mandelbaum <yitzhakm@google.com> | 2019-08-26 15:17:29 +0000 |
|---|---|---|
| committer | Yitzhak Mandelbaum <yitzhakm@google.com> | 2019-08-26 15:17:29 +0000 |
| commit | 640230cc97f723a97fe8599e6b2fa1918bc235b8 (patch) | |
| tree | 920b03f83582a8c41ca02536956b774e4bf0b5be /clang-tools-extra/clang-tidy/utils | |
| parent | 1c9aa70b042bef8ed976ecf05ac92f255cea1da5 (diff) | |
| download | bcm5719-llvm-640230cc97f723a97fe8599e6b2fa1918bc235b8.tar.gz bcm5719-llvm-640230cc97f723a97fe8599e6b2fa1918bc235b8.zip | |
[clang-tidy] TransformerClangTidyCheck: change choice of location for diagnostic message.
Summary:
This patch changes the location specified to the
`ClangTidyCheck::diag()`. Currently, the beginning of the matched range is
used. This patch uses the beginning of the first fix's range. This change both
simplifies the code and (hopefully) gives a more intuitive result: the reported
location aligns with the fix(es) provided, rather than the (arbitrary) range of
the rule's match.
N.B. this patch will break the line offset numbers in lit tests if the first fix
is not at the beginning of the match.
Reviewers: gribozavr
Subscribers: xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66676
llvm-svn: 369914
Diffstat (limited to 'clang-tools-extra/clang-tidy/utils')
| -rw-r--r-- | clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp index 4c17a5ce273..06899108ea3 100644 --- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp @@ -71,14 +71,6 @@ void TransformerClangTidyCheck::check( if (Result.Context->getDiagnostics().hasErrorOccurred()) return; - // Verify the existence and validity of the AST node that roots this rule. - const ast_matchers::BoundNodes::IDToNodeMap &NodesMap = Result.Nodes.getMap(); - auto Root = NodesMap.find(RewriteRule::RootID); - assert(Root != NodesMap.end() && "Transformation failed: missing root node."); - SourceLocation RootLoc = Result.SourceManager->getExpansionLoc( - Root->second.getSourceRange().getBegin()); - assert(RootLoc.isValid() && "Invalid location for Root node of match."); - assert(Rule && "check() should not fire if Rule is None"); RewriteRule::Case Case = tooling::detail::findSelectedCase(Result, *Rule); Expected<SmallVector<tooling::detail::Transformation, 1>> Transformations = @@ -99,10 +91,12 @@ void TransformerClangTidyCheck::check( << llvm::toString(Explanation.takeError()) << "\n"; return; } - DiagnosticBuilder Diag = diag(RootLoc, *Explanation); - for (const auto &T : *Transformations) { + + // Associate the diagnostic with the location of the first change. + DiagnosticBuilder Diag = + diag((*Transformations)[0].Range.getBegin(), *Explanation); + for (const auto &T : *Transformations) Diag << FixItHint::CreateReplacement(T.Range, T.Replacement); - } for (const auto &I : Case.AddedIncludes) { auto &Header = I.first; |

