Skip to content

Commit

Permalink
[OpenMP] [Flang] [Semantics] Add a missing semantic check for OMP DIS…
Browse files Browse the repository at this point in the history
…TRIBUTE directive.

Added semantic support for following restriction which applies to OMP DISTRIBUTE directives

  - A list item may appear in a firstprivate or lastprivate clause but not both.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D157465
  • Loading branch information
raghavendhra committed Aug 9, 2023
1 parent 66c43fb commit 9c2d54e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions flang/lib/Semantics/check-omp-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ static OmpDirectiveSet teamSet{Directive::OMPD_teams,
Directive::OMPD_teams_distribute_parallel_do,
Directive::OMPD_teams_distribute_parallel_do_simd,
Directive::OMPD_teams_distribute_simd};
static OmpDirectiveSet distributeSet{Directive::OMPD_distribute,
Directive::OMPD_distribute_parallel_do,
Directive::OMPD_distribute_parallel_do_simd,
Directive::OMPD_distribute_simd, Directive::OMPD_target_teams_distribute,
Directive::OMPD_target_teams_distribute_parallel_do,
Directive::OMPD_target_teams_distribute_parallel_do_simd,
Directive::OMPD_target_teams_distribute_simd,
Directive::OMPD_teams_distribute,
Directive::OMPD_teams_distribute_parallel_do,
Directive::OMPD_teams_distribute_parallel_do_simd,
Directive::OMPD_teams_distribute_simd};
static OmpDirectiveSet taskGeneratingSet{
OmpDirectiveSet{Directive::OMPD_task} | taskloopSet};
static OmpDirectiveSet nestedOrderedErrSet{Directive::OMPD_critical,
Expand Down
11 changes: 11 additions & 0 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,17 @@ void OmpAttributeVisitor::ResolveOmpObject(
"clauses on a TARGET DATA construct"_err_en_US,
symbol->name());
}
if (llvm::omp::distributeSet.test(GetContext().directive) &&
(((ompFlag == Symbol::Flag::OmpFirstPrivate) &&
symbol->test(Symbol::Flag::OmpLastPrivate)) ||
((ompFlag == Symbol::Flag::OmpLastPrivate) &&
symbol->test(Symbol::Flag::OmpFirstPrivate)))) {
context_.Say(designator.source,
"Variable '%s' may not "
"appear on both FIRSTPRIVATE and LASTPRIVATE "
"clauses on a DISTRIBUTE construct"_err_en_US,
symbol->name());
}
}
} else {
// Array sections to be changed to substrings as needed
Expand Down
35 changes: 35 additions & 0 deletions flang/test/Semantics/OpenMP/firstprivate01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
! Variables that appear in a firstprivate clause on a distribute or
! worksharing constructs must not appear in the private or
! reduction clause in a teams or parallel constructs in the outer context
!
! A list item may appear in a firstprivate or lastprivate clause but not both on
! a distribute directive

program omp_firstprivate
integer :: i, a(10), b(10), c(10)
Expand All @@ -29,6 +32,38 @@ program omp_firstprivate
end do
!$omp end distribute
!$omp end teams

!$omp teams distribute firstprivate(a) lastprivate(b)
do i = 1, 10
a(i) = a(i) + b(i) - i
end do
!$omp end teams distribute
!ERROR: Variable 'b' may not appear on both FIRSTPRIVATE and LASTPRIVATE clauses on a DISTRIBUTE construct
!$omp teams distribute firstprivate(a,b) lastprivate(b)
do i = 1, 10
a(i) = a(i) + b(i) - i
end do
!$omp end teams distribute
!ERROR: Variable 'a' may not appear on both FIRSTPRIVATE and LASTPRIVATE clauses on a DISTRIBUTE construct
!ERROR: Variable 'b' may not appear on both FIRSTPRIVATE and LASTPRIVATE clauses on a DISTRIBUTE construct
!$omp teams distribute firstprivate(a,b) lastprivate(a,b)
do i = 1, 10
a(i) = a(i) + b(i) - i
end do
!$omp end teams distribute
!ERROR: Variable 'b' may not appear on both FIRSTPRIVATE and LASTPRIVATE clauses on a DISTRIBUTE construct
!$omp teams distribute lastprivate(a,b) firstprivate(b)
do i = 1, 10
a(i) = a(i) + b(i) - i
end do
!$omp end teams distribute
!ERROR: Variable 'b' may not appear on both FIRSTPRIVATE and LASTPRIVATE clauses on a DISTRIBUTE construct
!ERROR: Variable 'a' may not appear on both FIRSTPRIVATE and LASTPRIVATE clauses on a DISTRIBUTE construct
!$omp teams distribute lastprivate(a,b) firstprivate(b,a)
do i = 1, 10
a(i) = a(i) + b(i) - i
end do
!$omp end teams distribute
!$omp end target

print *, a, b
Expand Down

0 comments on commit 9c2d54e

Please sign in to comment.