diff mbox series

[committed,Fortran] PR68020 – Fix implied-shape handling for rank > 2

Message ID e73dfda9-a156-af6c-9696-8dc99865b2d6@net-b.de
State New
Headers show
Series [committed,Fortran] PR68020 – Fix implied-shape handling for rank > 2 | expand

Commit Message

Tobias Burnus Jan. 2, 2020, 3:43 p.m. UTC
implied-shape: Used with PARAMETER; takes the shape of the RHS and 
(F2018, R824) "implied-shape-spec  is  assumed-implied-spec, 
assumed-implied-spec-list"

When matching an element in an array spec of this type, i.e. (R821) 
"assumed-implied-spec is [lower-bound: ] *", the matcher always returns 
AS_ASSUMED_SIZE as – without further knowledge – the two, assumed-size 
and implied-shape, are indistinguishable:

current_type = match_array_element_spec (as);

When matching the lowest dimension (as->rank = 1), as->type is set to 
current_type – for the same reason as above. However, when matching the 
second time an element of type "AS_ASSUMED_SIZE", one knows that it 
cannot be a valid assumed-size array – but it can be a valid 
implied-shape array. Hence, it is turned into the latter: as->type = 
AS_IMPLIED_SHAPE.

If we now patch the third, etc. dimension, current_type is still 
assumed-size but as->type is now implied-size. Seemingly, the code 
writer was confused between assumed-shape and assumed-size …

Committed as Rev. 279835 after building an regtesting the attached patch.

Tobias

Comments

Rainer Orth Jan. 2, 2020, 8:44 p.m. UTC | #1
Hi Tobias,

> implied-shape: Used with PARAMETER; takes the shape of the RHS and (F2018,
> R824) "implied-shape-spec  is  assumed-implied-spec,
> assumed-implied-spec-list"
>
> When matching an element in an array spec of this type, i.e. (R821)
> "assumed-implied-spec is [lower-bound: ] *", the matcher always returns
> AS_ASSUMED_SIZE as – without further knowledge – the two, assumed-size and
> implied-shape, are indistinguishable:
>
> current_type = match_array_element_spec (as);
>
> When matching the lowest dimension (as->rank = 1), as->type is set to
> current_type – for the same reason as above. However, when matching the
> second time an element of type "AS_ASSUMED_SIZE", one knows that it cannot
> be a valid assumed-size array – but it can be a valid implied-shape
> array. Hence, it is turned into the latter: as->type = AS_IMPLIED_SHAPE.
>
> If we now patch the third, etc. dimension, current_type is still
> assumed-size but as->type is now implied-size. Seemingly, the code writer
> was confused between assumed-shape and assumed-size …
>
> Committed as Rev. 279835 after building an regtesting the attached patch.

seems you missed

+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O0  compilation failed to produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O1  compilation failed to produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O2  compilation failed to produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  compilation failed to produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O3 -g  compilation failed to produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -Os  compilation failed to produce executable

The new test is expected to fail compilation everywhere, but is still
marked { dg-do run }.  Usually a sign of a problem in the regtest
procedure: don't check only for (new) FAILs, but compare mail-report.log
output before and after the patch.

I guess the test should just be marked dg-do compile instead.

	Rainer
Jakub Jelinek Jan. 2, 2020, 11:59 p.m. UTC | #2
On Thu, Jan 02, 2020 at 04:43:29PM +0100, Tobias Burnus wrote:
> Committed as Rev. 279835 after building an regtesting the attached patch.

+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O0  compilation failed to produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O1  compilation failed to produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O2  compilation failed to produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  compilation failed to produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O3 -g  compilation failed to produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -Os  compilation failed to produce executable

Fixed thusly, tested on x86_64-linux, committed to trunk as obvious.

2020-01-03  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/68020
	* gfortran.dg/impled_shape_5.f90: Use dg-do compile rather than dg-do
	run.

--- gcc/testsuite/gfortran.dg/implied_shape_5.f90	(revision 279848)
+++ gcc/testsuite/gfortran.dg/implied_shape_5.f90	(working copy)
@@ -1,4 +1,4 @@
-! { dg-do run }
+! { dg-do compile }
 !
 ! PR fortran/68020
 !

	Jakub
Tobias Burnus Jan. 3, 2020, 8:02 a.m. UTC | #3
Sorry – I had fixed it locally before the commit, but forgot the "git 
add" for that change :-(

Thanks for the fix.

Tobias

On 1/3/20 12:59 AM, Jakub Jelinek wrote:
> On Thu, Jan 02, 2020 at 04:43:29PM +0100, Tobias Burnus wrote:
>> Committed as Rev. 279835 after building an regtesting the attached patch.
> +UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O0  compilation failed to produce executable
> +UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O1  compilation failed to produce executable
> +UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O2  compilation failed to produce executable
> +UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  compilation failed to produce executable
> +UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O3 -g  compilation failed to produce executable
> +UNRESOLVED: gfortran.dg/implied_shape_5.f90   -Os  compilation failed to produce executable
>
> Fixed thusly, tested on x86_64-linux, committed to trunk as obvious.
>
> 2020-01-03  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR fortran/68020
> 	* gfortran.dg/impled_shape_5.f90: Use dg-do compile rather than dg-do
> 	run.
>
> --- gcc/testsuite/gfortran.dg/implied_shape_5.f90	(revision 279848)
> +++ gcc/testsuite/gfortran.dg/implied_shape_5.f90	(working copy)
> @@ -1,4 +1,4 @@
> -! { dg-do run }
> +! { dg-do compile }
>   !
>   ! PR fortran/68020
>   !
>
> 	Jakub
>
diff mbox series

Patch

Index: gcc/testsuite/gfortran.dg/implied_shape_4.f90
===================================================================
--- gcc/testsuite/gfortran.dg/implied_shape_4.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/implied_shape_4.f90	(revision 279835)
@@ -0,0 +1,45 @@ 
+! { dg-do run }
+! { dg-additional-options "-std=f2008" }
+!
+! PR fortran/68020
+!
+! Contributed by Gerhard Steinmetz
+!
+subroutine rank_1_2
+  integer, parameter :: a(1, 2) = 0
+  integer, parameter :: x(*, *) = a
+  integer, parameter :: y(11:*, 12:*) = a
+  integer :: k
+  if (any (lbound(x) /= [1,1])) stop 1
+  if (any (ubound(x) /= [1,2])) stop 2
+  if (any (lbound(y) /= [11,12])) stop 3
+  if (any (ubound(y) /= [11,13])) stop 4
+end
+
+subroutine rank_3
+  integer, parameter :: a(1, 2, 3) = 0
+  integer, parameter :: x(*, *, *) = a
+  integer, parameter :: y(11:*, 12:*, 13:*) = a
+  integer :: k
+  if (any (lbound(x) /= [1,1,1])) stop 5
+  if (any (ubound(x) /= [1,2,3])) stop 6
+  if (any (lbound(y) /= [11,12,13])) stop 7
+  if (any (ubound(y) /= [11,13,15])) stop 8
+end
+
+subroutine rank_4
+  integer, parameter :: a(1, 2, 3, 4) = 0
+  integer, parameter :: x(*, *, *, *) = a
+  integer, parameter :: y(11:*, 12:*, 13:*, 14:*) = a
+  integer :: k
+  if (any (lbound(x) /= [1,1,1,1])) stop 9
+  if (any (ubound(x) /= [1,2,3,4])) stop 10
+  if (any (lbound(y) /= [11,12,13,14])) stop 11
+  if (any (ubound(y) /= [11,13,15,17])) stop 12
+end
+
+program p
+  call rank_1_2
+  call rank_3
+  call rank_4
+end program p
Index: gcc/testsuite/gfortran.dg/implied_shape_5.f90
===================================================================
--- gcc/testsuite/gfortran.dg/implied_shape_5.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/implied_shape_5.f90	(revision 279835)
@@ -0,0 +1,29 @@ 
+! { dg-do run }
+!
+! PR fortran/68020
+!
+! Reject mixing explicit-shape and implied-shape arrays
+!
+subroutine rank_1_2
+  integer, parameter :: a(1, 2) = 0
+  integer, parameter :: y(11:11, 12:*) = a ! { dg-error "Assumed size array at .1. must be a dummy argument" }
+  integer, parameter :: x(:, *) = a ! { dg-error "Bad specification for deferred shape array" }
+end
+
+subroutine rank_3
+  integer, parameter :: a(1, 2, 3) = 0
+  integer, parameter :: y(11:*, 12:14, 13:*) = a  ! { dg-error "Bad specification for assumed size array" }
+  integer, parameter :: x(11:*, :, 13:*) = a      ! { dg-error "Bad specification for assumed size array" }
+end
+
+subroutine rank_4
+  integer, parameter :: a(1, 2, 3, 4) = 0
+  integer, parameter :: y(11:*, 12:*, 13:*, 14:17) = a ! { dg-error "Bad array specification for implied-shape array" }
+  integer, parameter :: y(11:*, 12:*, 13:*, 14:) = a   ! { dg-error "Bad array specification for implied-shape array" }
+end
+
+program p
+  call rank_1_2
+  call rank_3
+  call rank_4
+end program p
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 279834)
+++ gcc/testsuite/ChangeLog	(revision 279835)
@@ -1,3 +1,9 @@ 
+2020-01-02  Tobias Burnus  <tobias@codesourcery.com>
+
+	PR fortran/68020
+	* gfortran.dg/implied_shape_4.f90: New.
+	* gfortran.dg/implied_shape_5.f90: New.
+
 2020-01-02  Jakub Jelinek  <jakub@redhat.com>
 
 	PR ipa/93087
Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c	(revision 279834)
+++ gcc/fortran/array.c	(revision 279835)
@@ -599,7 +599,7 @@ 
 	    goto cleanup;
 
 	  case AS_IMPLIED_SHAPE:
-	    if (current_type != AS_ASSUMED_SHAPE)
+	    if (current_type != AS_ASSUMED_SIZE)
 	      {
 		gfc_error ("Bad array specification for implied-shape"
 			   " array at %C");
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(revision 279834)
+++ gcc/fortran/ChangeLog	(revision 279835)
@@ -1,3 +1,9 @@ 
+2020-01-02  Tobias Burnus  <tobias@codesourcery.com>
+
+	PR fortran/68020
+	* array.c (gfc_match_array_spec): Fix implied-type matching
+	for rank > 2.
+
 2020-01-01  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
 	PR fortran/93113