public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] Fortran: Fix rank of assumed-rank array [PR99043]
@ 2021-02-11 18:02 Tobias Burnus
  2021-02-12 13:25 ` Paul Richard Thomas
  2021-02-17 21:56 ` Thomas Koenig
  0 siblings, 2 replies; 3+ messages in thread
From: Tobias Burnus @ 2021-02-11 18:02 UTC (permalink / raw)
  To: gcc-patches, fortran

[-- Attachment #1: Type: text/plain, Size: 763 bytes --]

In the Fortran standard, I think it is best explained
in the description of the RANK intrinsic:

"Example. If X is an assumed-rank dummy argument and
its associated effective argument is an array of rank,
RANK(X) has the value 3."

That's already well tested in assumed_rank_16.f90;
however, as the PR shows, this should not be reset
to "-1" when passing it further on as actual argument to
another assumed-rank dummy argument.

OK for mainline?
Reported against GCC 10, not a regression but simple wrong-code fix;
does it make sense to apply there was well?

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

[-- Attachment #2: assumed-rank-fix.diff --]
[-- Type: text/x-patch, Size: 2491 bytes --]

Fortran: Fix rank of assumed-rank array [PR99043]

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.

 gcc/fortran/trans-expr.c                      |  5 ++--
 gcc/testsuite/gfortran.dg/assumed_rank_20.f90 | 36 +++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index b0c8d577ca5..103cb31c664 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6403,9 +6403,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)
diff --git a/gcc/testsuite/gfortran.dg/assumed_rank_20.f90 b/gcc/testsuite/gfortran.dg/assumed_rank_20.f90
new file mode 100644
index 00000000000..10ad1fc8e89
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/assumed_rank_20.f90
@@ -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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch] Fortran: Fix rank of assumed-rank array [PR99043]
  2021-02-11 18:02 [Patch] Fortran: Fix rank of assumed-rank array [PR99043] Tobias Burnus
@ 2021-02-12 13:25 ` Paul Richard Thomas
  2021-02-17 21:56 ` Thomas Koenig
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Richard Thomas @ 2021-02-12 13:25 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, fortran

Hi Tobias,

The patch is good for 10- and 11-branches.

Thanks

Paul


On Thu, 11 Feb 2021 at 18:59, Tobias Burnus <tobias@codesourcery.com> wrote:

> In the Fortran standard, I think it is best explained
> in the description of the RANK intrinsic:
>
> "Example. If X is an assumed-rank dummy argument and
> its associated effective argument is an array of rank,
> RANK(X) has the value 3."
>
> That's already well tested in assumed_rank_16.f90;
> however, as the PR shows, this should not be reset
> to "-1" when passing it further on as actual argument to
> another assumed-rank dummy argument.
>
> OK for mainline?
> Reported against GCC 10, not a regression but simple wrong-code fix;
> does it make sense to apply there was well?
>
> Tobias
>
> -----------------
> Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München
> Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank
> Thürauf
>


-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch] Fortran: Fix rank of assumed-rank array [PR99043]
  2021-02-11 18:02 [Patch] Fortran: Fix rank of assumed-rank array [PR99043] Tobias Burnus
  2021-02-12 13:25 ` Paul Richard Thomas
@ 2021-02-17 21:56 ` Thomas Koenig
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Koenig @ 2021-02-17 21:56 UTC (permalink / raw)
  To: Tobias Burnus, gcc-patches, fortran


Hi Tobias,

> OK for mainline?
> Reported against GCC 10, not a regression but simple wrong-code fix;
> does it make sense to apply there was well?

OK for both.

Thanks for the patch!

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-17 21:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-11 18:02 [Patch] Fortran: Fix rank of assumed-rank array [PR99043] Tobias Burnus
2021-02-12 13:25 ` Paul Richard Thomas
2021-02-17 21:56 ` Thomas Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).