diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index 12f54fbd51e1c..a328424e0c098 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 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(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 78892d7bd282e..0adfa7b5d8387 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 ca62f6969eee1..6d69e16e7cc73 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 dc9aa5ef7f1d1..493c6c873bfbf 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 0000000000000..a0728e52ba3d2 --- /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