PR fortran/93364 - ICE in gfc_set_array_spec, at fortran/array.c:879
authorHarald Anlauf <anlauf@gmx.de>
Mon, 20 Apr 2020 12:20:19 +0000 (14:20 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Mon, 20 Apr 2020 12:20:19 +0000 (14:20 +0200)
Add missing check in gfc_set_array_spec for sum of rank and corank to not
exceed GFC_MAX_DIMENSIONS.

2020-04-20  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-20  Harald Anlauf  <anlauf@gmx.de>

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 2671c1aa38115ec9941943b22e3bb9e7ef42b37d..b783bfc7949f7264864f72a7ef2195efc71f5a98 100644 (file)
@@ -1,3 +1,9 @@
+2020-04-20  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-20  Steve Kargl  <kargl@gcc.gnu.org>
        Thomas Koenig  <tkoenig@gcc.gnu.org>
 
index 57972bc91760318014d5911738baa1163d3023b3..471523fb7675fa1404088c1f68990aeca56bbf55 100644 (file)
@@ -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;
index f8dba65ff9fed384c389e55adb8e2a1bbe79e310..473295dbef397e43d0796ca20e02f736e96ecd95 100644 (file)
@@ -1,3 +1,8 @@
+2020-04-20  Harald Anlauf  <anlauf@gmx.de>
+
+       PR fortran/93364
+       * gfortran.dg/pr93364.f90: New test.
+
 2020-04-20  Steve Kargl  <kargl@gcc.gnu.org>
        Thomas Koenig  <tkoenig@gcc.gnu.org>
 
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 }