[clang] [OpenMP] Support capturing structured bindings in OpenMP regions. (PR #190832)

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 30 08:26:12 PDT 2026


================
@@ -1407,7 +1423,35 @@ bool CodeGenFunction::EmitOMPLastprivateClauseInit(
     for (const Expr *IInit : C->private_copies()) {
       // Keep the address of the original variable for future update at the end
       // of the loop.
-      const auto *OrigVD = cast<VarDecl>(cast<DeclRefExpr>(*IRef)->getDecl());
+      const auto *OrigDecl = cast<DeclRefExpr>(*IRef)->getDecl();
+      // Handle BindingDecls with the same level of support as VarDecls.
+      if (const auto *BD = dyn_cast<BindingDecl>(OrigDecl)) {
+        if (AlreadyEmittedVars.insert(cast<ValueDecl>(BD->getCanonicalDecl()))
+                .second) {
+          const auto *DestVD =
+              cast<VarDecl>(cast<DeclRefExpr>(*IDestRef)->getDecl());
+          // Get the original binding address.
+          DeclRefExpr DRE(getContext(), const_cast<BindingDecl *>(BD),
+                          /*RefersToEnclosingVariableOrCapture=*/true,
+                          BD->getType(), VK_LValue, (*IRef)->getExprLoc());
+          PrivateScope.addPrivate(DestVD, EmitLValue(&DRE).getAddress());
+
+          if (IInit) {
+            const auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IInit)->getDecl());
+            // Emit private VarDecl with copy init.
+            EmitDecl(*VD);
----------------
alexey-bataev wrote:

It never calls emitLastprivateConditionalInit, while checkForLastprivateConditionalUpdate skips BindingDecls. So, `lastprivate(conditional: a)` on a binding behaves as ordinary lastprivate with no diagnostic. Either diagnose as unsupported or handle it. Add a test either way.

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


More information about the cfe-commits mailing list