This is an archive of the discontinued LLVM Phabricator instance.

[clangBasic] Refactor StaticAnalyzer to use `clang::SarifDocumentWriter`
ClosedPublic

Authored by vaibhav.y on Oct 14 2022, 1:50 PM.

Details

Summary

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.

Diff Detail

Event Timeline

vaibhav.y created this revision.Oct 14 2022, 1:50 PM
Herald added a project: Restricted Project. · View Herald Transcript
vaibhav.y updated this revision to Diff 472133.Oct 31 2022, 2:26 PM

Update unit tests

vaibhav.y retitled this revision from [clangBasic] Create `FullSourceLoc::getDecomposedExpansionLoc` to [clangBasic] Refactor StaticAnalyzer to use `clang::SarifDocumentWriter`.Oct 31 2022, 2:39 PM
vaibhav.y edited the summary of this revision. (Show Details)
vaibhav.y published this revision for review.Oct 31 2022, 2:42 PM
vaibhav.y added inline comments.
clang/lib/Basic/Sarif.cpp
121–122

L121 was copied wrong, libStaticAnalyzer (sensibly) uses the expansion loc. This has been fixed as well.

Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 2:42 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thank you for this refactoring, I really like the direction it's going! I've not spotted anything concerning, but if someone can double-check conformance to SARIF in terms of the changes to the tests, that would be appreciated.

It looks like precommit CI found a relevant failure that should be addressed.

vaibhav.y updated this revision to Diff 475475.Nov 15 2022, 7:36 AM

Update FileCheck tests to include now serialized file URIs

Thank you for this refactoring, I really like the direction it's going! I've not spotted anything concerning, but if someone can double-check conformance to SARIF in terms of the changes to the tests, that would be appreciated.

It looks like precommit CI found a relevant failure that should be addressed.

Thank you! It was the FileCheck tests for -Wsarif-format-unstable. I think I've updated those correctly, but would appreciate another look. I haven't had much experience with FileCheck so far.

aaron.ballman accepted this revision.Nov 17 2022, 5:56 AM

LGTM from my understanding of SARIF, thank you!

This revision is now accepted and ready to land.Nov 17 2022, 5:56 AM

Great! Please use the following for patch attribution:

  • Name: Vaibhav Yenamandra
  • email address: vyenamandra@bloomberg.net

Great! Please use the following for patch attribution:

  • Name: Vaibhav Yenamandra
  • email address: vyenamandra@bloomberg.net

Happy to, can you rebase the patch on the top of tree? It doesn't apply cleanly for me.

vaibhav.y updated this revision to Diff 476186.EditedNov 17 2022, 11:01 AM

Rebase on upstream/main

Had missed changes from D135896

I've landed in 7b6fe711b210a90cbb8facfe5343a0f999de5a0c on your behalf, thank you for the improvements!