[flang-commits] [flang] [Flang][OpenMP] Fix DEFAULT(NONE) check for Cray pointers in nested OpenMP directives (PR #190764)

via flang-commits flang-commits at lists.llvm.org
Tue Apr 7 02:59:41 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: Urvi Rav (ravurvi20)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/190764.diff


2 Files Affected:

- (modified) flang/lib/Semantics/resolve-directives.cpp (+1-1) 
- (modified) flang/test/Semantics/OpenMP/cray-pointer-usage.f90 (+17) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/190764


More information about the flang-commits mailing list