[PATCH] D98635: [libtooling][clang-tidy] Fix diagnostics not handlings SourceRange highlights

Whisperity via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 15 09:13:18 PDT 2021


whisperity created this revision.
whisperity added reviewers: aaron.ballman, njames93.
whisperity added projects: clang, clang-tools-extra.
Herald added subscribers: martong, gamesh411, Szelethus, dkrupp, rnkovacs, xazax.hun.
whisperity requested review of this revision.
Herald added a subscriber: cfe-commits.

> Fixes bug #49000 <http://bugs.llvm.org/show_bug.cgi?id=49000>.

Currently, when a diagnostic in Clang-Tidy is produced as `diag(Var->getLocation(), "foo %0") << "bar" << Var->getSourceRange();`, the source range specified to be highlighted is discarded, i.e.

  x.cpp:21:18: warning: foo bar [blah-blah-checker]
  void fun(int I, int J, int K) {}
               ^

is created instead of producing a full highlight:

  x.cpp:21:18: warning: foo bar [blah-blah-checker]
  void fun(int I, int J, int K) {}
           ^~~~~

This creates a discrepancy between warnings generated in `Clang::Sema` which work properly, and in Tidy.
This patch fixes the issue by making sure Clang-Tidy's logic of decoupling ranges from the `SourceManager` and rendering them later respects custom ranges that are fed into a diagnostic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98635

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
  clang-tools-extra/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
  clang/include/clang/Tooling/Core/Diagnostic.h
  clang/include/clang/Tooling/DiagnosticsYaml.h
  clang/lib/Tooling/Core/Diagnostic.cpp
  clang/unittests/Tooling/DiagnosticsYamlTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98635.330682.patch
Type: text/x-patch
Size: 15978 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210315/065fd5e9/attachment.bin>


More information about the cfe-commits mailing list