This is an archive of the discontinued LLVM Phabricator instance.

[NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy
ClosedPublic

Authored by Manna on Apr 4 2023, 2:14 PM.

Details

Summary

Reported by Coverity:

AUTO_CAUSES_COPY
Unnecessary object copies can affect performance

  1. Inside FrontendActions.cpp file,

In clang::​DumpModuleInfoAction::​ExecuteAction(): Using the auto keyword without an & causes the copy of an object of type pair.

  1. Inside ComputeDependence.cpp file,

In clang::​computeDependence(clang::​OverloadExpr *, bool, bool, bool): Using the auto keyword without an & causes the copy of an object of type TemplateArgumentLoc.

Diff Detail

Event Timeline

Manna created this revision.Apr 4 2023, 2:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 2:14 PM
Manna requested review of this revision.Apr 4 2023, 2:14 PM
Manna set the repository for this revision to rG LLVM Github Monorepo.Apr 5 2023, 5:37 AM
Manna added a subscriber: cfe-commits.
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2023, 5:37 AM
erichkeane accepted this revision.Apr 5 2023, 6:13 AM

Previous comments on this were here: https://reviews.llvm.org/D147552. I've copy/pasted them into here to keep history at least somewhat reasonable.

This LGTM.

clang/lib/AST/ComputeDependence.cpp
753

Ends up being pretty sizable, TemplateArgumentLoc has a TemplateArgument (which we typically pass around by value), but it also has a TemplateArgumentLocInfo, which is a pair of pointers + a pair of source locations.

clang/lib/Frontend/FrontendActions.cpp
885

A pair of a string and the other type, definitely worth saving the copies.

This revision is now accepted and ready to land.Apr 5 2023, 6:13 AM
Manna added a comment.Apr 5 2023, 7:25 AM

Thanks @erichkeane.

Is this known failure?

Failed Tests (1):

Clang :: SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp

https://buildkite.com/llvm-project/premerge-checks/builds/145026#01874e21-00e2-47a9-9bc4-975357d197ef

Thanks @erichkeane.

Is this known failure?

Failed Tests (1):

Clang :: SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp

https://buildkite.com/llvm-project/premerge-checks/builds/145026#01874e21-00e2-47a9-9bc4-975357d197ef

Looks like the commit that added that test got reverted here d5c428356f6ee107a97977eb9ef1aa4d5fa0c378 because it caused the test to fail, so it looks like the answer is 'yes'.

Manna added a comment.Apr 5 2023, 7:35 AM

Thanks @erichkeane.

Is this known failure?

Failed Tests (1):

Clang :: SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp

https://buildkite.com/llvm-project/premerge-checks/builds/145026#01874e21-00e2-47a9-9bc4-975357d197ef

Looks like the commit that added that test got reverted here d5c428356f6ee107a97977eb9ef1aa4d5fa0c378 because it caused the test to fail, so it looks like the answer is 'yes'.

Thanks @erichkeane for confirming!

Manna closed this revision.Apr 10 2023, 6:19 AM

I am closing this revision since it's already been pushed: https://reviews.llvm.org/rG59cb47015a18