Skip to content

Commit 28fde68

Browse files
[Flang] - Enhance testing for strictly-nested teams in target regions. (#168437)
This patch enhances the semantics test for checking that teams directives are strictly nested inside target directives. Fixes #153173
1 parent 9c2d5e2 commit 28fde68

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) {
335335
EnterDirectiveNest(SIMDNest);
336336
}
337337

338+
if (CurrentDirectiveIsNested() &&
339+
llvm::omp::topTeamsSet.test(GetContext().directive) &&
340+
GetContextParent().directive == llvm::omp::Directive::OMPD_target &&
341+
!GetDirectiveNest(TargetBlockOnlyTeams)) {
342+
context_.Say(GetContextParent().directiveSource,
343+
"TARGET construct with nested TEAMS region contains statements or "
344+
"directives outside of the TEAMS construct"_err_en_US);
345+
}
346+
338347
// Combined target loop constructs are target device constructs. Keep track of
339348
// whether any such construct has been visited to later check that REQUIRES
340349
// directives for target-related options don't appear after them.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5217,6 +5217,13 @@ bool OmpStructureChecker::CheckTargetBlockOnlyTeams(
52175217
if (dirId == llvm::omp::Directive::OMPD_teams) {
52185218
nestedTeams = true;
52195219
}
5220+
} else if (const auto *ompLoopConstruct{
5221+
std::get_if<parser::OpenMPLoopConstruct>(
5222+
&ompConstruct->u)}) {
5223+
llvm::omp::Directive dirId{ompLoopConstruct->BeginDir().DirId()};
5224+
if (llvm::omp::topTeamsSet.test(dirId)) {
5225+
nestedTeams = true;
5226+
}
52205227
}
52215228
}
52225229

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
3+
program main
4+
implicit none
5+
integer, parameter :: n = 100
6+
integer, parameter :: expected = n+2
7+
integer :: i
8+
integer :: counter
9+
10+
counter = 0
11+
!ERROR: TARGET construct with nested TEAMS region contains statements or directives outside of the TEAMS construct
12+
!$omp target map(tofrom:counter)
13+
counter = counter+1
14+
!$omp teams distribute reduction(+:counter)
15+
do i=1, n
16+
counter = counter+1
17+
end do
18+
counter = counter+1
19+
!$omp end target
20+
end program

0 commit comments

Comments
 (0)