[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 13 09:51:30 PDT 2024
================
@@ -8485,6 +8485,53 @@ class LValueExprEvaluator
};
} // end anonymous namespace
+/// Get an lvalue to a field of a lambda's closure type.
+static bool HandleLambdaCapture(EvalInfo &Info, const Expr *E, LValue &Result,
+ const CXXMethodDecl *MD, const FieldDecl *FD,
+ bool LValueToRValueConversion) {
+ // Static lambda function call operators can't have captures. We already
+ // diagnosed this, so bail out here.
+ if (MD->isStatic()) {
+ assert(Info.CurrentCall->This == nullptr &&
+ "This should not be set for a static call operator");
+ return false;
+ }
+
+ // Start with 'Result' referring to the complete closure object...
+ if (MD->isExplicitObjectMemberFunction()) {
+ // Self may be passed by reference or by value.
+ auto *Self = MD->getParamDecl(0);
+ if (Self->getType()->isReferenceType()) {
+ APValue *RefValue = Info.getParamSlot(Info.CurrentCall->Arguments, Self);
+ Result.setFrom(Info.Ctx, *RefValue);
+ } else {
+ auto *VD = Info.CurrentCall->Arguments.getOrigParam(Self);
+ auto *Frame =
+ Info.getCallFrameAndDepth(Info.CurrentCall->Arguments.CallIndex)
+ .first;
+ auto Version = Info.CurrentCall->Arguments.Version;
----------------
AaronBallman wrote:
Should spell these types out because they're not spelled out in the initialization.
https://github.com/llvm/llvm-project/pull/81102
More information about the cfe-commits
mailing list