Skip to content

Commit 03e16c8

Browse files
authored
[clang][bytecode] Move generic lambda handling to Compiler (#159733)
So the static invoker's Function still points to the static invoker instead of the call operator of the lambda record. This is important for a later commit.
1 parent 4d197c8 commit 03e16c8

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6077,7 +6077,24 @@ bool Compiler<Emitter>::emitLambdaStaticInvokerBody(const CXXMethodDecl *MD) {
60776077
assert(cast<CompoundStmt>(MD->getBody())->body_empty());
60786078

60796079
const CXXRecordDecl *ClosureClass = MD->getParent();
6080-
const CXXMethodDecl *LambdaCallOp = ClosureClass->getLambdaCallOperator();
6080+
const FunctionDecl *LambdaCallOp;
6081+
assert(ClosureClass->captures().empty());
6082+
if (ClosureClass->isGenericLambda()) {
6083+
LambdaCallOp = ClosureClass->getLambdaCallOperator();
6084+
assert(MD->isFunctionTemplateSpecialization() &&
6085+
"A generic lambda's static-invoker function must be a "
6086+
"template specialization");
6087+
const TemplateArgumentList *TAL = MD->getTemplateSpecializationArgs();
6088+
FunctionTemplateDecl *CallOpTemplate =
6089+
LambdaCallOp->getDescribedFunctionTemplate();
6090+
void *InsertPos = nullptr;
6091+
const FunctionDecl *CorrespondingCallOpSpecialization =
6092+
CallOpTemplate->findSpecialization(TAL->asArray(), InsertPos);
6093+
assert(CorrespondingCallOpSpecialization);
6094+
LambdaCallOp = CorrespondingCallOpSpecialization;
6095+
} else {
6096+
LambdaCallOp = ClosureClass->getLambdaCallOperator();
6097+
}
60816098
assert(ClosureClass->captures().empty());
60826099
const Function *Func = this->getFunction(LambdaCallOp);
60836100
if (!Func)

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -465,23 +465,6 @@ const Function *Context::getOrCreateFunction(const FunctionDecl *FuncDecl) {
465465
// be a non-static member function, this (usually) requiring an
466466
// instance pointer. We suppress that later in this function.
467467
IsLambdaStaticInvoker = true;
468-
469-
const CXXRecordDecl *ClosureClass = MD->getParent();
470-
assert(ClosureClass->captures().empty());
471-
if (ClosureClass->isGenericLambda()) {
472-
const CXXMethodDecl *LambdaCallOp = ClosureClass->getLambdaCallOperator();
473-
assert(MD->isFunctionTemplateSpecialization() &&
474-
"A generic lambda's static-invoker function must be a "
475-
"template specialization");
476-
const TemplateArgumentList *TAL = MD->getTemplateSpecializationArgs();
477-
FunctionTemplateDecl *CallOpTemplate =
478-
LambdaCallOp->getDescribedFunctionTemplate();
479-
void *InsertPos = nullptr;
480-
const FunctionDecl *CorrespondingCallOpSpecialization =
481-
CallOpTemplate->findSpecialization(TAL->asArray(), InsertPos);
482-
assert(CorrespondingCallOpSpecialization);
483-
FuncDecl = CorrespondingCallOpSpecialization;
484-
}
485468
}
486469
// Set up argument indices.
487470
unsigned ParamOffset = 0;

0 commit comments

Comments
 (0)