From 808a6eadda1a353ce3a70556feac128580491b24 Mon Sep 17 00:00:00 2001 From: Jose Rui Faustino de Sousa Date: Wed, 22 Apr 2020 18:20:26 +0200 Subject: [PATCH] For assumed-size arrays check if the reference is to a full array. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2020-04-22 José Rui Faustino de Sousa PR fortran/90350 * simplify.c (simplify_bound): In the case of assumed-size arrays check if the reference is to a full array. 2020-04-22 José Rui Faustino de Sousa PR fortran/90350 * gfortran.dg/PR90350.f90: New test. --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/simplify.c | 4 +++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/PR90350.f90 | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/PR90350.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e02815ee246..1ab0514f49e 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2020-04-22 José Rui Faustino de Sousa + + PR fortran/90350 + * simplify.c (simplify_bound): In the case of assumed-size arrays + check if the reference is to a full array. + 2020-04-22 Tobias Burnus PR fortran/94709 diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index c7a4f77e70b..eb8b2afeb29 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -4157,6 +4157,7 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) { gfc_ref *ref; gfc_array_spec *as; + ar_type type = AR_UNKNOWN; int d; if (array->ts.type == BT_CLASS) @@ -4180,6 +4181,7 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) switch (ref->type) { case REF_ARRAY: + type = ref->u.ar.type; switch (ref->u.ar.type) { case AR_ELEMENT: @@ -4233,7 +4235,7 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) int k; /* UBOUND(ARRAY) is not valid for an assumed-size array. */ - if (upper && as && as->type == AS_ASSUMED_SIZE) + if (upper && type == AR_FULL && as && as->type == AS_ASSUMED_SIZE) { /* An error message will be emitted in check_assumed_size_reference (resolve.c). */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f6dd7ac6777..b23a2dd423b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-22 José Rui Faustino de Sousa + + PR fortran/90350 + * gfortran.dg/PR90350.f90: New test. + 2020-04-22 Paolo Carlini PR c++/90448 diff --git a/gcc/testsuite/gfortran.dg/PR90350.f90 b/gcc/testsuite/gfortran.dg/PR90350.f90 new file mode 100644 index 00000000000..2e2cf10a813 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/PR90350.f90 @@ -0,0 +1,19 @@ +! { dg-do compile } +! +! Test the fix for PR90350 +! +! Contributed by +! + +program artificial +implicit none +integer :: arr(-10:10) + call asub(arr,size(arr)) +end program artificial +subroutine asub(arr,n) +integer,intent(in) :: arr(*) +integer,intent(in) :: n + write(*,*)'UPPER=',ubound(arr(:n)) + write(*,*)'LOWER=',lbound(arr(:n)) + write(*,*)'SIZE=',size(arr(:n)) +end subroutine asub -- 2.30.2