This is an archive of the discontinued LLVM Phabricator instance.

[clang] Skip re-building lambda expressions in parameters to consteval fns.
ClosedPublic

Authored by usaxena95 on Aug 30 2022, 8:00 AM.

Details

Summary

As discussed in this comment, we end up building the lambda twice: once while parsing the function calls and then again while handling the immediate invocation.
This happens specially during removing nested immediate invocation. Eg: When we have another consteval function as the parameter along with this lambda expression. Eg: foo(bar([]{})), foo(bar(), []{})

While removing such nested immediate invocations, we should not rebuild this lambda. (IIUC, rebuilding a lambda would always generate a new type which will never match the original type from parsing)

Fixes: https://github.com/llvm/llvm-project/issues/56183
Fixes: https://github.com/llvm/llvm-project/issues/51695
Fixes: https://github.com/llvm/llvm-project/issues/50455
Fixes: https://github.com/llvm/llvm-project/issues/54872
Fixes: https://github.com/llvm/llvm-project/issues/54587

Diff Detail

Event Timeline

usaxena95 created this revision.Aug 30 2022, 8:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 8:00 AM
usaxena95 requested review of this revision.Aug 30 2022, 8:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 8:00 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
usaxena95 added a subscriber: Restricted Project.
usaxena95 edited the summary of this revision. (Show Details)Aug 30 2022, 8:12 AM
usaxena95 updated this revision to Diff 456684.Aug 30 2022, 8:19 AM

More tests.

Add some test with expected errors as well.

This actually fixes two more issues.
Update release notes and add more documentation.

usaxena95 edited the summary of this revision. (Show Details)Aug 30 2022, 12:08 PM

Gentle ping for review.

ilya-biryukov accepted this revision.Sep 1 2022, 1:42 AM

Thanks, that's a nice find!

Could you also add a test that mentions uses consteval functions in lambda captures inside immediate invocations?
Something like consteval_foo([x = consteval_foo(1)]() consteval { return x; }) and maybe also without consteval on lambda parameter list.
I suspect this should work as expected, just wanted to make sure we capture this in tests

clang/docs/ReleaseNotes.rst
219

NIT

clang/lib/Sema/SemaExpr.cpp
17601–17605

NIT: I tried to expand the meaning of term 'built' to make the comment a bit clearer.

This revision is now accepted and ready to land.Sep 1 2022, 1:42 AM
usaxena95 updated this revision to Diff 457546.Sep 2 2022, 3:04 AM
usaxena95 marked 2 inline comments as done.

Addressed comments and added more tests.

This revision was landed with ongoing or failed builds.Sep 2 2022, 3:31 AM
This revision was automatically updated to reflect the committed changes.