[flang-commits] [flang] [Flang][OpenMP] : Compilation error involving Cray pointers and data sharing attributes (PR #82481)

Kiran Kumar T P via flang-commits flang-commits at lists.llvm.org
Mon Nov 11 04:19:35 PST 2024


https://github.com/kiranktp updated https://github.com/llvm/llvm-project/pull/82481

>From 127024c2a0d8cb3bb19e76193ef4af45bfea54fe Mon Sep 17 00:00:00 2001
From: Kiran Kumar T P <kirankumar.tp at amd.com>
Date: Wed, 21 Feb 2024 16:24:11 +0530
Subject: [PATCH] [Flang][OpenMP] : Compilation error involving Cray pointers
 and data-sharing attributes

Issue description:
	When DEFAULT DSA is NONE, all data refs must be listed in one of the data sharing clause.
	When a Cray pointer is listed in one of the data sharing clause, Cray pointee can be used in parallel region.
	This is valid as per standard.
	"Cray pointees have the same data-sharing attribute as the storage with which their Cray pointers are associated."
        Currently compiler crashes for default(none).
        Also current semantic checks incorrectly updates the symbol flags related to Craypointee symbols.
        due to this incorrect updation, compiler crashes when default(private) and default(firstprivate) is specified.

Solution:
        Added an additional check to skip updation of symbol flags related to Craypointee symbols.
        This also prevents from checking cray pointee when DEFAULT DSA is NONE.

This patch has code changes and a test case.
---
 flang/lib/Semantics/resolve-directives.cpp    | 26 ++++++++++-------
 .../Semantics/OpenMP/cray-pointer-usage.f90   | 29 +++++++++++++++++++
 2 files changed, 45 insertions(+), 10 deletions(-)
 create mode 100644 flang/test/Semantics/OpenMP/cray-pointer-usage.f90

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 20885587074775..58f62364529ad7 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2242,16 +2242,22 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
       if (Symbol * found{currScope().FindSymbol(name.source)}) {
         if (symbol != found) {
           name.symbol = found; // adjust the symbol within region
-        } else if (GetContext().defaultDSA == Symbol::Flag::OmpNone &&
-            !symbol->test(Symbol::Flag::OmpThreadprivate) &&
-            // Exclude indices of sequential loops that are privatised in
-            // the scope of the parallel region, and not in this scope.
-            // TODO: check whether this should be caught in IsObjectWithDSA
-            !symbol->test(Symbol::Flag::OmpPrivate)) {
-          context_.Say(name.source,
-              "The DEFAULT(NONE) clause requires that '%s' must be listed in "
-              "a data-sharing attribute clause"_err_en_US,
-              symbol->name());
+        } else {
+          // If the symbol is a CrayPointee, no need to updates the symbol
+          // flags.
+          if (symbol->test(Symbol::Flag::CrayPointee)) {
+            return;
+          } else if (GetContext().defaultDSA == Symbol::Flag::OmpNone &&
+              !symbol->test(Symbol::Flag::OmpThreadprivate) &&
+              // Exclude indices of sequential loops that are privatised in
+              // the scope of the parallel region, and not in this scope.
+              // TODO: check whether this should be caught in IsObjectWithDSA
+              !symbol->test(Symbol::Flag::OmpPrivate)) {
+            context_.Say(name.source,
+                "The DEFAULT(NONE) clause requires that '%s' must be listed in "
+                "a data-sharing attribute clause"_err_en_US,
+                symbol->name());
+          }
         }
       }
     }
diff --git a/flang/test/Semantics/OpenMP/cray-pointer-usage.f90 b/flang/test/Semantics/OpenMP/cray-pointer-usage.f90
new file mode 100644
index 00000000000000..189d14b66ceb54
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/cray-pointer-usage.f90
@@ -0,0 +1,29 @@
+!RUN: %python %S/../test_errors.py %s %flang -fopenmp
+subroutine test_crayptr
+  implicit none
+  integer :: I
+  real*8 var(*)
+  pointer(ivar,var)
+  real*8 pointee(8)
+
+  pointee(1) = 42.0
+  ivar = loc(pointee)
+
+  !$omp parallel num_threads(2) default(none) shared(ivar)
+    print *, var(1)
+  !$omp end parallel
+
+  !$omp parallel num_threads(2) default(none) private(ivar)
+    print *, var(1)
+  !$omp end parallel
+
+  !$omp parallel num_threads(2) default(private) shared(ivar)
+    print *, var(1)
+  !$omp end parallel
+
+  !$omp parallel num_threads(2) default(firstprivate) shared(ivar)
+    print *, var(1)
+  !$omp end parallel
+
+end subroutine test_crayptr
+



More information about the flang-commits mailing list