[clang] [Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (PR #86265)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 18 19:32:34 PDT 2024


================
@@ -14636,6 +14645,20 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
                                     /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // Parts other than the capture e.g. the lambda body might still contain a
+  // pattern that an outer fold expression would expand.
+  //
+  // We don't have a way to propagate up the ContainsUnexpandedParameterPack
+  // flag from a Stmt, so we have to revisit the lambda.
+  if (!LSICopy.ContainsUnexpandedParameterPack) {
+    llvm::SmallVector<UnexpandedParameterPack> UnexpandedPacks;
+    getSema().collectUnexpandedParameterPacksFromLambda(NewCallOperator,
+                                                        UnexpandedPacks);
+    // FIXME: Should we call Sema::DiagnoseUnexpandedParameterPacks() instead?
+    // Unfortunately, that requires the LambdaScopeInfo to exist, which has been
+    // removed by ActOnFinishFunctionBody().
+    LSICopy.ContainsUnexpandedParameterPack = !UnexpandedPacks.empty();
+  }
----------------
zyn0217 wrote:

Despite these, I have another concern on performance issue after some deliberation. This is actually a workaround given that we don't have any flags on a `Stmt` to tell whether it contains unexpanded expressions - what we do now leads to visiting the lambda body twice, which might cause some impact in lambda instantiation, if the body is large enough.

A compromise is, we remove this traversal in this patch and *leave it for future fixes*. (Sigh!)

https://github.com/llvm/llvm-project/pull/86265


More information about the cfe-commits mailing list