This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Correctly capture bindings in dependent lambdas.
ClosedPublic

Authored by cor3ntin on Nov 2 2022, 5:00 AM.

Details

Summary

Structured bindings were not properly marked odr-used
and therefore captured in generic lambddas.

Fixes #57826

It is unclear to me if further simplification can be gained
through the allowance described in
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0588r1.html.

Either way, I think this makes support for P0588 completes,
but we probably want to add test for that in a separate PR.
(and I lack confidence I understand P0588 sufficiently to assert
the completeness of our cnformance).

Diff Detail

Event Timeline

cor3ntin created this revision.Nov 2 2022, 5:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 5:00 AM
cor3ntin requested review of this revision.Nov 2 2022, 5:00 AM
Herald added a project: Restricted Project. · View Herald Transcript
cor3ntin updated this revision to Diff 472581.Nov 2 2022, 5:01 AM

Forgot to clang-format!

(No changelog, this fixes an unreleased feature)

cor3ntin updated this revision to Diff 472920.Nov 3 2022, 6:34 AM

Use the getPotentiallyDecomposedVarDecl everywhere it makes sense.

Thanks for this! Can you also add a release note for the changes?

clang/include/clang/AST/Decl.h
673

This should be moved up to around line 77 or so (and kept in alphabetical order).

clang/lib/AST/DeclCXX.cpp
3234–3237

No need to use the fully-qualified name (we weren't using it for the calls to isa either).

clang/lib/Sema/SemaDeclCXX.cpp
91
  1. We should rename Decl to something that doesn't shadow the name of a type, since we're here.
  2. Can Decl be null? You're assuming it can't be below with the isa call, so this could switch to cast.
clang/lib/Sema/SemaExpr.cpp
18384–18387
19481–19483
19485
19489–19492

Can re-flow this comment.

Thanks for this! Can you also add a release note for the changes?

Thanks for the Review!
As mentioned this fixes an unreleased feature, hence why I don't think a release note entry is necessary.

cor3ntin added inline comments.Nov 8 2022, 11:47 AM
clang/lib/AST/DeclCXX.cpp
3234–3237

My IDE completion being weird, sorry about that :)

cor3ntin updated this revision to Diff 474080.Nov 8 2022, 1:34 PM
cor3ntin marked 4 inline comments as done.

Address Aaron's comment.

shafik added a subscriber: shafik.Nov 10 2022, 8:42 PM
shafik added inline comments.
clang/lib/Sema/SemaExpr.cpp
18251–18252
cor3ntin updated this revision to Diff 474770.Nov 11 2022, 7:57 AM

Address Shafik's comment

This looks reasonable to me but not confident enough to approve it.

cor3ntin added a reviewer: Restricted Project.Dec 8 2022, 4:47 AM

@aaron.ballman gentle ping. I hope your feedback was addressed to your satisfaction :)

Mostly just nits from me at this point.

clang/lib/AST/DeclCXX.cpp
3232
clang/lib/Sema/SemaDeclCXX.cpp
125

ValueDecl is a subclass of NamedDecl and the diagnostic printer knows how to properly print those -- I assume this is an NFC change (or near enough to it).

clang/lib/Sema/SemaExpr.cpp
19651–19653

Should this comment be moved elsewhere, as it now seems detached from the original logic.

clang/lib/Sema/TreeTransform.h
13326–13328
clang/test/SemaCXX/cxx20-decomposition.cpp
96

Spurious whitespace?

160

Same edit elsewhere. Did clang-format get confused?

cor3ntin added inline comments.Jan 9 2023, 8:22 AM
clang/lib/AST/DeclCXX.cpp
3232

That's future tech, assert would part that as 2 macros arguments!

aaron.ballman added inline comments.Jan 9 2023, 8:23 AM
clang/lib/AST/DeclCXX.cpp
3232

Ugh.

(isa<VarDecl, BindingDecl>(this)) && ...

should suppress that problem, right? I don't feel strongly though.

cor3ntin updated this revision to Diff 487452.Jan 9 2023, 8:27 AM

Address Aaron's comments

cor3ntin added inline comments.Jan 9 2023, 8:31 AM
clang/lib/AST/DeclCXX.cpp
3232

Oh right, that works too :)

clang/lib/Sema/SemaExpr.cpp
19651–19653

I think it's still relevant. the logic is still doing lambda captures, and we still don't need to do anything else, and the fixme is not resolved.

cor3ntin updated this revision to Diff 487453.Jan 9 2023, 8:33 AM

Rewrite assert in DeclCXX.cpp

rymiel added a subscriber: rymiel.Jan 9 2023, 8:33 AM
rymiel added inline comments.
clang/test/SemaCXX/cxx20-decomposition.cpp
160

It can't be clang-format because it would figuratively explode due to https://github.com/llvm/llvm-project/issues/40694! (but it did remind me to investigate that issue)

aaron.ballman added inline comments.Jan 9 2023, 8:42 AM
clang/lib/Sema/SemaDeclCXX.cpp
125

Did this one not work the way I expected?

clang/lib/Sema/SemaExpr.cpp
19651–19653

Okay, fine by me, I thought it might make more sense in DoMarkPotentialCapture, but I see now that the comment relates more to where it is currently.

cor3ntin added inline comments.Jan 9 2023, 8:54 AM
clang/lib/Sema/SemaDeclCXX.cpp
125

I'm still running the tests, It does seem fine :)

cor3ntin updated this revision to Diff 487464.Jan 9 2023, 8:58 AM

Symplify printing a NamedDecl in moved code per Aaron's comment

aaron.ballman accepted this revision.Jan 9 2023, 9:32 AM

LGTM assuming precommit CI doesn't discover any problems from the latest changes.

This revision is now accepted and ready to land.Jan 9 2023, 9:32 AM
This revision was landed with ongoing or failed builds.Jan 9 2023, 12:21 PM
This revision was automatically updated to reflect the committed changes.