[gcc/devel/ranger] For assumed-size arrays check if the reference is to a full array.

Aldy Hernandez aldyh@gcc.gnu.org
Wed Jun 17 20:39:25 GMT 2020


https://gcc.gnu.org/g:808a6eadda1a353ce3a70556feac128580491b24

commit 808a6eadda1a353ce3a70556feac128580491b24
Author: Jose Rui Faustino de Sousa <jrfsousa@gmail.com>
Date:   Wed Apr 22 18:20:26 2020 +0200

    For assumed-size arrays check if the reference is to a full array.
    
    2020-04-22  José Rui Faustino de Sousa  <jrfsousa@gmail.com>
    
            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  <jrfsousa@gmail.com>
    
            PR fortran/90350
            * gfortran.dg/PR90350.f90: New test.

Diff:
---
 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(-)

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  <jrfsousa@gmail.com>
+
+	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  <tobias@codesourcery.com>
 
 	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  <jrfsousa@gmail.com>
+
+	PR fortran/90350
+	* gfortran.dg/PR90350.f90: New test.
+
 2020-04-22  Paolo Carlini  <paolo.carlini@oracle.com>
 
 	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  <urbanjost@comcast.net>
+!
+
+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


More information about the Gcc-cvs mailing list