Skip to content

Commit 97c9c94

Browse files
authored
[flang][OpenMP] Added semantic checks for target update (#71270)
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. ```
1 parent bf87638 commit 97c9c94

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "definable.h"
1111
#include "flang/Parser/parse-tree.h"
1212
#include "flang/Semantics/tools.h"
13-
#include <algorithm>
1413

1514
namespace Fortran::semantics {
1615

@@ -1394,6 +1393,16 @@ void OmpStructureChecker::CheckOrderedDependClause(
13941393
}
13951394
}
13961395

1396+
void OmpStructureChecker::CheckTargetUpdate() {
1397+
const parser::OmpClause *toClause = FindClause(llvm::omp::Clause::OMPC_to);
1398+
const parser::OmpClause *fromClause =
1399+
FindClause(llvm::omp::Clause::OMPC_from);
1400+
if (!toClause && !fromClause) {
1401+
context_.Say(GetContext().directiveSource,
1402+
"At least one motion-clause (TO/FROM) must be specified on TARGET UPDATE construct."_err_en_US);
1403+
}
1404+
}
1405+
13971406
void OmpStructureChecker::Enter(
13981407
const parser::OpenMPSimpleStandaloneConstruct &x) {
13991408
const auto &dir{std::get<parser::OmpSimpleStandaloneDirective>(x.t)};
@@ -1402,12 +1411,15 @@ void OmpStructureChecker::Enter(
14021411
}
14031412

14041413
void OmpStructureChecker::Leave(
1405-
const parser::OpenMPSimpleStandaloneConstruct &) {
1414+
const parser::OpenMPSimpleStandaloneConstruct &x) {
14061415
switch (GetContext().directive) {
14071416
case llvm::omp::Directive::OMPD_ordered:
14081417
// [5.1] 2.19.9 Ordered Construct Restriction
14091418
ChecksOnOrderedAsStandalone();
14101419
break;
1420+
case llvm::omp::Directive::OMPD_target_update:
1421+
CheckTargetUpdate();
1422+
break;
14111423
default:
14121424
break;
14131425
}

flang/lib/Semantics/check-omp-structure.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class OmpStructureChecker
182182
void CheckDistLinear(const parser::OpenMPLoopConstruct &x);
183183
void CheckSIMDNest(const parser::OpenMPConstruct &x);
184184
void CheckTargetNest(const parser::OpenMPConstruct &x);
185+
void CheckTargetUpdate();
185186
void CheckCancellationNest(
186187
const parser::CharBlock &source, const parser::OmpCancelType::Type &type);
187188
std::int64_t GetOrdCollapseLevel(const parser::OpenMPLoopConstruct &x);

flang/test/Parser/OpenMP/if-clause.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ program openmp_parse_if
77
! CHECK: OmpSimpleStandaloneDirective -> llvm::omp::Directive = target update
88
! CHECK-NEXT: OmpClause -> If -> OmpIfClause
99
! CHECK-NOT: DirectiveNameModifier
10-
!$omp target update if(cond)
10+
!$omp target update if(cond) to(i)
1111

1212
! CHECK: OmpSimpleStandaloneDirective -> llvm::omp::Directive = target update
1313
! CHECK-NEXT: OmpClause -> If -> OmpIfClause
1414
! CHECK-NEXT: DirectiveNameModifier = TargetUpdate
15-
!$omp target update if(target update: cond)
15+
!$omp target update if(target update: cond) to(i)
1616

1717
! CHECK: OmpSimpleStandaloneDirective -> llvm::omp::Directive = target enter data
1818
! CHECK: OmpClause -> If -> OmpIfClause

flang/test/Semantics/OpenMP/if-clause.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,15 +451,15 @@ program main
451451
! ----------------------------------------------------------------------------
452452
! TARGET UPDATE
453453
! ----------------------------------------------------------------------------
454-
!$omp target update if(.true.)
454+
!$omp target update to(i) if(.true.)
455455

456-
!$omp target update if(target update: .true.)
456+
!$omp target update to(i) if(target update: .true.)
457457

458458
!ERROR: Unmatched directive name modifier TARGET on the IF clause
459-
!$omp target update if(target: .true.)
459+
!$omp target update to(i) if(target: .true.)
460460

461461
!ERROR: At most one IF clause can appear on the TARGET UPDATE directive
462-
!$omp target update if(.true.) if(target update: .false.)
462+
!$omp target update to(i) if(.true.) if(target update: .false.)
463463

464464
! ----------------------------------------------------------------------------
465465
! TASK
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
3+
subroutine foo(x)
4+
integer :: x
5+
!ERROR: At least one motion-clause (TO/FROM) must be specified on TARGET UPDATE construct.
6+
!$omp target update
7+
8+
!ERROR: At least one motion-clause (TO/FROM) must be specified on TARGET UPDATE construct.
9+
!$omp target update nowait
10+
11+
!$omp target update to(x) nowait
12+
13+
!ERROR: At most one NOWAIT clause can appear on the TARGET UPDATE directive
14+
!$omp target update to(x) nowait nowait
15+
16+
end subroutine

0 commit comments

Comments
 (0)