From 2c6e2eb1b10bb921b739c8733721cc8a0274dccd Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 6 Jul 2017 19:49:33 +0000 Subject: [PATCH] re PR fortran/70071 (ICE on wrong usage of a subscript triplet) 2017-07-06 Harald Anlauf PR fortran/70071 * array.c (gfc_ref_dimen_size): Handle bad subscript triplets. 2017-07-06 Harald Anlauf PR fortran/70071 * gfortran.dg/coarray_44.f90: New testcase. From-SVN: r250039 --- gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/array.c | 8 +++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/coarray_44.f90 | 12 ++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/coarray_44.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 692b8ff57f4..dc89407d4c5 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2017-07-06 Harald Anlauf + + PR fortran/70071 + * array.c (gfc_ref_dimen_size): Handle bad subscript triplets. + 2017-07-03 Dominique d'Humieres PR fortran/79866 diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index 30656c197d0..46642bb5d97 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -2203,9 +2203,15 @@ gfc_ref_dimen_size (gfc_array_ref *ar, int dimen, mpz_t *result, mpz_t *end) bool t; gfc_expr *stride_expr = NULL; - if (dimen < 0 || ar == NULL || dimen > ar->dimen - 1) + if (dimen < 0 || ar == NULL) gfc_internal_error ("gfc_ref_dimen_size(): Bad dimension"); + if (dimen > ar->dimen - 1) + { + gfc_error ("Bad array dimension at %L", &ar->c_where[dimen]); + return false; + } + switch (ar->dimen_type[dimen]) { case DIMEN_ELEMENT: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ac18d1ab293..f0f068b663f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-07-06 Harald Anlauf + + PR fortran/70071 + * gfortran.dg/coarray_44.f90: New testcase. + 2017-07-06 Maxim Ostapenko * c-c++-common/asan/kasan-alloca-1.c: New test. diff --git a/gcc/testsuite/gfortran.dg/coarray_44.f90 b/gcc/testsuite/gfortran.dg/coarray_44.f90 new file mode 100644 index 00000000000..15fb8c76ce4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray_44.f90 @@ -0,0 +1,12 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +! +! PR fortran/70071 +! Based on testcases by Gerhard Steinmetz + +program pr70071 + implicit none + integer, allocatable :: z(:)[:,:] + allocate (z(2)[1::2,*]) ! { dg-error "Bad array dimension" } + allocate (z(1::2)[2,*]) ! { dg-error "Bad array specification in ALLOCATE" } +end program pr70071 -- 2.30.2