This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Handle constructors in performance-unnecessary-value-param
ClosedPublic

Authored by malcolm.parsons on Dec 21 2016, 5:35 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

malcolm.parsons retitled this revision from to [clang-tidy] Handle constructors in performance-unnecessary-value-param.
malcolm.parsons updated this object.
malcolm.parsons added a subscriber: cfe-commits.
alexfh requested changes to this revision.Dec 21 2016, 6:50 AM
alexfh edited edge metadata.
alexfh added inline comments.
clang-tidy/performance/UnnecessaryValueParamCheck.cpp
114 ↗(On Diff #82230)

How about pulling out variables for **AllDeclRefExprs.begin() and *Function->getDefinition() to remove some boilerplate?

clang-tidy/utils/DeclRefExprUtils.h
35 ↗(On Diff #82230)

Please convert the comment (and the other ones the patch touches) to doxygen style.

55–56 ↗(On Diff #82230)

The comment is now confusing. It says nothing about Decl and doesn't make it clear where the "call expr" (btw, it should either be CallExpr, if it references to the corresponding type or "call expression" otherwise) comes from. Same above.

This revision now requires changes to proceed.Dec 21 2016, 6:50 AM
malcolm.parsons edited edge metadata.
malcolm.parsons marked 3 inline comments as done.

Add some variables.
Improve comments.

aaron.ballman added inline comments.Dec 21 2016, 8:46 AM
clang-tidy/performance/UnnecessaryValueParamCheck.cpp
96 ↗(On Diff #82237)

Instead of using hasBody() and getDefinition(), you should use FunctionDecl::getBody() and pass in an argument to receive the function's definition.

clang-tidy/performance/UnnecessaryValueParamCheck.cpp
96 ↗(On Diff #82237)

I don't want the body - the CXXCtorInitializers are not in it.

clang-tidy/performance/UnnecessaryValueParamCheck.cpp
96 ↗(On Diff #82237)

I should use hasBody() and pass in an argument.

aaron.ballman added inline comments.Dec 21 2016, 8:58 AM
clang-tidy/performance/UnnecessaryValueParamCheck.cpp
96 ↗(On Diff #82237)

You are calling Function-hasBody() followed by Function->getDefinition(), which is what FunctionDecl::getBody() does. The difference is that FunctionDecl::getBody() will also load serialized bodies from the AST (if the body happens to be in a PCH, for instance).

malcolm.parsons edited edge metadata.

Move hasBody check into matcher.
The matcher checks the function is a definition.

clang-tidy/performance/UnnecessaryValueParamCheck.cpp
96 ↗(On Diff #82237)

Do I want to load serialized bodies?

aaron.ballman added inline comments.Dec 21 2016, 9:11 AM
clang-tidy/performance/UnnecessaryValueParamCheck.cpp
96 ↗(On Diff #82237)

I would imagine you would want to deserialize, since you care about the contents of the body, not just the presence of one. This may or may not be important with modules (Richard Smith would be able to give a more definitive answer there).

alexfh added inline comments.Dec 22 2016, 6:50 AM
clang-tidy/performance/UnnecessaryValueParamCheck.cpp
96 ↗(On Diff #82237)

I would suggest writing minimal sane code that works until we have good reasons to write more complex code to support module-enabled builds (and appropriate tests).

clang-tidy/utils/DeclRefExprUtils.h
51 ↗(On Diff #82239)

Please enclose true, DeclRefExpr and other inline code snippets in double backquotes.

aaron.ballman added inline comments.Dec 22 2016, 7:06 AM
clang-tidy/performance/UnnecessaryValueParamCheck.cpp
96 ↗(On Diff #82237)

I think either approach is minimal, sane code and we should understand why we shouldn't use the interface provided by FunctionDecl::getBody() for getting the definition before deciding to not use it.

I *think* we're fine to not use getBody() because the matcher should match over all of the function declarations with a definition, and so eventually it will find the definition with the actual body. In the case that the function definition is serialized, I think this already does the right thing and deserializes it. (I think the only case where we need the deserialization may be when we have a function declaration and we need to traverse from that to the function body, which may be in a different FunctionDecl.) So the use of hasBody() in the matcher above seems like the correct solution to me.

Add double backticks.

alexfh accepted this revision.Dec 30 2016, 3:26 PM
alexfh edited edge metadata.

LG

This revision is now accepted and ready to land.Dec 30 2016, 3:26 PM
This revision was automatically updated to reflect the committed changes.