Hi again,

I was so focussed on whether I got this correct for the gcc git repository that
I forgot to mention that this has been cleanly regtested on x86_64-pc-linux-gnu.

Sorry for the added noise.

Harald


> Gesendet: Sonntag, 19. April 2020 um 22:49 Uhr
> Von: "Harald Anlauf" <anl...@gmx.de>
> An: "fortran" <fort...@gcc.gnu.org>, "gcc-patches" <gcc-patches@gcc.gnu.org>
> Betreff: [Patch fortran/93364] [9/10 Regression] ICE in gfc_set_array_spec, 
> at fortran/array.c:879
>
> Hi,
>
> a missing check in gfc_set_array_spec for for sum of rank and corank
> not exceeding GFC_MAX_DIMENSIONS could trigger an assert on invalid code.
>
> The attached patch fixes that.  OK for mainline / backport to 9-branch?
>
> Harald
>
>
> 2020-04-19  Harald Anlauf  <anl...@gmx.de>
>
>       PR fortran/93364
>       * array.c (gfc_set_array_spec): Check for sum of rank and corank
>       not exceeding GFC_MAX_DIMENSIONS.
>
>
> 2020-04-19  Harald Anlauf  <anl...@gmx.de>
>
>       PR fortran/93364
>       * gfortran.dg/pr93364.f90: New test.
>
>
> diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
> index 57972bc9176..471523fb767 100644
> --- a/gcc/fortran/array.c
> +++ b/gcc/fortran/array.c
> @@ -864,6 +864,10 @@ gfc_set_array_spec (gfc_symbol *sym, gfc_array_spec *as, 
> locus *error_loc)
>        return false;
>      }
>
> +  /* Check F2018:C822.  */
> +  if (sym->as->rank + sym->as->corank > GFC_MAX_DIMENSIONS)
> +    goto too_many;
> +
>    if (as->corank)
>      {
>        sym->as->cotype = as->cotype;
> diff --git a/gcc/testsuite/gfortran.dg/pr93364.f90 
> b/gcc/testsuite/gfortran.dg/pr93364.f90
> new file mode 100644
> index 00000000000..61d7fa149a6
> --- /dev/null
> +++ b/gcc/testsuite/gfortran.dg/pr93364.f90
> @@ -0,0 +1,13 @@
> +! { dg-do compile }
> +! { dg-options "-fcoarray=single" }
> +!
> +! PR fortran/93364 - check fix for ICE in gfc_set_array_spec
> +
> +type(t) function f()
> +  codimension :: t[1,2,1,2,1,2,1,*]
> +  dimension :: t(1,2,1,2,1,2,1,2)
> +end
> +
> +! { dg-error "has not been declared" " " { target *-*-* } 6 }
> +! { dg-error "is of type 't'" " " { target *-*-* } 6 }
> +! { dg-error "rank \\+ corank of" " " { target *-*-* } 8 }
>

Reply via email to