Skip to content

Commit 076e3f2

Browse files
committed
[Flang] [Semantics] [OpenMP] Added missing semantic check with nested
target region.
1 parent 9a0e0f5 commit 076e3f2

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
@@ -785,7 +785,8 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) {
785785
std::get<parser::OmpBeginBlockDirective>(c.t)};
786786
const auto &beginDir{
787787
std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
788-
if (beginDir.v == llvm::omp::Directive::OMPD_target_data) {
788+
if (beginDir.v == llvm::omp::Directive::OMPD_target_data ||
789+
llvm::omp::allTargetSet.test(beginDir.v)) {
789790
eligibleTarget = false;
790791
ineligibleTargetDir = beginDir.v;
791792
}
@@ -984,6 +985,20 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
984985
if (llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
985986
HasInvalidTeamsNesting(beginDir.v, beginDir.source);
986987
}
988+
if ((llvm::omp::allTargetSet.test(GetContext().directive) ||
989+
(GetContext().directive ==
990+
llvm::omp::Directive::OMPD_target_data)) &&
991+
(llvm::omp::allTargetSet.test(GetContextParent().directive) ||
992+
(GetContextParent().directive ==
993+
llvm::omp::Directive::OMPD_target_data))) {
994+
context_.Warn(common::UsageWarning::OpenMPUsage,
995+
parser::FindSourceLocation(x),
996+
"If %s directive is nested inside %s region, the behaviour is unspecified"_port_en_US,
997+
parser::ToUpperCaseLetters(
998+
getDirectiveName(GetContext().directive).str()),
999+
parser::ToUpperCaseLetters(
1000+
getDirectiveName(GetContextParent().directive).str()));
1001+
}
9871002
if (GetContext().directive == llvm::omp::Directive::OMPD_master) {
9881003
CheckMasterNesting(x);
9891004
}

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 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)