[PATCH] D72566: [clang-tidy] Clang tidy is now alias aware

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 12 04:44:52 PST 2020


njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, JonasToth, hokein.
njames93 added projects: clang-tools-extra, clang.
Herald added a subscriber: xazax.hun.

Clang-tidy has had an on growing issue with blindly adding all checks from a module using the `-checks=somemodule-* ` option. If somemodule alias' another enabled check. the check will get ran twice giving duplicated warning and fix options. This can lead to fixes overlapping preventing them from being applied or worse still applying twice resulting in malformed code. There are other issues with ConfigOptions being different in the 2 different instances so one instance of the check may be running a different set of options to the other.

This patch solves these issue by making clang-tidy only run 1 instance of an aliased check even if it has been turned on with multiple names. Warning messages are appended with the original check name if it has been enabled(via cmd line, or config file). If the original check hasn't been enabled then the name will be the first enabled alias that was registered.

Config options are also handled in a similar fashion, see example

  [{ key: MyAliasedName.Option1, value: 0 }.
  { key: OriginalCheckName.Option1, value: 1 }]

If the check `original-check-name` was turned on, then `Option1` will be parsed as being `1`, otherwise it ignores `OriginalCheckName.Option1` key and falls back to the first enabled alias check that declares `Option1`

To declare a check as an alias when you register then check, just add the check this alias' to as a second parameter

  CheckFactories.registerCheck<readability::BracesAroundStatementsCheck>(
      "hicpp-braces-around-statements");
  // Update to
  CheckFactories.registerCheck<readability::BracesAroundStatementsCheck>(
      "hicpp-braces-around-statements", "readability-braces-around-statements");

I haven't added in all the alias declarations in just yet (If you want me to just ask), nor have I added test cases. However once all the alias declarations are added in, the tests fall nicely in line with the current test infrastructure.
Adding this line to the readability-braces-around-statements checks causes no errors, no multiple fix attempts or warning messages.

  // RUN: %check_clang_tidy %s readability-braces-around-statements,hicpp-readability-braces-around-statements %t

Likewise changing it to

  // RUN: %check_clang_tidy %s hicpp-readability-braces-around-statements %t

Also runs without a hitch (obviously warning messages are appended with `[hicpp-readability-braces-around-statements]` instead of `[readability-braces-around-statements]` as above.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72566

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/docs/ReleaseNotes.rst

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72566.237530.patch
Type: text/x-patch
Size: 9747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200112/318ba760/attachment-0001.bin>


More information about the cfe-commits mailing list