[PATCH] D135987: [clangBasic] Refactor StaticAnalyzer to use `clang::SarifDocumentWriter`

Vaibhav Yenamandra via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 14:42:13 PDT 2022


vaibhav.y created this revision.
vaibhav.y added reviewers: aaron.ballman, cjdb.
Herald added subscribers: steakhal, wenlei, martong.
Herald added a reviewer: NoQ.
Herald added a project: All.
vaibhav.y updated this revision to Diff 472133.
vaibhav.y added a comment.
vaibhav.y added a reviewer: dbeer1.
vaibhav.y retitled this revision from "[clangBasic] Create `FullSourceLoc::getDecomposedExpansionLoc`" to "[clangBasic] Refactor StaticAnalyzer to use `clang::SarifDocumentWriter`".
vaibhav.y edited the summary of this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
vaibhav.y published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update unit tests



================
Comment at: clang/lib/Basic/Sarif.cpp:121-123
+  std::pair<FileID, unsigned> LocInfo = Loc.getDecomposedExpansionLoc();
+  assert(LocInfo.second > Loc.getExpansionColumnNumber() &&
+         "position in file is before column number?");
----------------
L121 was copied wrong, `libStaticAnalyzer` (sensibly) uses the expansion loc. This has been fixed as well.


Refactor StaticAnalyzer to use `clang::SarifDocumentWriter` for serializing sarif diagnostics.

Uses `clang::SarifDocumentWriter` to generate SARIF output in the StaticAnalyzer.

Various bugfixes are also made to `clang::SarifDocumentWriter`.

Summary of changes:

- `clang/lib/Basic/Sarif.cpp`:
  - Fix bug in adjustColumnPos introduced from prev move, it now uses FullSourceLoc::getDecomposedExpansionLoc which provides the correct location (in the presence of macros) instead of `FullSourceLoc::getDecomposedLoc`.
  - Fix `createTextRegion` so that it handles caret ranges correctly, this should bring it to parity with the previous implementation.
- `clang/test/Analysis/diagnostics/Inputs/expected-sarif`:
  - Update the schema URL to the offical website
  - Add the emitted `defaultConfiguration` sections to all rules
  - Annotate results with the "level" property
- `clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp`:
  - Update `SarifDiagnostics` class to hold a `clang::SarifDocumentWriter` that it uses to convert diagnostics to SARIF.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135987

Files:
  clang/include/clang/Basic/SourceLocation.h
  clang/lib/Basic/Sarif.cpp
  clang/lib/Basic/SourceLocation.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
  clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
  clang/unittests/Basic/SarifTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135987.472133.patch
Type: text/x-patch
Size: 32920 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221031/45844a16/attachment-0001.bin>


More information about the cfe-commits mailing list