From aeb430aadc3c91af50095be924365981d85f8b8a Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 20 Apr 2020 14:20:19 +0200 Subject: [PATCH] PR fortran/93364 - ICE in gfc_set_array_spec, at fortran/array.c:879 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 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 PR fortran/93364 * gfortran.dg/pr93364.f90: New test. --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/array.c | 4 ++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr93364.f90 | 13 +++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr93364.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 2671c1aa381..b783bfc7949 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2020-04-20 Harald Anlauf + + 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 Thomas Koenig 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/ChangeLog b/gcc/testsuite/ChangeLog index f8dba65ff9f..473295dbef3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-20 Harald Anlauf + + PR fortran/93364 + * gfortran.dg/pr93364.f90: New test. + 2020-04-20 Steve Kargl Thomas Koenig 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 } -- 2.30.2