]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix rank of assumed-rank array [PR99043]
authorTobias Burnus <tobias@codesourcery.com>
Fri, 12 Feb 2021 15:43:54 +0000 (16:43 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Fri, 12 Feb 2021 15:43:54 +0000 (16:43 +0100)
gcc/fortran/ChangeLog:

PR fortran/99043
* trans-expr.c (gfc_conv_procedure_call): Don't reset
rank of assumed-rank array.

gcc/testsuite/ChangeLog:

PR fortran/99043
* gfortran.dg/assumed_rank_20.f90: New test.

(cherry picked from commit f699e0b16578cdc1be8b90691ef8b0964af32d2f)

gcc/fortran/ChangeLog.omp
gcc/fortran/trans-expr.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/assumed_rank_20.f90 [new file with mode: 0644]

index 9dd1f8dd2ef32fb97aaff8e0810c42e34bda5b55..a02606190319bbf937eed4bb7411e073d0a530fb 100644 (file)
@@ -1,3 +1,12 @@
+2021-02-12  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline
+       2021-02-12  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/99043
+       * trans-expr.c (gfc_conv_procedure_call): Don't reset
+       rank of assumed-rank array.
+
 2021-02-12  Tobias Burnus  <tobias@codesourcery.com>
 
        PR fortran/99045
index 25ffd4891a5dfb352c4bb7573e641c0e4cea9ee1..a3bd8ddd5998c3b4c89c6bb6361edb43052c56f9 100644 (file)
@@ -6235,9 +6235,10 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 
              /* Unallocated allocatable arrays and unassociated pointer arrays
                 need their dtype setting if they are argument associated with
-                assumed rank dummies.  */
+                assumed rank dummies, unless already assumed rank.  */
              if (!sym->attr.is_bind_c && e && fsym && fsym->as
-                 && fsym->as->type == AS_ASSUMED_RANK)
+                 && fsym->as->type == AS_ASSUMED_RANK
+                 && e->rank != -1)
                {
                  if (gfc_expr_attr (e).pointer
                      || gfc_expr_attr (e).allocatable)
index 3012c77ce8f68f53be71bb7d7d0f488816a3a965..8f5512990b85f1806a3389544fdae649197bdbe4 100644 (file)
@@ -1,3 +1,11 @@
+2021-02-12  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline
+       2021-02-12  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/99043
+       * gfortran.dg/assumed_rank_20.f90: New test.
+
 2021-02-12  Tobias Burnus  <tobias@codesourcery.com>
 
        PR fortran/99045
diff --git a/gcc/testsuite/gfortran.dg/assumed_rank_20.f90 b/gcc/testsuite/gfortran.dg/assumed_rank_20.f90
new file mode 100644 (file)
index 0000000..10ad1fc
--- /dev/null
@@ -0,0 +1,36 @@
+! { dg-do run }
+!
+! PR fortran/99043
+!
+module assumed_rank_module
+    implicit none
+    private
+
+    public :: rank_of_pointer_level1
+contains
+    subroutine rank_of_pointer_level1(ap,aa)
+        real, dimension(..), intent(in), pointer :: ap
+        real, dimension(..), intent(in), allocatable :: aa
+        if (rank(ap) /= 3) stop 1
+        if (rank(aa) /= 3) stop 2
+        call rank_of_pointer_level2(ap, aa)
+    end subroutine rank_of_pointer_level1
+
+    subroutine rank_of_pointer_level2(ap,aa)
+        real, dimension(..), intent(in), pointer :: ap
+        real, dimension(..), intent(in), allocatable :: aa
+
+        if (rank(ap) /= 3) stop 3
+        if (rank(aa) /= 3) stop 4
+    end subroutine rank_of_pointer_level2
+end module assumed_rank_module
+
+program assumed_rank
+    use :: assumed_rank_module, only : rank_of_pointer_level1
+    implicit none
+    real, dimension(:,:,:), pointer :: ap
+    real, dimension(:,:,:), allocatable :: aa
+
+    ap => null()
+    call rank_of_pointer_level1(ap, aa)
+end program assumed_rank