From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 891163858407; Fri, 17 Dec 2021 21:48:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 891163858407 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10346] Fortran: dimensions of an array have to be non-negative X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: dc33024011d9dcfb2e6820d989837a0289bbd650 X-Git-Newrev: a28d6903677629c23bac53ff061eb80f22d51006 Message-Id: <20211217214842.891163858407@sourceware.org> Date: Fri, 17 Dec 2021 21:48:42 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Dec 2021 21:48:42 -0000 https://gcc.gnu.org/g:a28d6903677629c23bac53ff061eb80f22d51006 commit r10-10346-ga28d6903677629c23bac53ff061eb80f22d51006 Author: Harald Anlauf Date: Tue Dec 7 23:06:41 2021 +0100 Fortran: dimensions of an array have to be non-negative gcc/fortran/ChangeLog: PR fortran/103610 * array.c (spec_dimen_size): Fix simplification of SHAPE: dimensions must be non-negative. gcc/testsuite/ChangeLog: PR fortran/103610 * gfortran.dg/shape_11.f90: New test. (cherry picked from commit 5f7cdea34e118776d0ccd2ff3dda0f5acab18a94) Diff: --- gcc/fortran/array.c | 6 ++++-- gcc/testsuite/gfortran.dg/shape_11.f90 | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index b304efdad50..8e4782ac1ae 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -2292,8 +2292,7 @@ gfc_copy_iterator (gfc_iterator *src) /********* Subroutines for determining the size of an array *********/ /* These are needed just to accommodate RESHAPE(). There are no - diagnostics here, we just return a negative number if something - goes wrong. */ + diagnostics here, we just return false if something goes wrong. */ /* Get the size of single dimension of an array specification. The @@ -2326,6 +2325,9 @@ spec_dimen_size (gfc_array_spec *as, int dimen, mpz_t *result) mpz_add_ui (*result, *result, 1); + if (mpz_cmp_si (*result, 0) < 0) + mpz_set_si (*result, 0); + return true; } diff --git a/gcc/testsuite/gfortran.dg/shape_11.f90 b/gcc/testsuite/gfortran.dg/shape_11.f90 new file mode 100644 index 00000000000..127d221e710 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/shape_11.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original" } +! PR fortran/103610 - ICE while simplifying SHAPE +! Contributed by G.Steinmetz + +program p + integer, parameter :: a(-1) = 1 + integer, parameter :: b(1) = maskl(shape(a)) + integer, parameter :: c(1) = shape(a) + integer, parameter :: d(1) = maskr(shape(a)) + if (b(1) /= 0) stop 1 + if (c(1) /= 0) stop 2 + if (d(1) /= 0) stop 3 +end + +! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "original" } }