================
@@ -22651,14 +22949,98 @@ class MapBaseChecker final : public 
StmtVisitor<MapBaseChecker, bool> {
 
 public:
   bool VisitDeclRefExpr(DeclRefExpr *DRE) {
-    if (!isa<VarDecl>(DRE->getDecl())) {
+    ValueDecl *D = DRE->getDecl();
+    Expr *E = DRE;
+
+    // Handle BindingDecls by mapping them as member accesses.
+    // When the user writes:
+    //   auto [a, b] = p;
+    //   #pragma omp target map(tofrom:a) map(to:b)
+    // we transform it to:
+    //   #pragma omp target map(tofrom:p.x) map(to:p.y)
+    // This avoids conflicts when different bindings have different map types.
+    if (auto *BD = dyn_cast<BindingDecl>(D)) {
+      auto *DD = cast<DecompositionDecl>(BD->getDecomposedDecl());
+      Expr *BindingExpr = BD->getBinding();
+
+      // Check if the binding is a member expression (struct/class
+      // decomposition).
+      if (auto *ME = dyn_cast_or_null<MemberExpr>(BindingExpr)) {
+
+        // Get the original variable that the decomposition was initialized
+        // from.
+        if (const VarDecl *OrigVar =
+                getOriginalVarOrDiagnose(SemaRef, DD, DRE->getExprLoc())) {
+
+          // Create a new member expression: OrigVar.field.
+          // This transforms map(a) -> map(p.x)
+          DeclarationNameInfo BaseNameInfo(OrigVar->getDeclName(),
+                                           DRE->getLocation());
+          Expr *BaseExpr = DeclRefExpr::Create(
+              SemaRef.Context, DRE->getQualifierLoc(),
+              DRE->getTemplateKeywordLoc(), const_cast<VarDecl *>(OrigVar),
+              /*RefersToEnclosingVariableOrCapture=*/false, BaseNameInfo,
+              OrigVar->getType(), DRE->getValueKind(), nullptr,
+              /*TemplateArgs=*/nullptr, DRE->isNonOdrUse());
+
+          // Create member expression: base.member.
+          E = MemberExpr::Create(
+              SemaRef.Context, BaseExpr, /*IsArrow=*/false,
+              ME->getOperatorLoc(), ME->getQualifierLoc(),
+              ME->getTemplateKeywordLoc(), ME->getMemberDecl(),
+              ME->getFoundDecl(), ME->getMemberNameInfo(),
+              /*TemplateArgs=*/nullptr, ME->getType(), ME->getValueKind(),
+              ME->getObjectKind(), ME->isNonOdrUse());
+
+          // Now process this as a member expression, which will properly
+          // handle the field-level mapping.
+          return Visit(E);
+        }
+        return false;
+      }
+      if (dyn_cast_or_null<ArraySubscriptExpr>(BindingExpr)) {
----------------
alexey-bataev wrote:

```suggestion
      if (isa_and_present<ArraySubscriptExpr>(BindingExpr)) {
```

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