Skip to content

Commit 556ea52

Browse files
authored
[Flang] [Semantics] [OpenMP] Added missing semantic check with nested 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.
1 parent 22fdc57 commit 556ea52

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,21 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) {
848848
},
849849
c.u);
850850
},
851+
[&](const parser::OpenMPLoopConstruct &c) {
852+
const auto &beginLoopDir{
853+
std::get<parser::OmpBeginLoopDirective>(c.t)};
854+
const auto &beginDir{
855+
std::get<parser::OmpLoopDirective>(beginLoopDir.t)};
856+
if (llvm::omp::allTargetSet.test(beginDir.v)) {
857+
eligibleTarget = false;
858+
ineligibleTargetDir = beginDir.v;
859+
}
860+
},
851861
[&](const auto &c) {},
852862
},
853863
c.u);
854864
if (!eligibleTarget) {
855-
context_.Warn(common::UsageWarning::Portability,
865+
context_.Warn(common::UsageWarning::OpenMPUsage,
856866
parser::FindSourceLocation(c),
857867
"If %s directive is nested inside TARGET region, the behaviour is unspecified"_port_en_US,
858868
parser::ToUpperCaseLetters(
@@ -1068,7 +1078,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
10681078
CheckMatching<parser::OmpBlockDirective>(beginDir, endDir);
10691079

10701080
PushContextAndClauseSets(beginDir.source, beginDir.v);
1071-
if (GetContext().directive == llvm::omp::Directive::OMPD_target) {
1081+
if (llvm::omp::allTargetSet.test(GetContext().directive)) {
10721082
EnterDirectiveNest(TargetNest);
10731083
}
10741084

@@ -1151,7 +1161,7 @@ void OmpStructureChecker::Leave(const parser::OpenMPBlockConstruct &) {
11511161
if (GetDirectiveNest(TargetBlockOnlyTeams)) {
11521162
ExitDirectiveNest(TargetBlockOnlyTeams);
11531163
}
1154-
if (GetContext().directive == llvm::omp::Directive::OMPD_target) {
1164+
if (llvm::omp::allTargetSet.test(GetContext().directive)) {
11551165
ExitDirectiveNest(TargetNest);
11561166
}
11571167
dirContext_.pop_back();

flang/test/Semantics/OpenMP/nested-target.f90

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
! 2.12.5 Target Construct
66

77
program main
8-
integer :: i, j, N = 10
8+
integer :: i, j, N = 10, n1, n2, res(100)
99
real :: a, arrayA(512), arrayB(512), ai(10)
1010
real, allocatable :: B(:)
1111

@@ -50,4 +50,28 @@ program main
5050
!$omp end target
5151
deallocate(B)
5252

53+
n1 = 10
54+
n2 = 10
55+
!$omp target teams map(to:a)
56+
!PORTABILITY: If TARGET DATA directive is nested inside TARGET region, the behaviour is unspecified
57+
!$omp target data map(n1,n2)
58+
do i=1, n1
59+
do j=1, n2
60+
res((i-1)*10+j) = i*j
61+
end do
62+
end do
63+
!$omp end target data
64+
!$omp end target teams
65+
66+
!$omp target teams map(to:a) map(from:n1,n2)
67+
!PORTABILITY: If TARGET TEAMS DISTRIBUTE PARALLEL DO directive is nested inside TARGET region, the behaviour is unspecified
68+
!$omp target teams distribute parallel do
69+
do i=1, n1
70+
do j=1, n2
71+
res((i-1)*10+j) = i*j
72+
end do
73+
end do
74+
!$omp end target teams distribute parallel do
75+
!$omp end target teams
76+
5377
end program main

0 commit comments

Comments
 (0)