================ @@ -4684,6 +4684,29 @@ LValue CodeGenFunction::EmitLValueForLambdaField(const FieldDecl *Field, else LambdaLV = MakeAddrLValue(AddrOfExplicitObject, D->getType().getNonReferenceType()); + + // Make sure we have an lvalue to the lambda itself and not a derived class. + auto *ThisTy = D->getType().getNonReferenceType()->getAsCXXRecordDecl(); + auto *LambdaTy = cast<CXXRecordDecl>(Field->getParent()); + if (ThisTy != LambdaTy) { + CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/true, + /*DetectVirtual=*/false); + + [[maybe_unused]] bool Derived = ThisTy->isDerivedFrom(LambdaTy, Paths); + assert(Derived && "Type not derived from lambda type?"); ---------------- Sirraide wrote:
On that note, as for actually emitting the cast, is it worth it doing that once when we start emitting the lambda and then just reusing the computed lvalue instead of emitting the cast every time we need to access a capture? Or do we just let the optimiser clean that up? Asking because I’m not too familiar w/ how situations like these are typically handled in codegen. https://github.com/llvm/llvm-project/pull/89828 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits