openmp: Diagnose invalid teams nested in target construct [PR99226]
authorJakub Jelinek <jakub@redhat.com>
Wed, 24 Feb 2021 19:11:11 +0000 (20:11 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 24 Feb 2021 19:11:11 +0000 (20:11 +0100)
commit9d2a69106beb346be1c511a9c1a61a256b697868
tree9a4a8cfa512a426e8d92eecada77af812c842663
parent35da095d7e0614235cb0e241685c5e1a240dc882
openmp: Diagnose invalid teams nested in target construct [PR99226]

The OpenMP standard says:
"A teams region can only be strictly nested within the implicit parallel region
or a target region. If a teams construct is nested within a target construct,
that target construct must contain no statements, declarations or directives
outside of the teams construct."
We weren't diagnosing that restriction, because we need to allow e.g.
 #pragma omp target
 {{{{{{
   #pragma omp teams
   ;
 }}}}}}
and as target doesn't need to have teams nested in it, using some special
parser of the target body didn't feel right.  And after the parsing,
the question is if e.g. already parsing of the clauses doesn't add some
statements before the teams statement (gimplification certainly will).

As we now have a bugreport where we ICE on the invalid code, this just
diagnoses a subset of the invalid programs, in particular those where
nest to the teams strictly nested in targets the target region contains
some other OpenMP construct.

2021-02-24  Jakub Jelinek  <jakub@redhat.com>

PR fortran/99226
* omp-low.c (struct omp_context): Add teams_nested_p and
nonteams_nested_p members.
(scan_omp_target): Diagnose teams nested inside of target with other
directives strictly nested inside of the same target.
(check_omp_nesting_restrictions): Set ctx->teams_nested_p or
ctx->nonteams_nested_p as needed.

* c-c++-common/gomp/pr99226.c: New test.
* gfortran.dg/gomp/pr99226.f90: New test.
gcc/omp-low.c
gcc/testsuite/c-c++-common/gomp/pr99226.c [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/pr99226.f90 [new file with mode: 0644]