]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix 'select rank' for allocatables/pointers
authorTobias Burnus <tobias@codesourcery.com>
Wed, 27 Oct 2021 08:59:27 +0000 (10:59 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 27 Oct 2021 08:59:27 +0000 (10:59 +0200)
gcc/fortran/ChangeLog:

* trans-stmt.c (gfc_trans_select_rank_cases): Fix condition
for allocatables/pointers.

gcc/testsuite/ChangeLog:

* gfortran.dg/PR93963.f90: Extend testcase by scan-tree-dump test.

gcc/fortran/trans-stmt.c
gcc/testsuite/gfortran.dg/PR93963.f90

index c66a3bee83e66e2640a2f63d48aadf39381b9e3d..eaf2cc25f214e59e1d6aa7e9fe6a450cb9020327 100644 (file)
@@ -3685,7 +3685,7 @@ gfc_trans_select_rank_cases (gfc_code * code)
   rank = gfc_conv_descriptor_rank (se.expr);
   rank = gfc_evaluate_now (rank, &block);
   symbol_attribute attr = gfc_expr_attr (code->expr1);
-  if (!attr.pointer || !attr.allocatable)
+  if (!attr.pointer && !attr.allocatable)
     {
       /* Special case for assumed-rank ('rank(*)', internally -1):
         rank = (rank == 0 || ubound[rank-1] != -1) ? rank : -1.  */
index 66c937974ac1c2ff844158557eefb00088bd6fea..6769d7fe061049456291e46b6517e74d92a5cdd0 100644 (file)
@@ -1,4 +1,5 @@
 ! { dg-do run }
+! { dg-additional-options "-fdump-tree-original" }
 !
 ! Test the fix for PR93963
 !
@@ -190,3 +191,7 @@ program selr_p
   deallocate(inta)
 
 end program selr_p
+
+! Special code for assumed rank - but only if not allocatable/pointer
+! Thus, expect it only once for subroutine rank_o but not for rank_a or rank_p
+! { dg-final { scan-tree-dump-times "ubound != -1" 1 "original" } }