Skip to content

Commit fb029d2

Browse files
[Flang] - Enhance testing for strictly-nested teams in target regions.
This patch enhances the semantics test for checking that teams directives are strictly nested inside target directives.
1 parent 7d5c11f commit fb029d2

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

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

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

265+
if (CurrentDirectiveIsNested() &&
266+
llvm::omp::allTeamsSet.test(GetContext().directive) &&
267+
GetContextParent().directive == llvm::omp::Directive::OMPD_target &&
268+
!GetDirectiveNest(TargetBlockOnlyTeams)) {
269+
context_.Say(GetContextParent().directiveSource,
270+
"TARGET construct with nested TEAMS region contains statements or "
271+
"directives outside of the TEAMS construct"_err_en_US);
272+
}
273+
265274
// Combined target loop constructs are target device constructs. Keep track of
266275
// whether any such construct has been visited to later check that REQUIRES
267276
// 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
@@ -5215,6 +5215,13 @@ bool OmpStructureChecker::CheckTargetBlockOnlyTeams(
52155215
if (dirId == llvm::omp::Directive::OMPD_teams) {
52165216
nestedTeams = true;
52175217
}
5218+
} else if (const auto *ompLoopConstruct{
5219+
std::get_if<parser::OpenMPLoopConstruct>(
5220+
&ompConstruct->u)}) {
5221+
llvm::omp::Directive dirId{ompLoopConstruct->BeginDir().DirId()};
5222+
if (llvm::omp::allTeamsSet.test(dirId)) {
5223+
nestedTeams = true;
5224+
}
52185225
}
52195226
}
52205227

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
21+
print '("Result: "I0)', counter
22+
end program

0 commit comments

Comments
 (0)