This is an archive of the discontinued LLVM Phabricator instance.

Add UnnecessaryCopyInitialization check to new "performance" module in ClangTidy
ClosedPublic

Authored by flx on Dec 17 2015, 12:36 PM.

Details

Summary

The patch adds a new ClangTidy check that detects when expensive-to-copy types are unnecessarily copy initialized from a const reference that has the same or are larger scope than the copy.

It currently only detects this when the copied variable is const qualified. But this will be extended to non const variables if they are only used in a const fashion.

Diff Detail

Event Timeline

flx updated this revision to Diff 43170.Dec 17 2015, 12:36 PM
flx retitled this revision from to Add UnnecessaryCopyInitialization check to new "performance" module in ClangTidy.
flx updated this object.
flx added a reviewer: alexfh.
alexfh edited edge metadata.Dec 29 2015, 4:24 AM

Thank you for working on this!

A few minor comments.

clang-tidy/performance/UnnecessaryCopyInitialization.cpp
22

Maybe move this to clang-tidy/utils/Matchers.h?

25

This might be useful elsewhere. Let's move it to clang-tidy/utils/LexerUtils.h / .cpp.

clang-tidy/performance/UnnecessaryCopyInitialization.h
17

This should also be in the performance namespace. The add_new_check.py script has been fixed in the meantime.

flx updated this revision to Diff 43743.Dec 29 2015, 10:13 AM
flx edited edge metadata.
flx marked 2 inline comments as done.
alexfh accepted this revision.Dec 30 2015, 2:06 AM
alexfh edited edge metadata.

Looks good! I'll commit the patch for you.

This revision is now accepted and ready to land.Dec 30 2015, 2:06 AM
This revision was automatically updated to reflect the committed changes.