Skip to content

[flang][OpenMP] Add semantic check for declare target #71425

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
Nov 7, 2023

Conversation

shraiysh
Copy link
Member

@shraiysh shraiysh commented Nov 6, 2023

This patch adds a semantic check for the following:

If a list item is a procedure name, it must not be a generic name,
procedure pointer, entry name, or statement function name.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Nov 6, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2023

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Shraiysh (shraiysh)

Changes

This patch adds a semantic check for the following:

If a list item is a procedure name, it must not be a generic name,
procedure pointer, entry name, or statement function name.

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

3 Files Affected:

  • (modified) flang/lib/Semantics/check-omp-structure.cpp (+30)
  • (modified) flang/lib/Semantics/check-omp-structure.h (+1)
  • (added) flang/test/Semantics/OpenMP/declare-target07.f90 (+38)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 2054a13bd92e790..85265c768891bdd 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1173,6 +1173,36 @@ void OmpStructureChecker::Enter(const parser::OpenMPDeclareTargetConstruct &x) {
   }
 }
 
+void OmpStructureChecker::Enter(const parser::OmpDeclareTargetWithList &x) {
+  SymbolSourceMap symbols;
+  GetSymbolsInObjectList(x.v, symbols);
+  for (auto &[symbol, source] : symbols) {
+    const GenericDetails *genericDetails = symbol->detailsIf<GenericDetails>();
+    if (genericDetails) {
+      context_.Say(source,
+          "The procedure '%s' in DECLARE TARGET construct cannot be a generic name"_err_en_US,
+          symbol->name());
+      genericDetails->specific();
+    }
+    if(IsProcedurePointer(*symbol)) {
+      context_.Say(source,
+          "The procedure '%s' in DECLARE TARGET construct cannot be a procedure pointer"_err_en_US,
+          symbol->name());
+    }
+    const SubprogramDetails *entryDetails = symbol->detailsIf<SubprogramDetails>();
+    if(entryDetails && entryDetails->entryScope()) {
+      context_.Say(source,
+          "The procedure '%s' in DECLARE TARGET construct cannot be an entry name"_err_en_US,
+          symbol->name());
+    }
+    if(IsStmtFunction(*symbol)) {
+      context_.Say(source,
+          "The procedure '%s' in DECLARE TARGET construct cannot be a statement function"_err_en_US,
+          symbol->name());
+    }
+  }
+}
+
 void OmpStructureChecker::CheckSymbolNames(
     const parser::CharBlock &source, const parser::OmpObjectList &objList) {
   for (const auto &ompObject : objList.v) {
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index 0adfa7b5d83874d..d35602cca75d549 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -79,6 +79,7 @@ class OmpStructureChecker
   void Leave(const parser::OpenMPDeclarativeAllocate &);
   void Enter(const parser::OpenMPDeclareTargetConstruct &);
   void Leave(const parser::OpenMPDeclareTargetConstruct &);
+  void Enter(const parser::OmpDeclareTargetWithList &);
   void Enter(const parser::OpenMPExecutableAllocate &);
   void Leave(const parser::OpenMPExecutableAllocate &);
   void Enter(const parser::OpenMPAllocatorsConstruct &);
diff --git a/flang/test/Semantics/OpenMP/declare-target07.f90 b/flang/test/Semantics/OpenMP/declare-target07.f90
new file mode 100644
index 000000000000000..5645a31aa1e8a92
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/declare-target07.f90
@@ -0,0 +1,38 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
+
+module my_module
+  interface foo
+    subroutine foo_int(a)
+    integer :: a
+    end subroutine
+    subroutine foo_real(a)
+    real :: a
+    end subroutine
+  end interface
+contains
+  subroutine bar(N)
+    integer :: N
+    entry entry1(N)
+  end subroutine
+  subroutine foobar(N)
+    integer::N
+    !ERROR: The procedure 'entry1' in DECLARE TARGET construct cannot be an entry name
+    !$omp declare target(bar, entry1)
+    call bar(N)
+  end subroutine
+end module
+
+subroutine baz(x)
+    real, intent(inout) :: x
+    real :: res 
+    stmtfunc(x) = 4.0 * (x**3)
+    !ERROR: The procedure 'stmtfunc' in DECLARE TARGET construct cannot be a statement function
+    !$omp declare target (stmtfunc)
+    res = stmtfunc(x)
+end subroutine
+
+program main
+  use my_module
+  !ERROR: The procedure 'foo' in DECLARE TARGET construct cannot be a generic name
+  !$omp declare target(foo)
+end

Copy link

github-actions bot commented Nov 6, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@agozillon agozillon left a comment

Choose a reason for hiding this comment

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

LGTM, aside from the slight formatting complaint by the tool!

Copy link
Contributor

@raghavendhra raghavendhra left a comment

Choose a reason for hiding this comment

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

LGTM

@shraiysh shraiysh force-pushed the declare_target_semantics branch from 9752967 to 139e242 Compare November 7, 2023 02:30
This patch adds a semantic check for the following:

```
If a list item is a procedure name, it must not be a generic name,
procedure pointer, entry name, or statement function name.
```
@shraiysh shraiysh force-pushed the declare_target_semantics branch from 139e242 to 72bf7ea Compare November 7, 2023 02:30
@shraiysh shraiysh merged commit 6846258 into llvm:main Nov 7, 2023
@shraiysh shraiysh deleted the declare_target_semantics branch November 7, 2023 02:42
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.

4 participants