[PATCH] D94476: [analyzer] Implement conversion from Clang diagnostics to PathDiagnostics.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 12 01:50:26 PST 2021


NoQ created this revision.
NoQ added reviewers: vsavchenko, xazax.hun, martong, Szelethus, baloghadamsoftware, Charusso.
Herald added subscribers: steakhal, ASDenysPetrov, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, mgorny.
NoQ requested review of this revision.

This `clang::DiagnosticConsumer` can take normal clang diagnostics (eg., Sema errors or Clang-Tidy warnings) and turn them into static analyzer's `PathDiagnostic`s which are then fed into `PathDiagnosticConsumer`s. It's an essential component for my clang-tidy/static analyzer cross-integration efforts.

The consumer isn't magically aware of information that isn't present in Clang diagnostics but expected in path diagnostics. Such info includes checker name / bug type / category; the consumer expects an external provider to provide such information for every incoming diagnostic.

Additionally, `PathDiagnostic`'s declaration-with-issue and uniqueing-declaration are currently set to `nullptr`. I'm slowly thinking about auto-detecting those based on the source location but technically all path diagnostic consumer facilities can function just fine without them (declaration-with-issue is there purely for displaying user-visible names and uniqueing declaration only makes sense for path-sensitive warnings that require exotic uniqueing which will probably never be fed into this consumer).

There are also a few features missing here and there, such as fix-it hint support, which i plan to add later.

Though technically possible, this consumer is never supposed to consume the output of `TextPathDiagnosticConsumer`; a lot of information is lost that way that can't be recovered. In particular, the proper way to teach clang-tidy to emit path diagnostics while keeping in mind that it already ships with static analyzer integration is to allow the integrated static analyzer to talk to path diagnostic consumers directly; static analyzer warnings should never go through this new consumer.


https://reviews.llvm.org/D94476

Files:
  clang/include/clang/Analysis/PathDiagnosticConverterDiagnosticConsumer.h
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Analysis/PathDiagnosticConverterDiagnosticConsumer.cpp
  clang/unittests/Analysis/CMakeLists.txt
  clang/unittests/Analysis/PathDiagnosticConverterDiagnosticConsumer.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94476.316019.patch
Type: text/x-patch
Size: 12266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210112/1c5d3212/attachment-0001.bin>


More information about the cfe-commits mailing list