From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 993FF3858C2C; Thu, 30 Sep 2021 19:08:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 993FF3858C2C 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 r9-9749] Fortran - ensure simplification of bounds of array-valued named constants X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: 46c7fc8a7f052ada8b788f29081ff6fcd50a9a54 X-Git-Newrev: 3a70195d7da49fe793ce3eb0e839b9ceea96c97a Message-Id: <20210930190832.993FF3858C2C@sourceware.org> Date: Thu, 30 Sep 2021 19:08:32 +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: Thu, 30 Sep 2021 19:08:32 -0000 https://gcc.gnu.org/g:3a70195d7da49fe793ce3eb0e839b9ceea96c97a commit r9-9749-g3a70195d7da49fe793ce3eb0e839b9ceea96c97a Author: Harald Anlauf Date: Mon Sep 13 19:28:10 2021 +0200 Fortran - ensure simplification of bounds of array-valued named constants gcc/fortran/ChangeLog: PR fortran/82314 * decl.c (add_init_expr_to_sym): For proper initialization of array-valued named constants the array bounds need to be simplified before adding the initializer. gcc/testsuite/ChangeLog: PR fortran/82314 * gfortran.dg/pr82314.f90: New test. (cherry picked from commit 104c05c5284b7822d770ee51a7d91946c7e56d50) Diff: --- gcc/fortran/decl.c | 18 ++++++++++++++++++ gcc/testsuite/gfortran.dg/pr82314.f90 | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 00321da827e..51238e49fb1 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -2043,6 +2043,24 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) sym->as->type = AS_EXPLICIT; } + /* Ensure that explicit bounds are simplified. */ + if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension + && sym->as->type == AS_EXPLICIT) + { + for (int dim = 0; dim < sym->as->rank; ++dim) + { + gfc_expr *e; + + e = sym->as->lower[dim]; + if (e->expr_type != EXPR_CONSTANT) + gfc_reduce_init_expr (e); + + e = sym->as->upper[dim]; + if (e->expr_type != EXPR_CONSTANT) + gfc_reduce_init_expr (e); + } + } + /* Need to check if the expression we initialized this to was one of the iso_c_binding named constants. If so, and we're a parameter (constant), let it be iso_c. diff --git a/gcc/testsuite/gfortran.dg/pr82314.f90 b/gcc/testsuite/gfortran.dg/pr82314.f90 new file mode 100644 index 00000000000..3a147e22711 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr82314.f90 @@ -0,0 +1,11 @@ +! { dg-do run } +! PR fortran/82314 - ICE in gfc_conv_expr_descriptor + +program p + implicit none + integer, parameter :: karray(merge(3,7,.true.):merge(3,7,.false.)) = 1 + integer, parameter :: i = size (karray) + integer, parameter :: l = lbound (karray,1) + integer, parameter :: u = ubound (karray,1) + if (l /= 3 .or. u /= 7 .or. i /= 5) stop 1 +end