Skip to content

Commit 17944a9

Browse files
committed
[Flang] [Semantics] [OpenMP] Added missing semantic check with nested
target region.
1 parent 71b87d1 commit 17944a9

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,8 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) {
824824
std::get<parser::OmpBeginBlockDirective>(c.t)};
825825
const auto &beginDir{
826826
std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
827-
if (beginDir.v == llvm::omp::Directive::OMPD_target_data) {
827+
if (beginDir.v == llvm::omp::Directive::OMPD_target_data ||
828+
llvm::omp::allTargetSet.test(beginDir.v)) {
828829
eligibleTarget = false;
829830
ineligibleTargetDir = beginDir.v;
830831
}
@@ -1074,6 +1075,20 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
10741075
if (llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
10751076
HasInvalidTeamsNesting(beginDir.v, beginDir.source);
10761077
}
1078+
if ((llvm::omp::allTargetSet.test(GetContext().directive) ||
1079+
(GetContext().directive ==
1080+
llvm::omp::Directive::OMPD_target_data)) &&
1081+
(llvm::omp::allTargetSet.test(GetContextParent().directive) ||
1082+
(GetContextParent().directive ==
1083+
llvm::omp::Directive::OMPD_target_data))) {
1084+
context_.Warn(common::UsageWarning::OpenMPUsage,
1085+
parser::FindSourceLocation(x),
1086+
"If %s directive is nested inside %s region, the behaviour is unspecified"_port_en_US,
1087+
parser::ToUpperCaseLetters(
1088+
getDirectiveName(GetContext().directive).str()),
1089+
parser::ToUpperCaseLetters(
1090+
getDirectiveName(GetContextParent().directive).str()));
1091+
}
10771092
if (GetContext().directive == llvm::omp::Directive::OMPD_master) {
10781093
CheckMasterNesting(x);
10791094
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ SUBROUTINE NESTED_BAD(N)
166166
end do
167167
!$omp end task
168168
!ERROR: The only OpenMP constructs that can be encountered during execution of a 'SIMD' region are the `ATOMIC` construct, the `LOOP` construct, the `SIMD` construct, the `SCAN` construct and the `ORDERED` construct with the `SIMD` clause.
169+
!ERROR: If TARGET directive is nested inside TARGET SIMD region, the behaviour is unspecified
169170
!$omp target
170171
do J = 1, N
171172
K = 2

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

Lines changed: 14 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,17 @@ 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 TEAMS 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+
5366
end program main

0 commit comments

Comments
 (0)