[flang-commits] [flang] [Flang] - Enhance testing for strictly-nested teams in target regions. (PR #168437)

Pranav Bhandarkar via flang-commits flang-commits at lists.llvm.org
Thu Nov 20 10:10:57 PST 2025


================
@@ -262,6 +262,15 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) {
     EnterDirectiveNest(SIMDNest);
   }
 
+  if (CurrentDirectiveIsNested() &&
+      llvm::omp::topTeamsSet.test(GetContext().directive) &&
+      GetContextParent().directive == llvm::omp::Directive::OMPD_target &&
+      !GetDirectiveNest(TargetBlockOnlyTeams)) {
----------------
bhandarkar-pranav wrote:

I coudn't nest a `target` directive inside the `teams` directive because that is not allowed, but I did the following
```
 !$omp target map(tofrom:counter)
   !$omp teams
    !$omp parallel
      !$omp target
        ... some stmt...
       !$omp teams
        .... a strictly structured block like a do loop ...
       !$omp end teams    <<< compiler insisted on an end teams here although the do loop is a strictly structured block
      !$omp end target
    !$omp end parallel
   !$omp end teams
  !$omp end target
```

This compiled fine but it shouldn't have for the reason you mentioned. Strangely enough, `gfortran` also accepts the code above, only warning about reverse-offloading. I am torn between spending time fixing it on the one hand while on the other hand letting what seems to be an obscure case slide.


https://github.com/llvm/llvm-project/pull/168437


More information about the flang-commits mailing list