[fortran/93364,9/10,Regression] ICE in gfc_set_array_spec, at fortran/array.c:879

Message ID trinity-60590e61-a989-42a7-b902-3f06df8e1443-1587329372424@3c-app-gmx-bap40
State New
Headers show
Series
  • Untitled series #24643
Related show

Commit Message

Harald Anlauf April 19, 2020, 8:49 p.m.
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  <anlauf@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  <anlauf@gmx.de>

	PR fortran/93364
	* gfortran.dg/pr93364.f90: New test.

Comments

Harald Anlauf April 19, 2020, 8:54 p.m. | #1
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" <anlauf@gmx.de>

> An: "fortran" <fortran@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  <anlauf@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  <anlauf@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 }

>
David Malcolm via Gcc-patches April 20, 2020, 9:39 a.m. | #2
Hi Harald,

> The attached patch fixes that.  OK for mainline / backport to 9-branch?


OK for both.

Thanks a lot for the patch!

Regards

	Thomas

Patch

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 }