]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR fortran/93364 - ICE in gfc_set_array_spec, at fortran/array.c:879
authorHarald Anlauf <anlauf@gmx.de>
Mon, 20 Apr 2020 12:45:10 +0000 (14:45 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Mon, 20 Apr 2020 12:48:16 +0000 (14:48 +0200)
Backport from mainline.

2020-04-20  Harald Anlauf  <anlauf@gmx.de>

Add missing check in gfc_set_array_spec for sum of rank and corank to not
exceed GFC_MAX_DIMENSIONS.

PR fortran/93364
* array.c (gfc_set_array_spec): Check for sum of rank and corank
not exceeding GFC_MAX_DIMENSIONS.

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

gcc/fortran/ChangeLog
gcc/fortran/array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr93364.f90 [new file with mode: 0644]

index 1c88bb0efcb019cbf150a1387db6b2068259b7c9..03193c2f9d7c4176bd1547aef2b12beb359a5bd3 100644 (file)
@@ -1,3 +1,10 @@
+2020-04-20  Harald Anlauf  <anlauf@gmx.de>
+
+       Backport from mainline.
+       PR fortran/93364
+       * array.c (gfc_set_array_spec): Check for sum of rank and corank
+       not exceeding GFC_MAX_DIMENSIONS.
+
 2020-04-14  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        Backport from trunk.
index 4a7f44f3e8bc8d514b6dd9c4725b5c269c03de33..017334839ede692d4ac1f00d3bf5ec5b595d11ad 100644 (file)
@@ -835,6 +835,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;
index d0117119d4b86e0f3f8804f4bb94b61ed736067c..fb039ee0e97a596b70daf36f7d81c9207d01787f 100644 (file)
@@ -1,3 +1,9 @@
+2020-04-20  Harald Anlauf  <anlauf@gmx.de>
+
+       Backport from mainline.
+       PR fortran/93364
+       * gfortran.dg/pr93364.f90: New test.
+
 2020-04-20  Andrea Corallo  <andrea.corallo@arm.com>
 
        Backport from mainline.
diff --git a/gcc/testsuite/gfortran.dg/pr93364.f90 b/gcc/testsuite/gfortran.dg/pr93364.f90
new file mode 100644 (file)
index 0000000..61d7fa1
--- /dev/null
@@ -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 }