================
@@ -1496,8 +1540,41 @@ void CodeGenFunction::EmitOMPLastprivateClauseFinal(
     auto ISrcRef = C->source_exprs().begin();
     auto IDestRef = C->destination_exprs().begin();
     for (const Expr *AssignOp : C->assignment_ops()) {
-      const auto *PrivateVD =
-          cast<VarDecl>(cast<DeclRefExpr>(*IRef)->getDecl());
+      const auto *PrivateDecl = cast<DeclRefExpr>(*IRef)->getDecl();
+      // Handle BindingDecls with the same level of support as VarDecls.
+      if (const auto *BD = dyn_cast<BindingDecl>(PrivateDecl)) {
+        QualType Type = BD->getType();
+        const auto *CanonicalBD = cast<ValueDecl>(BD->getCanonicalDecl());
+        if (AlreadyEmittedVars.insert(CanonicalBD).second) {
+          // Get the private address. The BindingDecl was registered in
+          // PrivateScope during initialization, so look it up in LocalDeclMap.
+          auto It = LocalDeclMap.find(CanonicalBD);
+          if (It == LocalDeclMap.end()) {
+            It = LocalDeclMap.find(BD);
+          }
+          assert(It != LocalDeclMap.end() &&
+                 "lastprivate BindingDecl not found in LocalDeclMap");
----------------
alexey-bataev wrote:

Why need a double lookup here? This is fragile. Either explain the invariant 
(which key is guaranteed present and why) or use OMPPrivatizedBindings to 
retrieve the private address since that map was specifically designed for 
BindingDecl remapping. If neither map holds the private address at this point, 
the entire lastprivate-final path for BindingDecls is broken.

https://github.com/llvm/llvm-project/pull/190832
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to