[clang] [Clang][OpenMP] Fix crash on a tuple-like structured binding in a task (PR #241357)
Akash Manna via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 11 07:52:49 PST 2026
https://github.com/akash-manna-sky created https://github.com/llvm/llvm-project/pull/241357
Fixes #116258
A tuple-like structured binding (`std::pair`, `std::tuple`) referenced in a `task` or named in `firstprivate` crashed clang right after the "not yet supported" error. `isOpenMPCapturedDecl` maps struct and array bindings to their `DecompositionDecl` but let tuple-like ones fall into the data-member path, which dereferences a private copy that a binding's DSA never has.
A tuple-like binding has no variable the region can capture, so `isOpenMPCapturedDecl` now returns null for it, as it already did when the binding's DSA was shared.
AI Aided!
>From dcb4cb6f987e0b55cd0ba7d40c728df1e0e58ce9 Mon Sep 17 00:00:00 2001
From: Akash Manna <akash.manna.mymail at gmail.com>
Date: Wed, 11 Nov 2026 11:20:11 +0530
Subject: [PATCH] [Clang][OpenMP] Fix crash on a tuple-like structured binding
in a task
Fixes #116258
A tuple-like structured binding (`std::pair`, `std::tuple`) referenced in a `task` or named in `firstprivate` crashed clang right after the "not yet supported" error. `isOpenMPCapturedDecl` maps struct and array bindings to their `DecompositionDecl` but let tuple-like ones fall into the data-member path, which dereferences a private copy that a binding's DSA never has.
A tuple-like binding has no variable the region can capture, so `isOpenMPCapturedDecl` now returns null for it, as it already did when the binding's DSA was shared.
LLM tools were used for this contribution.
---
clang/lib/Sema/SemaOpenMP.cpp | 7 ++--
.../OpenMP/structured-bindings-messages.cpp | 32 +++++++++++++++++++
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 9acf3b3724527c..f4ff8bc86b606f 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2476,8 +2476,11 @@ VarDecl *SemaOpenMP::isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo,
D = getCanonicalDecl(D);
if (auto *BD = dyn_cast<BindingDecl>(D)) {
- if (!BD->getHoldingVar())
- D = cast<VarDecl>(BD->getDecomposedDecl());
+ // Tuple-like bindings are not capturable; the non-VarDecl paths below
+ // expect a data member with a private copy.
+ if (BD->getHoldingVar())
+ return nullptr;
+ D = cast<VarDecl>(BD->getDecomposedDecl());
}
auto *VD = dyn_cast<VarDecl>(D);
// Do not capture constexpr variables.
diff --git a/clang/test/OpenMP/structured-bindings-messages.cpp b/clang/test/OpenMP/structured-bindings-messages.cpp
index 88316d317ef981..b29eaf0f6def28 100644
--- a/clang/test/OpenMP/structured-bindings-messages.cpp
+++ b/clang/test/OpenMP/structured-bindings-messages.cpp
@@ -147,6 +147,38 @@ void test_pair_map() {
}
}
+// GH116258
+void test_pair_task() {
+ auto [a, b] = std::make_pair(1, 2);
+ // expected-note at -1 4{{'a' declared here}}
+ // expected-note at -2{{'b' declared here}}
+#pragma omp task
+ {
+ use(a);
+ // expected-error at -1{{capturing tuple-like structured binding 'a' is not yet supported in OpenMP}}
+ }
+ [[omp::directive(task)]]
+ {
+ use(b);
+ // expected-error at -1{{capturing tuple-like structured binding 'b' is not yet supported in OpenMP}}
+ }
+#pragma omp taskloop
+ for (int i = 0; i < 2; ++i) {
+ use(a);
+ // expected-error at -1{{capturing tuple-like structured binding 'a' is not yet supported in OpenMP}}
+ }
+#pragma omp task firstprivate(a)
+ {
+ use(a);
+ // expected-error at -1{{capturing tuple-like structured binding 'a' is not yet supported in OpenMP}}
+ }
+#pragma omp parallel firstprivate(a)
+ {
+ use(a);
+ // expected-error at -1{{capturing tuple-like structured binding 'a' is not yet supported in OpenMP}}
+ }
+}
+
void test_tuple() {
std::tuple<int, int, int> t = {1, 2, 3};
auto [x, y, z] = t;
More information about the cfe-commits
mailing list