[clang] [OpenMP] Support capturing structured bindings in OpenMP regions. (PR #190832)
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 1 08:01:45 PDT 2026
================
@@ -4122,30 +4282,47 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
if (isOpenMPTargetExecutionDirective(DKind) &&
!Stack->isLoopControlVariable(VD).first) {
- if (!Stack->checkMappableExprComponentListsForDecl(
- VD, /*CurrentRegionOnly=*/true,
- [this](OMPClauseMappableExprCommon::MappableExprComponentListRef
- StackComponents,
- OpenMPClauseKind) {
- if (SemaRef.LangOpts.OpenMP >= 50)
- return !StackComponents.empty();
- // Variable is used if it has been marked as an array, array
- // section, array shaping or the variable itself.
- return StackComponents.size() == 1 ||
- llvm::all_of(
- llvm::drop_begin(llvm::reverse(StackComponents)),
- [](const OMPClauseMappableExprCommon::
- MappableComponent &MC) {
- return MC.getAssociatedDeclaration() ==
- nullptr &&
- (isa<ArraySectionExpr>(
- MC.getAssociatedExpression()) ||
- isa<OMPArrayShapingExpr>(
- MC.getAssociatedExpression()) ||
- isa<ArraySubscriptExpr>(
- MC.getAssociatedExpression()));
- });
- })) {
+ // Check if VD is already mapped. For DecompositionDecls, also check if
+ // the original variable they decompose has been mapped (via BindingDecl
+ // map clauses).
+ bool AlreadyMapped = Stack->checkMappableExprComponentListsForDecl(
+ VD, /*CurrentRegionOnly=*/true, [this](auto StackComponents, auto) {
+ if (SemaRef.LangOpts.OpenMP >= 50)
+ return !StackComponents.empty();
+ // Variable is used if it has been marked as an array, array
+ // section, array shaping or the variable itself.
+ return StackComponents.size() == 1 ||
+ llvm::all_of(
+ llvm::drop_begin(llvm::reverse(StackComponents)),
+ [](const auto &MC) {
+ return MC.getAssociatedDeclaration() == nullptr &&
+ (isa<ArraySectionExpr>(
+ MC.getAssociatedExpression()) ||
+ isa<OMPArrayShapingExpr>(
+ MC.getAssociatedExpression()) ||
+ isa<ArraySubscriptExpr>(
+ MC.getAssociatedExpression()));
+ });
+ });
+
+ // For DecompositionDecls, check if the original variable has been
+ // mapped.
+ if (!AlreadyMapped && isa<DecompositionDecl>(VD)) {
+ if (const auto *DD = cast<DecompositionDecl>(VD)) {
----------------
alexey-bataev wrote:
```suggestion
const auto *DD = dyn_cast<DecompositionDecl>(VD)
if (!AlreadyMapped && DD) {
```
https://github.com/llvm/llvm-project/pull/190832
More information about the cfe-commits
mailing list