Skip to content
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

[flang][OpenMP] Added semantic checks for target update #71270

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "definable.h"
#include "flang/Parser/parse-tree.h"
#include "flang/Semantics/tools.h"
#include <algorithm>

namespace Fortran::semantics {

Expand Down Expand Up @@ -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)};
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Semantics/check-omp-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions flang/test/Parser/OpenMP/if-clause.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions flang/test/Semantics/OpenMP/if-clause.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions flang/test/Semantics/OpenMP/target-update01.f90
Original file line number Diff line number Diff line change
@@ -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