This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.
ClosedPublic

Authored by xgupta on Feb 26 2021, 11:13 AM.

Details

Summary

Until now when determining all the const uses of a VarDecl we only considered
how the variable itself was used. This change extends checking for const usages
of the type's members as well.

This increases the number of true positives for various performance checks that
share the same const usage analysis.

Diff Detail

Event Timeline

flx created this revision.Feb 26 2021, 11:13 AM
flx requested review of this revision.Feb 26 2021, 11:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 26 2021, 11:13 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Eugene.Zelenko added a project: Restricted Project.
flx updated this revision to Diff 326798.Feb 26 2021, 2:03 PM

Add tests for PerformanceUnnecssaryCopyInitialization check which actually uses
decl_ref_expr::isOnlyUsedAsConst().

flx added a comment.Mar 15 2021, 1:21 PM

Hi,

could someone please take a look at this? Thanks!

flx added a comment.Apr 5 2021, 10:56 AM

Could someone take a look at this change?

flx added a comment.May 12 2021, 7:00 AM

Could someone take a look at this patch? Thank you!

njames93 accepted this revision.May 12 2021, 8:28 AM

LGTM, but with a very minor nit.

clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
46

Can you use hasObjectExpression instead of has here, Its a bit more explicit in what we are matching.

This revision is now accepted and ready to land.May 12 2021, 8:28 AM
xgupta commandeered this revision.Jul 23 2023, 7:22 AM
xgupta added a reviewer: flx.
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2023, 7:22 AM
xgupta updated this revision to Diff 543282.Jul 23 2023, 7:24 AM

Rebase and address one last comment.

I think now it will be fine to commit?

xgupta marked an inline comment as done.Jul 23 2023, 7:24 AM

Some release notes would be nice, looks like impacted checks are: performance-unnecessary-copy-initialization, performance-inefficient-vector-operation, performance-unnecessary-value-param, performance-for-range-copy. Some info about "Improved XYZ check by handling handling more properly const member expressions" or something similar. And wait for test results, I tried this change locally, and tests were failing.

xgupta updated this revision to Diff 543287.Jul 23 2023, 8:10 AM

Added release note and fix unit test case

PiotrZSL added inline comments.Jul 23 2023, 8:15 AM
clang-tools-extra/docs/ReleaseNotes.rst
539

Split it multiple entry's, 1 per check, keep in alphabetical order.
and maybe keep it in format;
"Improved XYZ check by extending const usage analysis to include the type's members."

PiotrZSL added inline comments.Jul 23 2023, 8:16 AM
clang-tools-extra/docs/ReleaseNotes.rst
539

And if we already got entry for some check, just try adding this info to that.

xgupta updated this revision to Diff 543299.Jul 23 2023, 10:15 AM

Update release note

xgupta updated this revision to Diff 543300.Jul 23 2023, 10:18 AM
xgupta marked 2 inline comments as done.

minor update

PiotrZSL added inline comments.Jul 23 2023, 10:28 AM
clang-tools-extra/docs/ReleaseNotes.rst
539

sort them by name, performance checks are before readability

xgupta updated this revision to Diff 543307.Jul 23 2023, 10:48 AM

Address comment

xgupta marked an inline comment as done.Jul 23 2023, 10:48 AM