This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop
ClosedPublic

Authored by flx on Nov 28 2016, 6:45 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

flx updated this revision to Diff 79497.Nov 28 2016, 6:45 PM
flx retitled this revision from to [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop.
flx updated this object.
flx added reviewers: alexfh, sbenza, aaron.ballman.
flx set the repository for this revision to rL LLVM.
flx added a project: Restricted Project.
flx added a subscriber: cfe-commits.
alexfh added inline comments.Nov 29 2016, 2:06 AM
clang-tidy/utils/DeclRefExprUtils.cpp
127 ↗(On Diff #79497)

How will this work with lambdas / local classes declared inside a loop? Not sure if this case is going to happen in real code, but we'd better be clear about the limitations of the implementation.

129 ↗(On Diff #79497)

Do you actually need to bind the node to "declRef"?

flx updated this revision to Diff 79550.Nov 29 2016, 5:48 AM
flx removed rL LLVM as the repository for this revision.
flx marked an inline comment as done.Nov 29 2016, 5:51 AM
flx added inline comments.
clang-tidy/utils/DeclRefExprUtils.cpp
127 ↗(On Diff #79497)

Why would this not work? Could you give an example? The way the function is written it handles my the use case for identifying when moving the parameter is not safe, so I could also just move it into the UnnecessaryValueParamCheck.

alexfh added inline comments.Nov 29 2016, 7:01 AM
clang-tidy/utils/DeclRefExprUtils.cpp
127 ↗(On Diff #79497)

I was thinking about a case where a loop this matcher finds is outside of the function definition and shouldn't be considered:

void F() {
  for (;;) {
    struct C {
      void f(ExpensiveMovableType E) {
        auto F = E;
      }
    };
  }
}
flx added inline comments.Nov 29 2016, 7:46 AM
clang-tidy/utils/DeclRefExprUtils.cpp
127 ↗(On Diff #79497)

This case is not an issue in the check as we're passing f's body statement to the hasLoopStmtAncestor function, so the search is scoped to f's body.

If you're concerned about the case where someone calls this with F's body but expects it to be scoped to f I can just move this function into the check and make it an implementation detail.

flx added a comment.Dec 1 2016, 7:51 PM

Do you have any more comments, Alex?

alexfh accepted this revision.Dec 13 2016, 8:43 AM
alexfh edited edge metadata.

LG modulo comment.

clang-tidy/utils/DeclRefExprUtils.cpp
127 ↗(On Diff #79497)

Making it an implementation detail until other potential users appear sounds good.

This revision is now accepted and ready to land.Dec 13 2016, 8:43 AM
flx updated this revision to Diff 81693.Dec 15 2016, 5:12 PM
flx edited edge metadata.

Thanks, this is fine to commit.

This revision was automatically updated to reflect the committed changes.
flx marked an inline comment as done.