This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Implement lambda static invokers
ClosedPublic

Authored by tbaeder on May 8 2023, 4:43 AM.

Details

Summary

Emit custom byte code for the static invoker function.

Unfortunately, there are a few (RVO-related) cases we can't handle yet. There's a bigger refactoring for the initialization stuff coming that will hopefully take care of that.

Diff Detail

Event Timeline

tbaeder created this revision.May 8 2023, 4:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2023, 4:43 AM
tbaeder requested review of this revision.May 8 2023, 4:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2023, 4:43 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tbaeder updated this revision to Diff 520330.May 8 2023, 4:43 AM
tbaeder updated this revision to Diff 520331.May 8 2023, 4:46 AM
aaron.ballman added inline comments.May 15 2023, 11:07 AM
clang/lib/AST/Interp/ByteCodeEmitter.cpp
100–103

I don't like the isa followed by a cast code smell, but rewriting it to use dyn_cast is perhaps kind of ugly:

bool IsEligibleForCompilation = false;
if (const auto *MD = dyn_cast<CXXMethodDecl>())
  IsEligibleForCompilation = MD->isLambdaStaticInvoker();
if (!IsEligibleForCompilation)
  IsEligibleForCompilation = FuncDecl->isConstexpr();

WDYT?

clang/lib/AST/Interp/ByteCodeStmtGen.cpp
125–126

Why do we need to do lvalue-to-rvalue conversion at all? The caller of the lambda function call operator would have already performed that conversion, right?

tbaeder added inline comments.May 16 2023, 6:25 AM
clang/lib/AST/Interp/ByteCodeEmitter.cpp
100–103

I'm not a fan of that pattern either. I've seen it elsewhere in the code base, didn't like it, but couldn't come up with an objective downside either. If you're also not a fan, I have no problem with changing it.

tbaeder updated this revision to Diff 522587.May 16 2023, 6:33 AM
tbaeder marked an inline comment as done.
This revision is now accepted and ready to land.May 16 2023, 7:32 AM
This revision was landed with ongoing or failed builds.Jul 25 2023, 11:42 PM
This revision was automatically updated to reflect the committed changes.