[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.
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 1340a84..fafec47 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6077,7 +6077,24 @@
assert(cast<CompoundStmt>(MD->getBody())->body_empty());
const CXXRecordDecl *ClosureClass = MD->getParent();
- const CXXMethodDecl *LambdaCallOp = ClosureClass->getLambdaCallOperator();
+ const FunctionDecl *LambdaCallOp;
+ assert(ClosureClass->captures().empty());
+ if (ClosureClass->isGenericLambda()) {
+ LambdaCallOp = ClosureClass->getLambdaCallOperator();
+ assert(MD->isFunctionTemplateSpecialization() &&
+ "A generic lambda's static-invoker function must be a "
+ "template specialization");
+ const TemplateArgumentList *TAL = MD->getTemplateSpecializationArgs();
+ FunctionTemplateDecl *CallOpTemplate =
+ LambdaCallOp->getDescribedFunctionTemplate();
+ void *InsertPos = nullptr;
+ const FunctionDecl *CorrespondingCallOpSpecialization =
+ CallOpTemplate->findSpecialization(TAL->asArray(), InsertPos);
+ assert(CorrespondingCallOpSpecialization);
+ LambdaCallOp = CorrespondingCallOpSpecialization;
+ } else {
+ LambdaCallOp = ClosureClass->getLambdaCallOperator();
+ }
assert(ClosureClass->captures().empty());
const Function *Func = this->getFunction(LambdaCallOp);
if (!Func)
diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp
index 6e6c609..22ae64e 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -465,23 +465,6 @@
// be a non-static member function, this (usually) requiring an
// instance pointer. We suppress that later in this function.
IsLambdaStaticInvoker = true;
-
- const CXXRecordDecl *ClosureClass = MD->getParent();
- assert(ClosureClass->captures().empty());
- if (ClosureClass->isGenericLambda()) {
- const CXXMethodDecl *LambdaCallOp = ClosureClass->getLambdaCallOperator();
- assert(MD->isFunctionTemplateSpecialization() &&
- "A generic lambda's static-invoker function must be a "
- "template specialization");
- const TemplateArgumentList *TAL = MD->getTemplateSpecializationArgs();
- FunctionTemplateDecl *CallOpTemplate =
- LambdaCallOp->getDescribedFunctionTemplate();
- void *InsertPos = nullptr;
- const FunctionDecl *CorrespondingCallOpSpecialization =
- CallOpTemplate->findSpecialization(TAL->asArray(), InsertPos);
- assert(CorrespondingCallOpSpecialization);
- FuncDecl = CorrespondingCallOpSpecialization;
- }
}
// Set up argument indices.
unsigned ParamOffset = 0;