[flang-commits] [flang] [flang][OpenMP] Added semantic checks for target update (PR #71270)
via flang-commits
flang-commits at lists.llvm.org
Fri Nov 3 20:58:04 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-openmp
Author: Shraiysh (shraiysh)
<details>
<summary>Changes</summary>
This patch adds the following semantic check for target update
```
At least one motion-clause must be specified.
```
A motion clause is either a `to` or a `from` clause.
This patch also adds a test for the following semantic check which was already supported.
```
At most one nowait clause can appear on the directive.
```
---
Full diff: https://github.com/llvm/llvm-project/pull/71270.diff
5 Files Affected:
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+14-2)
- (modified) flang/lib/Semantics/check-omp-structure.h (+1)
- (modified) flang/test/Parser/OpenMP/if-clause.f90 (+2-2)
- (modified) flang/test/Semantics/OpenMP/if-clause.f90 (+4-4)
- (added) flang/test/Semantics/OpenMP/target-update01.f90 (+16)
``````````diff
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 12f54fbd51e1c2f..a328424e0c098d0 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -10,7 +10,6 @@
#include "definable.h"
#include "flang/Parser/parse-tree.h"
#include "flang/Semantics/tools.h"
-#include <algorithm>
namespace Fortran::semantics {
@@ -1394,6 +1393,16 @@ void OmpStructureChecker::CheckOrderedDependClause(
}
}
+void OmpStructureChecker::CheckTargetUpdate() {
+ const parser::OmpClause *toClause = FindClause(llvm::omp::Clause::OMPC_to);
+ const parser::OmpClause *fromClause =
+ FindClause(llvm::omp::Clause::OMPC_from);
+ if (!toClause && !fromClause) {
+ context_.Say(GetContext().directiveSource,
+ "At least one motion-clause (TO/FROM) must be specified on TARGET UPDATE construct."_err_en_US);
+ }
+}
+
void OmpStructureChecker::Enter(
const parser::OpenMPSimpleStandaloneConstruct &x) {
const auto &dir{std::get<parser::OmpSimpleStandaloneDirective>(x.t)};
@@ -1402,12 +1411,15 @@ void OmpStructureChecker::Enter(
}
void OmpStructureChecker::Leave(
- const parser::OpenMPSimpleStandaloneConstruct &) {
+ const parser::OpenMPSimpleStandaloneConstruct &x) {
switch (GetContext().directive) {
case llvm::omp::Directive::OMPD_ordered:
// [5.1] 2.19.9 Ordered Construct Restriction
ChecksOnOrderedAsStandalone();
break;
+ case llvm::omp::Directive::OMPD_target_update:
+ CheckTargetUpdate();
+ break;
default:
break;
}
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index 78892d7bd282e65..0adfa7b5d83874d 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -182,6 +182,7 @@ class OmpStructureChecker
void CheckDistLinear(const parser::OpenMPLoopConstruct &x);
void CheckSIMDNest(const parser::OpenMPConstruct &x);
void CheckTargetNest(const parser::OpenMPConstruct &x);
+ void CheckTargetUpdate();
void CheckCancellationNest(
const parser::CharBlock &source, const parser::OmpCancelType::Type &type);
std::int64_t GetOrdCollapseLevel(const parser::OpenMPLoopConstruct &x);
diff --git a/flang/test/Parser/OpenMP/if-clause.f90 b/flang/test/Parser/OpenMP/if-clause.f90
index ca62f6969eee1c0..6d69e16e7cc731f 100644
--- a/flang/test/Parser/OpenMP/if-clause.f90
+++ b/flang/test/Parser/OpenMP/if-clause.f90
@@ -7,12 +7,12 @@ program openmp_parse_if
! CHECK: OmpSimpleStandaloneDirective -> llvm::omp::Directive = target update
! CHECK-NEXT: OmpClause -> If -> OmpIfClause
! CHECK-NOT: DirectiveNameModifier
- !$omp target update if(cond)
+ !$omp target update if(cond) to(i)
! CHECK: OmpSimpleStandaloneDirective -> llvm::omp::Directive = target update
! CHECK-NEXT: OmpClause -> If -> OmpIfClause
! CHECK-NEXT: DirectiveNameModifier = TargetUpdate
- !$omp target update if(target update: cond)
+ !$omp target update if(target update: cond) to(i)
! CHECK: OmpSimpleStandaloneDirective -> llvm::omp::Directive = target enter data
! CHECK: OmpClause -> If -> OmpIfClause
diff --git a/flang/test/Semantics/OpenMP/if-clause.f90 b/flang/test/Semantics/OpenMP/if-clause.f90
index dc9aa5ef7f1d15f..493c6c873bfbf29 100644
--- a/flang/test/Semantics/OpenMP/if-clause.f90
+++ b/flang/test/Semantics/OpenMP/if-clause.f90
@@ -451,15 +451,15 @@ program main
! ----------------------------------------------------------------------------
! TARGET UPDATE
! ----------------------------------------------------------------------------
- !$omp target update if(.true.)
+ !$omp target update to(i) if(.true.)
- !$omp target update if(target update: .true.)
+ !$omp target update to(i) if(target update: .true.)
!ERROR: Unmatched directive name modifier TARGET on the IF clause
- !$omp target update if(target: .true.)
+ !$omp target update to(i) if(target: .true.)
!ERROR: At most one IF clause can appear on the TARGET UPDATE directive
- !$omp target update if(.true.) if(target update: .false.)
+ !$omp target update to(i) if(.true.) if(target update: .false.)
! ----------------------------------------------------------------------------
! TASK
diff --git a/flang/test/Semantics/OpenMP/target-update01.f90 b/flang/test/Semantics/OpenMP/target-update01.f90
new file mode 100644
index 000000000000000..a0728e52ba3d230
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/target-update01.f90
@@ -0,0 +1,16 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
+
+subroutine foo(x)
+ integer :: x
+ !ERROR: At least one motion-clause (TO/FROM) must be specified on TARGET UPDATE construct.
+ !$omp target update
+
+ !ERROR: At least one motion-clause (TO/FROM) must be specified on TARGET UPDATE construct.
+ !$omp target update nowait
+
+ !$omp target update to(x) nowait
+
+ !ERROR: At most one NOWAIT clause can appear on the TARGET UPDATE directive
+ !$omp target update to(x) nowait nowait
+
+end subroutine
``````````
</details>
https://github.com/llvm/llvm-project/pull/71270
More information about the flang-commits
mailing list