Skip to content

[flang][OpenMP] Treat POINTER variables as valid variable list items #111722

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
Oct 9, 2024

Conversation

kparzysz
Copy link
Contributor

@kparzysz kparzysz commented Oct 9, 2024

Follow-up to 418920b, which started diagnosing the legality of objects in OpenMP clauses (and caused some test failures).

Follow-up to 418920b, which started
diagnosing the legality of objects in OpenMP clauses (and caused some
test failures).
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Oct 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 9, 2024

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)

Changes

Follow-up to 418920b, which started diagnosing the legality of objects in OpenMP clauses (and caused some test failures).


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

3 Files Affected:

  • (modified) flang/lib/Semantics/check-omp-structure.cpp (+7-3)
  • (modified) flang/lib/Semantics/check-omp-structure.h (+1)
  • (added) flang/test/Semantics/OpenMP/shared-pointer.f90 (+13)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index cf90c92bbf3c4d..a54fa14730321b 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -200,8 +200,12 @@ bool OmpStructureChecker::CheckAllowedClause(llvmOmpClause clause) {
   return CheckAllowed(clause);
 }
 
+bool OmpStructureChecker::IsVariableListItem(const Symbol &sym) {
+  return evaluate::IsVariable(sym) || sym.attrs().test(Attr::POINTER);
+}
+
 bool OmpStructureChecker::IsExtendedListItem(const Symbol &sym) {
-  return evaluate::IsVariable(sym) || sym.IsSubprogram();
+  return IsVariableListItem(sym) || sym.IsSubprogram();
 }
 
 bool OmpStructureChecker::IsCloselyNestedRegion(const OmpDirectiveSet &set) {
@@ -2351,7 +2355,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause &x) {
     SymbolSourceMap symbols;
     GetSymbolsInObjectList(*objList, symbols);
     for (const auto &[sym, source] : symbols) {
-      if (!evaluate::IsVariable(sym)) {
+      if (!IsVariableListItem(*sym)) {
         deferredNonVariables_.insert({sym, source});
       }
     }
@@ -3428,7 +3432,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::To &x) {
   SymbolSourceMap symbols;
   GetSymbolsInObjectList(objList, symbols);
   for (const auto &[sym, source] : symbols) {
-    if (!evaluate::IsVariable(*sym)) {
+    if (!IsVariableListItem(*sym)) {
       context_.SayWithDecl(
           *sym, source, "'%s' must be a variable"_err_en_US, sym->name());
     }
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index e6863b53ecfdef..a8e60b411e1846 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -141,6 +141,7 @@ class OmpStructureChecker
 
 private:
   bool CheckAllowedClause(llvmOmpClause clause);
+  bool IsVariableListItem(const Symbol &sym);
   bool IsExtendedListItem(const Symbol &sym);
   void CheckMultipleOccurrence(semantics::UnorderedSymbolSet &listVars,
       const std::list<parser::Name> &nameList, const parser::CharBlock &item,
diff --git a/flang/test/Semantics/OpenMP/shared-pointer.f90 b/flang/test/Semantics/OpenMP/shared-pointer.f90
new file mode 100644
index 00000000000000..6826086d02a54b
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/shared-pointer.f90
@@ -0,0 +1,13 @@
+!RUN: %flang_fc1 -fopenmp -emit-fir -o - %s | FileCheck %s
+!RUN: bbc -fopenmp -emit-fir -o - %s | FileCheck %s
+
+!Allow POINTER variables in OpenMP SHARED clause. Check that this
+!code compiles.
+
+!CHECK-LABEL: func.func @_QPfoo
+subroutine foo()
+  procedure(), pointer :: pf
+  !$omp parallel shared(pf)
+  !$omp end parallel
+end
+

@kparzysz kparzysz changed the title [flang][OpenMP] Tread POINTER variables as valid variable list items [flang][OpenMP] Treat POINTER variables as valid variable list items Oct 9, 2024
@kparzysz kparzysz requested a review from kkwli October 9, 2024 17:49
Copy link
Collaborator

@kkwli kkwli left a comment

Choose a reason for hiding this comment

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

LG

@kparzysz kparzysz merged commit d602f93 into llvm:main Oct 9, 2024
13 checks passed
@kparzysz kparzysz deleted the users/kparzysz/flang-pointer-variable branch October 9, 2024 19:22
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.

3 participants