[flang-commits] [flang] [flang][semantics][OpenMP] store DSA using ultimate sym (PR #107002)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Mon Sep 2 08:18:56 PDT 2024


https://github.com/tblah created https://github.com/llvm/llvm-project/pull/107002

Previously we tracked data sharing attributes by the symbol itself not by the ultimate symbol. When the private clause came first, subsequent uses of the symbol found a host-associated version instead of the ultimate symbol and so the check didn't consider them to be the same symbol. Always adding and checking for the ultimate symbol ensures that we have the same behaviour no matter the order of clauses.

Closes #78235

>From d852366bdaba86d2cdc2065acf67134fca2445b8 Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Thu, 29 Aug 2024 15:08:25 +0000
Subject: [PATCH] [flang][semantics][OpenMP] store DSA using ultimate sym

Previously we tracked data sharing attributes by the symbol itself not
by the ultimate symbol. When the private clause came first, subsequent
uses of the symbol found a host-associated version instead of the
ultimate symbol and so the check didn't consider them to be the same
symbol. Always adding and checking for the ultimate symbol ensures that
we have the same behaviour no matter the order of clauses.

Closes #78235
---
 flang/lib/Semantics/resolve-directives.cpp   |  4 ++--
 flang/test/Semantics/OpenMP/clause-order.f90 | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Semantics/OpenMP/clause-order.f90

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 4aecb8b8e7b479..17567a555db326 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2514,14 +2514,14 @@ void OmpAttributeVisitor::CheckMultipleAppearances(
       target = &details->symbol();
     }
   }
-  if (HasDataSharingAttributeObject(*target) &&
+  if (HasDataSharingAttributeObject(target->GetUltimate()) &&
       !WithMultipleAppearancesOmpException(symbol, ompFlag)) {
     context_.Say(name.source,
         "'%s' appears in more than one data-sharing clause "
         "on the same OpenMP directive"_err_en_US,
         name.ToString());
   } else {
-    AddDataSharingAttributeObject(*target);
+    AddDataSharingAttributeObject(target->GetUltimate());
     if (privateDataSharingAttributeFlags.test(ompFlag)) {
       AddPrivateDataSharingAttributeObjects(*target);
     }
diff --git a/flang/test/Semantics/OpenMP/clause-order.f90 b/flang/test/Semantics/OpenMP/clause-order.f90
new file mode 100644
index 00000000000000..0213d1849b5ce2
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/clause-order.f90
@@ -0,0 +1,19 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+! Ensure that checks on more than one data-sharing clause do not depend upon
+! the clause order
+
+PROGRAM main
+  INTEGER:: I, N1, N2
+
+  !ERROR: 'n1' appears in more than one data-sharing clause on the same OpenMP directive
+  !$OMP PARALLEL DO PRIVATE(N1) SHARED(N1)
+  DO I=1, 4
+  ENDDO
+  !$OMP END PARALLEL DO
+
+  !ERROR: 'n2' appears in more than one data-sharing clause on the same OpenMP directive
+  !$OMP PARALLEL DO SHARED(N2) PRIVATE(N2)
+  DO I=1, 4
+  ENDDO
+  !$OMP END PARALLEL DO
+END PROGRAM



More information about the flang-commits mailing list