Skip to content

Commit

Permalink
[Flang] [Semantics] [OpenMP] Added missing semantic check with nested…
Browse files Browse the repository at this point in the history
… target region. (#115344)

Issue semantic warning for any combination of nested OMP TARGET
directives inside another OMP TARGET region.

This change would not affect OMP TARGET inside an OMP TARGET DATA.
However, it issues warning for OMP TARGET DATA inside an OMP TARGET
region.
  • Loading branch information
raghavendhra authored Nov 22, 2024
1 parent 22fdc57 commit 556ea52
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
16 changes: 13 additions & 3 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,21 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) {
},
c.u);
},
[&](const parser::OpenMPLoopConstruct &c) {
const auto &beginLoopDir{
std::get<parser::OmpBeginLoopDirective>(c.t)};
const auto &beginDir{
std::get<parser::OmpLoopDirective>(beginLoopDir.t)};
if (llvm::omp::allTargetSet.test(beginDir.v)) {
eligibleTarget = false;
ineligibleTargetDir = beginDir.v;
}
},
[&](const auto &c) {},
},
c.u);
if (!eligibleTarget) {
context_.Warn(common::UsageWarning::Portability,
context_.Warn(common::UsageWarning::OpenMPUsage,
parser::FindSourceLocation(c),
"If %s directive is nested inside TARGET region, the behaviour is unspecified"_port_en_US,
parser::ToUpperCaseLetters(
Expand Down Expand Up @@ -1068,7 +1078,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
CheckMatching<parser::OmpBlockDirective>(beginDir, endDir);

PushContextAndClauseSets(beginDir.source, beginDir.v);
if (GetContext().directive == llvm::omp::Directive::OMPD_target) {
if (llvm::omp::allTargetSet.test(GetContext().directive)) {
EnterDirectiveNest(TargetNest);
}

Expand Down Expand Up @@ -1151,7 +1161,7 @@ void OmpStructureChecker::Leave(const parser::OpenMPBlockConstruct &) {
if (GetDirectiveNest(TargetBlockOnlyTeams)) {
ExitDirectiveNest(TargetBlockOnlyTeams);
}
if (GetContext().directive == llvm::omp::Directive::OMPD_target) {
if (llvm::omp::allTargetSet.test(GetContext().directive)) {
ExitDirectiveNest(TargetNest);
}
dirContext_.pop_back();
Expand Down
26 changes: 25 additions & 1 deletion flang/test/Semantics/OpenMP/nested-target.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
! 2.12.5 Target Construct

program main
integer :: i, j, N = 10
integer :: i, j, N = 10, n1, n2, res(100)
real :: a, arrayA(512), arrayB(512), ai(10)
real, allocatable :: B(:)

Expand Down Expand Up @@ -50,4 +50,28 @@ program main
!$omp end target
deallocate(B)

n1 = 10
n2 = 10
!$omp target teams map(to:a)
!PORTABILITY: If TARGET DATA directive is nested inside TARGET region, the behaviour is unspecified
!$omp target data map(n1,n2)
do i=1, n1
do j=1, n2
res((i-1)*10+j) = i*j
end do
end do
!$omp end target data
!$omp end target teams

!$omp target teams map(to:a) map(from:n1,n2)
!PORTABILITY: If TARGET TEAMS DISTRIBUTE PARALLEL DO directive is nested inside TARGET region, the behaviour is unspecified
!$omp target teams distribute parallel do
do i=1, n1
do j=1, n2
res((i-1)*10+j) = i*j
end do
end do
!$omp end target teams distribute parallel do
!$omp end target teams

end program main

0 comments on commit 556ea52

Please sign in to comment.