For assumed-size arrays check if the reference is to a full array.
authorJose Rui Faustino de Sousa <jrfsousa@gmail.com>
Wed, 22 Apr 2020 16:20:26 +0000 (18:20 +0200)
committerThomas König <tkoenig@gcc.gnu.org>
Wed, 22 Apr 2020 16:20:26 +0000 (18:20 +0200)
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.

gcc/fortran/ChangeLog
gcc/fortran/simplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/PR90350.f90 [new file with mode: 0644]

index e02815ee246454e38798ad06f207fdc58ef1ed4e..1ab0514f49e3c971df25c2e4ed8bd186d8d61e13 100644 (file)
@@ -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
index c7a4f77e70b13381c52d1e31220ba054360bf4c5..eb8b2afeb29dedb3b346db2dc4ad2bf7e277cf82 100644 (file)
@@ -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).  */
index f6dd7ac677775e2236739ec514096ce4912fda71..b23a2dd423b9b4225a1c77b9bd658321fc1a65d0 100644 (file)
@@ -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 (file)
index 0000000..2e2cf10
--- /dev/null
@@ -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