[PATCH] D114317: [clang-tidy][WIP] Do not run perfect alias checks

Carlos Galvez via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 20 06:01:08 PST 2021


carlosgalvezp created this revision.
carlosgalvezp added a reviewer: aaron.ballman.
Herald added subscribers: jeroen.dobbelaere, kbarton, xazax.hun, nemanjai.
carlosgalvezp requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Find "perfect aliases" and remove them from the list
of checks to run. On large codebases, this can save
up to 30% runtime, which is not negligible.

A "perfect alias" is an alias that:

- Is of the same check class as the primary check.
- Has all configuration options the same as the primary check.

NOTE TO REVIEWERS:

This is a WIP, quick and dirty PoC, so the code is not pretty,
well structured nor optimal.

The intention is to make this feature opt-in via config/CLI.
I.e. turned off by default -> should not break things.

Before polishing the patch I'd like to get feedback about
whether this is the desired direction, and in general if
I'm putting the pieces in the right places.

DESIGN GOALS:

- No impact on check developers, other than having to register the check via the new macro instead of the regular function.

- Only perfect aliases to be removed.

MISSING BITS/REQUIREMENTS FROM THE RFC:

- It would be desirable to still keep the diagnostic/fixit for the alias checks. I don't know how to implement this in practice. It would require each check to call the diag() function in a loop for all alias checks. This would be very disruptive for check developers. I cannot implement this in the ClangTidyCheck class because the diag() function returns an object, so I can't put a loop there.

- Ideally, it would be nice to show "CACHED - 0 seconds" or "SKIPPED - 0 seconds" in the profiling output (currently, the alias check just doesn't  show up). Again, I don't know how to implement this feature in a non-intrusive way that makes sense.

Suggestions are very welcome for these two bits! Otherwise I am
personally happy to skip them.

Current working test:

clang-tidy -checks=-*,*-c-arrays,*-in-classes

The result is:

- Only one of the 3 "c-arrays" check is run (the primary check), because the other 2 checks are perfect aliases.

- Both of the "-in-classes" checks (cppcoreguidelines, misc) are run, because they have different configuration options.


https://reviews.llvm.org/D114317

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114317.388701.patch
Type: text/x-patch
Size: 11478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211120/86d1885a/attachment.bin>


More information about the cfe-commits mailing list