Skip to content

[flang][semantics][OpenMP] store DSA using ultimate sym #107002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

tblah
Copy link
Contributor

@tblah tblah commented Sep 2, 2024

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

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 llvm#78235
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Sep 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 2, 2024

@llvm/pr-subscribers-flang-semantics

Author: Tom Eccles (tblah)

Changes

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


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+2-2)
  • (added) flang/test/Semantics/OpenMP/clause-order.f90 (+19)
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

@llvmbot
Copy link
Member

llvmbot commented Sep 2, 2024

@llvm/pr-subscribers-flang-openmp

Author: Tom Eccles (tblah)

Changes

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


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+2-2)
  • (added) flang/test/Semantics/OpenMP/clause-order.f90 (+19)
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

Copy link
Contributor

@luporl luporl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

OpenACC may have the same issue.

@tblah tblah merged commit 4befe65 into llvm:main Sep 3, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang][OpenMP] compiler not issuing error when both private and shared clause is specified for same variable
4 participants