[flang-commits] [flang] [Flang][OpenMP] Fix DEFAULT(NONE) check for Cray pointers in nested OpenMP directives (PR #190764)
Urvi Rav via flang-commits
flang-commits at lists.llvm.org
Tue Apr 7 02:59:05 PDT 2026
https://github.com/ravurvi20 created https://github.com/llvm/llvm-project/pull/190764
Fixes - [#190750](https://github.com/llvm/llvm-project/issues/190750)
In `resolve-directives.cpp`, the DEFAULT(NONE) verification was previously using `IsObjectWithDSA`, which only checks the current directive context. In cases with nested OpenMP regions, this leads to incorrect diagnostics because variables declared in enclosing directive contexts were not considered during the lookup.
The check has been updated to use `IsObjectWithVisibleDSA` instead. This function looks at the visible data-sharing attributes across enclosing contexts, ensuring that variables declared in outer directives are correctly recognized when used inside nested constructs.
>From b3d3adfd0ced4686f7dc3c361dfd29ce54adb6c8 Mon Sep 17 00:00:00 2001
From: Urvi Rav <urvi.rav20 at gmail.com>
Date: Tue, 7 Apr 2026 04:46:26 -0500
Subject: [PATCH] Updated resolve-directives.cpp for nested openmp regions
---
flang/lib/Semantics/resolve-directives.cpp | 2 +-
.../Semantics/OpenMP/cray-pointer-usage.f90 | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index fb241d2606b47..991dce801bb01 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2780,7 +2780,7 @@ void OmpAttributeVisitor::CreateImplicitSymbols(
if (sym->GetUltimate().test(Symbol::Flag::CrayPointee)) {
std::string crayPtrName{
semantics::GetCrayPointer(*sym).name().ToString()};
- if (!IsObjectWithDSA(*currScope().FindSymbol(crayPtrName))) {
+ if (!IsObjectWithVisibleDSA(*currScope().FindSymbol(crayPtrName))) {
context_.Say(loc,
"The DEFAULT(NONE) clause requires that the Cray Pointer '%s' must be listed in a data-sharing attribute clause"_err_en_US,
crayPtrName);
diff --git a/flang/test/Semantics/OpenMP/cray-pointer-usage.f90 b/flang/test/Semantics/OpenMP/cray-pointer-usage.f90
index 3f13338a19f7f..ba9166d6a47e8 100644
--- a/flang/test/Semantics/OpenMP/cray-pointer-usage.f90
+++ b/flang/test/Semantics/OpenMP/cray-pointer-usage.f90
@@ -43,3 +43,20 @@ subroutine test_cray_pointer_usage
print *, var(1)
!$omp end parallel
end subroutine test_cray_pointer_usage
+
+subroutine test_nested_cray_pointer
+ implicit none
+ real :: X, B
+ pointer(P, B)
+
+ X = 1.0
+ P = loc(X)
+
+ ! Test nested constructs: pointer declared in outer parallel, pointee used in nested critical
+ ! This should compile successfully - pointer P is in shared clause of parallel
+ !$omp parallel default(none) shared(P, X)
+ !$omp critical
+ B = B + 2.0
+ !$omp end critical
+ !$omp end parallel
+end subroutine test_nested_cray_pointer
More information about the flang-commits
mailing list