This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix references to captured variables in dependant context.
ClosedPublic

Authored by cor3ntin on Apr 19 2022, 9:19 AM.

Details

Summary

D119136 changed how captures are handled in a lambda call operator
declaration, but did not properly handled dependant context,
which led to crash when refering to init-captures in
a trailing return type.

We fix that bug by making transformations more symetric with parsing,
ie. we first create the call operator, then transform the capture,
then compute the type of the lambda call operaror.

This ensures captures exist and have the right type when
we parse a trailing requires-clause / return type.

Diff Detail

Event Timeline

cor3ntin created this revision.Apr 19 2022, 9:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2022, 9:19 AM
cor3ntin requested review of this revision.Apr 19 2022, 9:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2022, 9:19 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cor3ntin updated this revision to Diff 423653.Apr 19 2022, 9:27 AM

Remove some whitespace only changes.

cor3ntin updated this revision to Diff 423656.Apr 19 2022, 9:31 AM

Fix whitespace changes (again)

cor3ntin updated this revision to Diff 423657.Apr 19 2022, 9:37 AM

More cleanups and formatting.

aaron.ballman added inline comments.Apr 19 2022, 10:18 AM
clang/lib/Sema/SemaLambda.cpp
467–468

IIRC, we added buildLambdaScope() quite recently, so perhaps that function should go away now and callers just call buildLambdaScopeCaptures() directly?

1297–1301

Out of curiosity, why isn't this part of CompleteLambdaCallOperator() like all the other setters? (Should template instantiation also be setting this?)

1298–1303

The previous logic was to enter a mangling context and then check params, but the new logic checks params outside of the mangling context. Is that intentional?

cor3ntin updated this revision to Diff 423671.Apr 19 2022, 10:39 AM
  • Get rid of buildLambdaScopeCaptures
  • Set the call operator inner loc in CompleteLambdaCallOperator (+ tests)
clang/lib/Sema/SemaLambda.cpp
1298–1303

It has no impact one way or another, but we can't call CompleteLambdaCallOperator in the context of the class, so this is simpler.

cor3ntin marked an inline comment as done.Apr 19 2022, 10:41 AM
cor3ntin added inline comments.
clang/lib/Sema/SemaLambda.cpp
467–468

I got rid of buildLambdaScopeCaptures - as we also set things related to parameters / mutable, it makes more sense that way

1297–1301

No good reason - and template should have set this

cor3ntin updated this revision to Diff 423675.Apr 19 2022, 10:54 AM
cor3ntin marked an inline comment as done.

Remove startLambdaDefinition which is no longer used

aaron.ballman accepted this revision.Apr 19 2022, 11:22 AM

LGTM, but please wait a bit before landing so other reviewers have time to weigh in (should be fine to land tomorrow sometime if you don't hear back).

clang/lib/Sema/SemaLambda.cpp
1298–1303

Okay, thanks for the explanation!

This revision is now accepted and ready to land.Apr 19 2022, 11:22 AM

@erichkeane I will land that later today to unstuck people relying on main, let me know if you still want to have a look

@erichkeane I will land that later today to unstuck people relying on main, let me know if you still want to have a look

I didn't see anything on a quick pass, so LGTM!

This revision was landed with ongoing or failed builds.Apr 20 2022, 6:35 AM
This revision was automatically updated to reflect the committed changes.

@erichkeane @aaron.ballman Thanks! I'll keep an eye out for further issues.

erichkeane added inline comments.Apr 20 2022, 11:51 AM
clang/lib/Sema/TreeTransform.h
13165

So I just noticed this: What happens when NewTrailingRequiresClause is invalid here? I think the call to 'get' below on this would assert, right? This perhaps needs to return ExprError in that case.