[Bug fortran/99226] [11 Regression] ICE in expand_expr_real_1, at expr.c:10279

2021-02-25 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99226

Jakub Jelinek  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED
   Keywords||ice-on-invalid-code

--- Comment #7 from Jakub Jelinek  ---
Fixed.

[Bug fortran/99226] [11 Regression] ICE in expand_expr_real_1, at expr.c:10279

2021-02-24 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99226

--- Comment #6 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:9d2a69106beb346be1c511a9c1a61a256b697868

commit r11-7375-g9d2a69106beb346be1c511a9c1a61a256b697868
Author: Jakub Jelinek 
Date:   Wed Feb 24 20:11:11 2021 +0100

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  

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.

[Bug fortran/99226] [11 Regression] ICE in expand_expr_real_1, at expr.c:10279

2021-02-24 Thread burnus at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99226

--- Comment #5 from Tobias Burnus  ---
(In reply to Jakub Jelinek from comment #3)
> So, either we diagnose ...  in check_omp_nesting_restrictions.

See comment 4.

 * * *

Only for completeness,
the ICE is itself is due to: '.omp_data_i' showing up in 'sub' and not only in
'sub_._omp_fn.0'. This only occurs with -O1 (and higher) and
-fdump-tree-omplower shows:
  void sub (integer(kind=4) & restrict n)
  {
integer(kind=4) i;
{
  D.3961 = .omp_data_i->D.3941;  // <<< WRONG!!!
Codewise, the '!optimize' occurs via gimplify.c's lookup_tmp_var
if is_formal=true – as called by 'get_formal_tmp_var'.

[Bug fortran/99226] [11 Regression] ICE in expand_expr_real_1, at expr.c:10279

2021-02-24 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99226

Jakub Jelinek  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org
 Ever confirmed|0   |1
 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2021-02-24

--- Comment #4 from Jakub Jelinek  ---
Created attachment 50247
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50247=edit
gcc11-pr99226.patch

Like this.

[Bug fortran/99226] [11 Regression] ICE in expand_expr_real_1, at expr.c:10279

2021-02-24 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99226

--- Comment #3 from Jakub Jelinek  ---
(In reply to Tobias Burnus from comment #2)
> (In reply to Jakub Jelinek from comment #1)
> > This is invalid and should have been rejected, when teams is nested in
> > target, it must be the only thing nested in it, you can't have two teams
> > directives nested in one target construct.
> 
> How is this enforceable at compile time for '!$omp target; call f(); call
> g()" and then in f() and g() the teams?

That will just fail or misbehave at runtime.
The spec says that
"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."
The compiler considers teams not strictly nested inside of target as "host
teams" which is lowered and expanded differently, and teams strictly nested
inside of target as "target teams".  And the construct nesting diagnostics
then will warn if the "host teams" is nested in some other construct that it is
not allowed to be nested in, but sure, this works only for lexical nesting.

I think clang diagnoses the #c2 testcase, we don't, I think the reason was
that it wasn't as clear what exactly is and is not allowed.  E.g.
#pragma omp target
{{
#pragma omp teams
;
}}
should be allowed and some statements outside of the teams but in target might
appear artificially during the parsing of e.g. teams clauses or during their
gimplification etc.

So, either we diagnose it early in the FEs somehow, or we add some less strict
late diagnostics, e.g. allow code outside of the teams in target but require
that that code doesn't contain any OpenMP directives (or just constructs?).
I guess the latter would be far easier and could be done in
check_omp_nesting_restrictions.

[Bug fortran/99226] [11 Regression] ICE in expand_expr_real_1, at expr.c:10279

2021-02-24 Thread burnus at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99226

--- Comment #2 from Tobias Burnus  ---
(In reply to Jakub Jelinek from comment #1)
> This is invalid and should have been rejected, when teams is nested in
> target, it must be the only thing nested in it, you can't have two teams
> directives nested in one target construct.

How is this enforceable at compile time for '!$omp target; call f(); call g()"
and then in f() and g() the teams?


The following C program compiles – without ICE and without error:

void
sub (int n)
{
  int i;
#pragma omp target
  {
#pragma omp teams distribute dist_schedule (static,n+4)
for (i = 0; i < 8; ++i)
  ;
#pragma omp teams distribute dist_schedule (static,n+4)
for (i = 0; i < 8; ++i)
  ;
  }
}


And the resulting omplower dump is:
  #pragma omp teams shared(n)
  __builtin_GOMP_teams (0, 0);
  {
D.2077 = n + 4;
{
  int i;

  #pragma omp distribute dist_schedule(static,D.2077) private(i)
  for (i = 0; i < 8; i = i + 1)
  #pragma omp continue (i, i)
  #pragma omp return(nowait)
}
  }
  #pragma omp return(nowait)

while for Fortran the dump is
#pragma omp teams shared(n)
__builtin_GOMP_teams (0, 0);
{
  {
integer(kind=4) D.3932;

D.3936 = *n;
D.3932 = D.3936 + 4;
{
  integer(kind=4) i;

  #pragma omp distribute dist_schedule(static,D.3932)
private(i)
  for (i = 1; i <= 8; i = i + 1)
  :
  #pragma omp continue (i, i)
  #pragma omp return(nowait)
}
  }
}
#pragma omp return(nowait)

[Bug fortran/99226] [11 Regression] ICE in expand_expr_real_1, at expr.c:10279

2021-02-24 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99226

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P4
   Target Milestone|--- |11.0
   Keywords||accepts-invalid, openmp

[Bug fortran/99226] [11 Regression] ICE in expand_expr_real_1, at expr.c:10279

2021-02-23 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99226

Jakub Jelinek  changed:

   What|Removed |Added

 CC||burnus at gcc dot gnu.org,
   ||jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek  ---
This is invalid and should have been rejected, when teams is nested in target,
it must be the only thing nested in it, you can't have two teams directives
nested in one target construct.