This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Static Analyzer checker configuration options passthrough
ClosedPublic

Authored by xazax.hun on Mar 9 2015, 4:50 AM.

Details

Summary

Starting from http://reviews.llvm.org/rL231266 options for individual static analyzer checkers can be specified.

This patch makes it possible to specify static analyzer checker options in clang tidy configuration files.

Diff Detail

Repository
rL LLVM

Event Timeline

xazax.hun updated this revision to Diff 21479.Mar 9 2015, 4:50 AM
xazax.hun retitled this revision from to [clang-tidy] Static Analyzer checker configuration options passthrough.
xazax.hun updated this object.
xazax.hun edited the test plan for this revision. (Show Details)
xazax.hun added a reviewer: alexfh.
xazax.hun added a subscriber: Unknown Object (MLST).

One minor question: the options are stored in std::map<std::string, std::string>. I wonder if there is any specific reason not to use llvm::StringMap in this case.

alexfh edited edge metadata.Mar 10 2015, 6:48 PM

One minor question: the options are stored in std::map<std::string, std::string>. I wonder if there is any specific reason not to use llvm::StringMap in this case.

I don't remember any specific reason. You can try to replace map<> with StringMap in a separate patch.

clang-tidy/ClangTidy.cpp
207 ↗(On Diff #21479)

I'd say that the function _sets_ static analyzer checker options, not gets them. Also, IMHO the other order of arguments would be better, as it seems more intuitive if the source comes first (it may be a matter of taste, though, and memcpy, for example, puts destination first).

210 ↗(On Diff #21479)

I'd move the declaration into the loop.

211 ↗(On Diff #21479)

const auto &

218 ↗(On Diff #21479)

Can we just use the same format in clang-tidy options (prepended with 'clang-analyzer-')?

xazax.hun added inline comments.Mar 11 2015, 5:06 AM
clang-tidy/ClangTidy.cpp
218 ↗(On Diff #21479)

Unfortunately if colons are present in the key of a config option, there will be an yaml error message: unexpected ':'. It might be possible to escape it somehow but I find it an uglier solution, so I went ahead with the period syntax. It is more consistent with the tidy checker configuration syntax anyways.

alexfh added inline comments.Mar 11 2015, 6:11 AM
clang-tidy/ClangTidy.cpp
218 ↗(On Diff #21479)

I think, the consistency between the syntax here and in the -analyzer-config analyzer command-line option is more important than the negligible inconvenience of having to enclose option names in quotes. Option values frequently require quotes anyway.

xazax.hun updated this revision to Diff 21710.Mar 11 2015, 6:48 AM
xazax.hun edited edge metadata.

Changes:

  • Renamed the function that sets analyzer checker configuration option and swapped the parameters
  • Using the same format for checker options as the -analyzer-config analyzer command-line option.
  • Minor code tweaks
alexfh added inline comments.Mar 11 2015, 8:03 AM
clang-tidy/ClangTidy.cpp
214 ↗(On Diff #21710)

It's not a check name now. And I think, you can just remove the variable and use OptName.substr(...) as the index.

test/clang-tidy/static-analyzer-config.cpp
1 ↗(On Diff #21710)

You can use single quotes for the -checks option and double quotes without backslash-escaping for the key:.

xazax.hun updated this revision to Diff 21739.Mar 11 2015, 9:48 AM
alexfh accepted this revision.Mar 11 2015, 10:22 AM
alexfh edited edge metadata.

Looks good!

This revision is now accepted and ready to land.Mar 11 2015, 10:22 AM
This revision was automatically updated to reflect the committed changes.