================
@@ -4672,43 +4672,81 @@ static bool
 buildCapturedStmtCaptureList(Sema &S, CapturedRegionScopeInfo *RSI,
                              SmallVectorImpl<CapturedStmt::Capture> &Captures,
                              SmallVectorImpl<Expr *> &CaptureInits) {
+  bool HasError = false; // Track if any errors occurred.
+  llvm::SmallPtrSet<VarDecl *, 4> CapturedDecomposed;
   for (const sema::Capture &Cap : RSI->Captures) {
     if (Cap.isInvalid())
       continue;
 
+    ValueDecl *CapVar = nullptr;
+    if (Cap.isVariableCapture()) {
+      CapVar = Cap.getVariable();
+      if (auto *BD = dyn_cast<BindingDecl>(CapVar)) {
+        if (RSI->CapRegionKind == CR_OpenMP && BD->getHoldingVar()) {
+          S.Diag(Cap.getLocation(), diag::err_capture_tuple_binding_openmp)
+              << CapVar;
+          S.Diag(CapVar->getLocation(), diag::note_entity_declared_at)
+              << CapVar;
+          HasError = true; // Mark error but continue.
+          continue;        // Skip this capture, move to next.
----------------
zahiraam wrote:

For this test case:

```
void test_target_explicit_map() {
    Point p{1, 2};
    auto [a, b] = p;  // Creates DecompositionDecl with BindingDecls a, b.

    #pragma omp target map(tofrom: p)
    {
      a = a + 1;  // References BindingDecl 'a' inside captured region.
      b = b + 1;  // References BindingDecl 'b' inside captured region.
    }
  }
```
  
The call stack reaching line 4685 is:
`ActOnOpenMPRegionEnd()` -> `ActOnCapturedRegionEnd()` -> 
`buildCapturedStmtCaptureList()` -> Line 4685.

The reset in `SemaExpr.cpp` happens during expression evaluation.
Line 4685 runs during capture list construction (earlier phase), so it 
processes `BindingDecls` before they get remapped elsewhere.
Line 4685 is exercised by any `OpenMP` construct that captures structured 
bindings. The same logic applies to line 1975 in `SemaLambda.cpp` for `lambda` 
captures. I added a comment in the code to clarify this,  and added tests for 
the lambda case.

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