This is an archive of the discontinued LLVM Phabricator instance.

Ensure that we traverse non-op() method bodys of lambdas
ClosedPublic

Authored by steveire on Jan 28 2021, 3:43 PM.

Diff Detail

Event Timeline

steveire requested review of this revision.Jan 28 2021, 3:43 PM
steveire created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 28 2021, 3:43 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
steveire added inline comments.Jan 28 2021, 3:44 PM
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
485

I don't know how to create a lambda with a default ctor body.

rsmith added inline comments.Jan 28 2021, 4:12 PM
clang/include/clang/AST/RecursiveASTVisitor.h
2065–2066

In principle there can be multiple declarations of the lambda call operator if we merge multiple lambdas from different modules; we should check for any declaration of the operator() here rather than the exact one that getLambdaCallOperator returns.

I'd previously thought we could use isLambdaCallOperator here, but I think that's wrong: for a generic lambda, that would skip instantiations of the templated operator(), whereas I think you only want to skip the body of the primary template in that case, and still visit the instantiations, right? Eg, given:

auto x = [](auto n) { return n; };
int n = x(0);

... you'd want to skip the body of the template <lambda>::operator()(T), but you'd still want to visit the body of <lambda>::operator()<int>(int), right?

clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
485

I think that's probably not actually possible, sorry for misleading you on that! You can introduce a copy constructor with a body (by giving A a non-trivial copy constructor), though, if you want to test that.

steveire updated this revision to Diff 319987.Jan 28 2021, 4:17 PM

Use helper method

steveire added inline comments.Jan 28 2021, 4:30 PM
clang/include/clang/AST/RecursiveASTVisitor.h
2065–2066

Yes, the instantiations should still be visited here.

clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
485

Thanks! I think I have the copy-ctor case covered already. Is something missing?

rsmith accepted this revision.Jan 28 2021, 4:40 PM
This revision is now accepted and ready to land.Jan 28 2021, 4:40 PM
rsmith added inline comments.Jan 28 2021, 4:41 PM
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
485

Oh, right you are. Looks good :)

This revision was landed with ongoing or failed builds.Jan 28 2021, 4:49 PM
This revision was automatically updated to reflect the committed changes.