From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 9AA0D3858D39; Fri, 26 Nov 2021 20:50:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9AA0D3858D39 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-9846] Fortran: do not attempt simplification of [LU]BOUND for pointer/allocatable X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: 781007e491e39d5980ce2e83de99546b9e28ad1c X-Git-Newrev: dd1871c823e2ec9a500ac5ad3c87a117b934fa3b Message-Id: <20211126205003.9AA0D3858D39@sourceware.org> Date: Fri, 26 Nov 2021 20:50:03 +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, 26 Nov 2021 20:50:03 -0000 https://gcc.gnu.org/g:dd1871c823e2ec9a500ac5ad3c87a117b934fa3b commit r9-9846-gdd1871c823e2ec9a500ac5ad3c87a117b934fa3b Author: Harald Anlauf Date: Tue Nov 23 21:39:36 2021 +0100 Fortran: do not attempt simplification of [LU]BOUND for pointer/allocatable gcc/fortran/ChangeLog: PR fortran/103392 * simplify.c (simplify_bound): Do not try to simplify LBOUND/UBOUND for arrays with POINTER or ALLOCATABLE attribute. gcc/testsuite/ChangeLog: PR fortran/103392 * gfortran.dg/bound_simplification_7.f90: New test. (cherry picked from commit 16e95050f71e9fa408e9bd8ccd415b0e7adc66e5) Diff: --- gcc/fortran/simplify.c | 6 ++++++ gcc/testsuite/gfortran.dg/bound_simplification_7.f90 | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 2004895fbe3..db74925badc 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -4197,6 +4197,12 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) || (as->type == AS_ASSUMED_SHAPE && upper))) return NULL; + /* 'array' shall not be an unallocated allocatable variable or a pointer that + is not associated. */ + if (array->expr_type == EXPR_VARIABLE + && (gfc_expr_attr (array).allocatable || gfc_expr_attr (array).pointer)) + return NULL; + gcc_assert (!as || (as->type != AS_DEFERRED && array->expr_type == EXPR_VARIABLE diff --git a/gcc/testsuite/gfortran.dg/bound_simplification_7.f90 b/gcc/testsuite/gfortran.dg/bound_simplification_7.f90 new file mode 100644 index 00000000000..3efecdff769 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bound_simplification_7.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! PR fortran/103392 - ICE in simplify_bound + +program p + integer, allocatable :: a(1:1) ! { dg-error "deferred shape or assumed rank" } + integer :: b(1) = lbound(a) ! { dg-error "does not reduce" } + integer :: c(1) = ubound(a) ! { dg-error "does not reduce" } +end + +subroutine s(x, y) + type t + integer :: i(3) + end type t + type(t), pointer :: x(:) + type(t), allocatable :: y(:) + integer, parameter :: m(1) = ubound (x(1)% i) + integer :: n(1) = ubound (y(1)% i) +end subroutine s