public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran] [01..04/14] Support coarray subreferences: Add subreferences support in gfc_conv_expr_descriptor
  2011-10-07 14:39 [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Mikael Morin
  2011-10-07 14:39 ` [Patch, fortran] [12/14] Support coarray subreferences: Fix simplify_cobound Mikael Morin
  2011-10-07 14:39 ` [Patch, fortran] [10..11/14] Support coarray subreferences: Fix dim_corank_check Mikael Morin
@ 2011-10-07 14:39 ` Mikael Morin
  2011-10-07 14:39 ` [Patch, fortran] [05..09/14] Support coarray subreferences: Add support for array elements Mikael Morin
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Mikael Morin @ 2011-10-07 14:39 UTC (permalink / raw)
  To: gfortran, GCC patches

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

These patches change the descriptor initialization code in
gfc_conv_expr_descriptor introduced by the recent scalarizer patchset at
http://gcc.gnu.org/ml/fortran/2011-09/msg00056.html.
It was supposing (just like the code it was replacing) that coarrays were
always full, but a subobject of a coarray is also a coarray (if non-allocatable, non-pointer).
Thus, if `a' is a coarray of rank 2; `a', `a(1,:)' and `a(1,2)' are all valid
coarrays.
Because of the two latter ones, we have to distinguish between the full array
rank (2 in the three cases above), and the partial reference rank (respectively
2, 1, 0).
As a result:
 - in patch 4, we use loop.dimen (partial rank) instead of ndim (full rank) for
   accessing loop and descriptor elements.
 - in patch 3, we count codimensions from 0 and add to it either ndim or
   loop.dimen depending on whether we access array ref's elements or loop
   elements.
Patches 1 and 2 are preliminary changes.

OK?


[-- Attachment #2: pr50420-1.CL --]
[-- Type: text/plain, Size: 129 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_expr_descriptor): Move ndim initialization
	earlier.

[-- Attachment #3: pr50420-1.diff --]
[-- Type: text/x-diff, Size: 645 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 5144398..1db2186 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -5962,6 +5962,8 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
       tree to;
       tree base;
 
+      ndim = info->ref ? info->ref->u.ar.dimen : info->dimen;
+
       if (se->want_coarray)
 	{
 	  codim = gfc_get_corank (expr);
@@ -6034,7 +6036,6 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
       else
 	base = NULL_TREE;
 
-      ndim = info->ref ? info->ref->u.ar.dimen : info->dimen;
       for (n = 0; n < ndim; n++)
 	{
 	  stride = gfc_conv_array_stride (desc, n);

[-- Attachment #4: pr50420-2.CL --]
[-- Type: text/plain, Size: 122 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.c (gfc_conv_expr_descriptor): Save some horizontal space.

[-- Attachment #5: pr50420-2.diff --]
[-- Type: text/x-diff, Size: 1273 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 1db2186..034486d 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -5966,16 +5966,18 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
 
       if (se->want_coarray)
 	{
+	  gfc_array_ref *ar = &info->ref->u.ar;
+
 	  codim = gfc_get_corank (expr);
 	  for (n = ss->data.info.dimen; n < ss->data.info.dimen + codim - 1;
 	       n++)
 	    {
 	      /* Make sure we are not lost somehow.  */
-	      gcc_assert (info->ref->u.ar.dimen_type[n] == DIMEN_THIS_IMAGE);
+	      gcc_assert (ar->dimen_type[n] == DIMEN_THIS_IMAGE);
 
 	      /* Make sure the call to gfc_conv_section_startstride won't 
 	         generate unnecessary code to calculate stride.  */
-	      gcc_assert (info->ref->u.ar.stride[n] == NULL);
+	      gcc_assert (ar->stride[n] == NULL);
 
 	      gfc_conv_section_startstride (&loop, ss, n);
 	      loop.from[n] = info->start[n];
@@ -5983,7 +5985,7 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
 	    }
 
 	  gcc_assert (n == ss->data.info.dimen + codim - 1);
-	  evaluate_bound (&loop.pre, info->start, info->ref->u.ar.start,
+	  evaluate_bound (&loop.pre, info->start, ar->start,
 			  info->descriptor, n, true);
 	  loop.from[n] = info->start[n];
 	}

[-- Attachment #6: pr50420-3.CL --]
[-- Type: text/plain, Size: 236 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* trans-array.c (gfc_conv_expr_descriptor): Count codimensions starting
	from zero, and add then the relevant offset (either ndim or loop.dimen)
	depending on context.

[-- Attachment #7: pr50420-3.diff --]
[-- Type: text/x-diff, Size: 1473 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 034486d..57534e0 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -5969,25 +5969,24 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
 	  gfc_array_ref *ar = &info->ref->u.ar;
 
 	  codim = gfc_get_corank (expr);
-	  for (n = ss->data.info.dimen; n < ss->data.info.dimen + codim - 1;
-	       n++)
+	  for (n = 0; n < codim - 1; n++)
 	    {
 	      /* Make sure we are not lost somehow.  */
-	      gcc_assert (ar->dimen_type[n] == DIMEN_THIS_IMAGE);
+	      gcc_assert (ar->dimen_type[n + ndim] == DIMEN_THIS_IMAGE);
 
 	      /* Make sure the call to gfc_conv_section_startstride won't 
 	         generate unnecessary code to calculate stride.  */
-	      gcc_assert (ar->stride[n] == NULL);
+	      gcc_assert (ar->stride[n + ndim] == NULL);
 
-	      gfc_conv_section_startstride (&loop, ss, n);
-	      loop.from[n] = info->start[n];
-	      loop.to[n]   = info->end[n];
+	      gfc_conv_section_startstride (&loop, ss, n + ndim);
+	      loop.from[n + loop.dimen] = info->start[n + ndim];
+	      loop.to[n + loop.dimen]   = info->end[n + ndim];
 	    }
 
-	  gcc_assert (n == ss->data.info.dimen + codim - 1);
+	  gcc_assert (n == codim - 1);
 	  evaluate_bound (&loop.pre, info->start, ar->start,
-			  info->descriptor, n, true);
-	  loop.from[n] = info->start[n];
+			  info->descriptor, n + ndim, true);
+	  loop.from[n + loop.dimen] = info->start[n + ndim];
 	}
       else
 	codim = 0;

[-- Attachment #8: pr50420-4.CL --]
[-- Type: text/plain, Size: 171 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* trans-array.c (gfc_conv_expr_descriptor): Use loop.dimen instead of
	ndim for the descriptor's rank.

[-- Attachment #9: pr50420-4.diff --]
[-- Type: text/x-diff, Size: 642 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 57534e0..605b356 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -6138,13 +6138,13 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
 					  gfc_rank_cst[dim], stride);
 	}
 
-      for (n = ndim; n < ndim + codim; n++)
+      for (n = loop.dimen; n < loop.dimen + codim; n++)
 	{
 	  from = loop.from[n];
 	  to = loop.to[n];
 	  gfc_conv_descriptor_lbound_set (&loop.pre, parm,
 					  gfc_rank_cst[n], from);
-	  if (n < ndim + codim - 1)
+	  if (n < loop.dimen + codim - 1)
 	    gfc_conv_descriptor_ubound_set (&loop.pre, parm,
 					    gfc_rank_cst[n], to);
 	}

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

* [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences
@ 2011-10-07 14:39 Mikael Morin
  2011-10-07 14:39 ` [Patch, fortran] [12/14] Support coarray subreferences: Fix simplify_cobound Mikael Morin
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Mikael Morin @ 2011-10-07 14:39 UTC (permalink / raw)
  To: gfortran, GCC patches

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

Hello, 

the following patches propose to fix bug fortran/50420:
gfortran has been rejecting coarrays as argument to the coarray intrinsics 
({l,u}cobound, image_index) if they had a subreference.
The standard, however, has:
   A subobject of a coarray is a coarray if it does not have any cosubscripts,
   vector subscripts, allocatable component selection, or pointer component
   selection.

The recent scalarizer patchset at 
http://gcc.gnu.org/ml/fortran/2011-09/msg00056.html
makes thing worse by changing a rejects-valid bug into a ice-on-valid bug.

These patches make the necessary change to accept coarray subreferences

The full patchset has passed the fortran testsuite successfully.
OK for trunk?



Patches layout

 01..04/14: Add support for non-full arrays in descriptor initialization code.

 05..09/14: Make walk_coarray initialize the scalarizer structs properly to
            accept expression with subreferences.

 10..11/14: Fix corank checking

     12/14: Accept coarray subreferences in simplify_cobound

     13/14: Fix gfc_build_array_type

     14/14: Fix gfc_build_array_ref

[-- Attachment #2: pr50420-tests.CL --]
[-- Type: text/plain, Size: 167 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* gfortran.dg/coarray_subobject_1.f90: New test.
	* gfortran.dg/coarray/subobject_1.f90: New test.

[-- Attachment #3: coarray_subobject_1.f90 --]
[-- Type: text/plain, Size: 1281 bytes --]

! { dg-do compile }
! { dg-options "-fcoarray=single" }
!
! PR fortran/50420
! Coarray subobjects were not accepted as valid coarrays
! They should still be rejected if one of the component reference is allocatable
! or pointer

type t
  integer :: i
end type t
type t2
  type(t), allocatable :: a
  type(t), pointer     :: c
end type t2
type(t2) :: b[5:*]
allocate(b%a)
allocate(b%c)
b%a%i = 7
b%c%i = 13
if (b%a%i /= 7) call abort
if (any (lcobound(b%a) /= (/ 5 /))) call abort             ! { dg-error "Expected coarray variable" }
if (ucobound(b%a, dim=1) /= this_image() + 4) call abort   ! { dg-error "Expected coarray variable" }
if (any (lcobound(b%a%i) /= (/ 5 /))) call abort           ! { dg-error "Expected coarray variable" }
if (ucobound(b%a%i, dim=1) /= this_image() + 4) call abort ! { dg-error "Expected coarray variable" }
if (b%c%i /= 13) call abort
if (any (lcobound(b%c) /= (/ 5 /))) call abort             ! { dg-error "Expected coarray variable" }
if (ucobound(b%c, dim=1) /= this_image() + 4) call abort   ! { dg-error "Expected coarray variable" }
if (any (lcobound(b%c%i) /= (/ 5 /))) call abort           ! { dg-error "Expected coarray variable" }
if (ucobound(b%c%i, dim=1) /= this_image() + 4) call abort ! { dg-error "Expected coarray variable" }
end

[-- Attachment #4: subobject_1.f90 --]
[-- Type: text/plain, Size: 1323 bytes --]

! { dg-do run }
!
! PR fortran/50420
! Coarray subobjects were not accepted as valid coarrays

  integer  :: i
  integer, parameter :: la = 4, lb = 5, lc = 8
  integer, parameter :: init(la) = -4 + (/ (i, i=1,la) /)
  
  type t
    integer :: i
  end type t
  type t2
    type(t), allocatable :: a[:]
  end type t2
  type t3
    type(t), allocatable :: a(:)[:]
  end type t3

  type(t2) :: b
  type(t3) :: c

  allocate(b%a[lb:*])
  b%a%i = 7
  if (b%a%i /= 7) call abort
  if (any (lcobound(b%a) /= (/ lb /))) call abort
  if (ucobound(b%a, dim=1) /= this_image() + lb - 1) call abort
  if (any (lcobound(b%a%i) /= (/ lb /))) call abort
  if (ucobound(b%a%i, dim=1) /= this_image() + lb - 1) call abort
  allocate(c%a(la)[lc:*])
  c%a%i = init
  if (any(c%a%i /= init)) call abort
  if (any (lcobound(c%a) /= (/ lc /))) call abort
  if (ucobound(c%a, dim=1) /= this_image() + lc - 1) call abort
  if (any (lcobound(c%a%i) /= (/ lc /))) call abort
  if (ucobound(c%a%i, dim=1) /= this_image() + lc - 1) call abort
  if (c%a(2)%i /= init(2)) call abort
  if (any (lcobound(c%a(2)) /= (/ lc /))) call abort
  if (ucobound(c%a(2), dim=1) /= this_image() + lc - 1) call abort
  if (any (lcobound(c%a(2)%i) /= (/ lc /))) call abort
  if (ucobound(c%a(2)%i, dim=1) /= this_image() + lc - 1) call abort
  deallocate(b%a, c%a)
end

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

* [Patch, fortran] [05..09/14] Support coarray subreferences: Add support for array elements.
  2011-10-07 14:39 [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Mikael Morin
                   ` (2 preceding siblings ...)
  2011-10-07 14:39 ` [Patch, fortran] [01..04/14] Support coarray subreferences: Add subreferences support in gfc_conv_expr_descriptor Mikael Morin
@ 2011-10-07 14:39 ` Mikael Morin
  2011-10-07 14:45 ` [Patch, fortran] [13/14] Support coarray subreferences: don't force coarray lower bound to 1 Mikael Morin
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Mikael Morin @ 2011-10-07 14:39 UTC (permalink / raw)
  To: gfortran, GCC patches

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


The  walk_coarray function introduced at
http://gcc.gnu.org/ml/fortran/2011-09/msg00074.html doesn't (like the code it
replaces) support subreferences after the coarray.
These patches are going to change that.

- The first step is, while looking for the coarray reference, to really look for
  it, instead of walking blindly to the last ref (patch 7).
- Then, in the code generated, an offset to the full array has to be added,
  corresponding to the subreference.
  The path taken is to reuse the scalarizer initialization handling for array
  sections subreferences in gfc_walk_variable_expr, and then let the rest
  of the scalarizer do the right thing with that (patch 9).
- For that to work, we need to skip the array ref lookup in
  gfc_walk_variable_expr, which is not valid for coarrays. A new funtion
  gfc_walk_array_ref is introduced, containing all of gfc_walk_variable_expr's 
  code but the array ref lookup (patch 5).
- Then for array elements (like coarray(1,1)), we change them from AR_ELEMENT
  to AR_SECTION so that they get the same treatment as normal arrays in
  gfc_walk_array_ref (patch 8).
- There is a small problem with the latter change; there is an assertion in
  gfc_walk_array_ref that in the AR_SECTION case, rank is non-zero.
  Patch 6 fixes that.

OK?

PS: The patch numbering is odd, because I have tried to reorder patches so that
no regression is introduced.  However, I haven't checked that it is actually the
case.  All I know is at the end, it's fine. ;-)



[-- Attachment #2: pr50420-5.CL --]
[-- Type: text/plain, Size: 277 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-array.h (gfc_walk_array_ref): New prototype.
	* trans-array.c (gfc_walk_array_ref): New function, containing
	all but the beginning of gfc_walk_variable_expr's code.
	(gfc_walk_variable_expr): Use gfc_walk_array_ref.
	

[-- Attachment #3: pr50420-5.diff --]
[-- Type: text/x-diff, Size: 1240 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 605b356..1cfe382 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -7591,14 +7591,22 @@ static gfc_ss *
 gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
 {
   gfc_ref *ref;
-  gfc_array_ref *ar;
-  gfc_ss *newss;
-  int n;
 
   for (ref = expr->ref; ref; ref = ref->next)
     if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT)
       break;
 
+  return gfc_walk_array_ref (ss, expr, ref);
+}
+
+
+gfc_ss *
+gfc_walk_array_ref (gfc_ss * ss, gfc_expr * expr, gfc_ref * ref)
+{
+  gfc_array_ref *ar;
+  gfc_ss *newss;
+  int n;
+
   for (; ref; ref = ref->next)
     {
       if (ref->type == REF_SUBSTRING)
diff --git a/trans-array.h b/trans-array.h
index 73d8c40..4d737bd 100644
--- a/trans-array.h
+++ b/trans-array.h
@@ -70,6 +70,8 @@ void gfc_trans_static_array_pointer (gfc_symbol *);
 gfc_ss *gfc_walk_expr (gfc_expr *);
 /* Workhorse for gfc_walk_expr.  */
 gfc_ss *gfc_walk_subexpr (gfc_ss *, gfc_expr *);
+/* Workhorse for gfc_walk_variable_expr.  */
+gfc_ss *gfc_walk_array_ref (gfc_ss *, gfc_expr *, gfc_ref * ref);
 /* Walk the arguments of an elemental function.  */
 gfc_ss *gfc_walk_elemental_function_args (gfc_ss *, gfc_actual_arglist *,
 					  gfc_ss_type);

[-- Attachment #4: pr50420-6.CL --]
[-- Type: text/plain, Size: 152 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* trans-array.c (gfc_walk_array_ref): Allow zero rank arrays
	if they are coarrays.

[-- Attachment #5: pr50420-6.diff --]
[-- Type: text/x-diff, Size: 607 bytes --]

diff --git a/trans-array.c b/trans-array.c
index 1cfe382..4158a32 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -7688,8 +7688,10 @@ gfc_walk_array_ref (gfc_ss * ss, gfc_expr * expr, gfc_ref * ref)
 		  gcc_unreachable ();
 		}
 	    }
-	  /* We should have at least one non-elemental dimension.  */
-	  gcc_assert (newss->data.info.dimen > 0);
+	  /* We should have at least one non-elemental dimension,
+	     unless we are creating a descriptor for a (scalar) coarray.  */
+	  gcc_assert (newss->data.info.dimen > 0
+		      || newss->data.info.ref->u.ar.as->corank > 0);
 	  ss = newss;
 	  break;
 

[-- Attachment #6: pr50420-7.CL --]
[-- Type: text/plain, Size: 159 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* trans-intrinsic.c (walk_coarray): Allow subreferences after a
	coarray object reference.

[-- Attachment #7: pr50420-7.diff --]
[-- Type: text/x-diff, Size: 621 bytes --]

diff --git a/trans-intrinsic.c b/trans-intrinsic.c
index c47e678..7d12eb9 100644
--- a/trans-intrinsic.c
+++ b/trans-intrinsic.c
@@ -941,10 +941,16 @@ walk_coarray (gfc_expr *e)
       ss = gfc_get_array_ss (gfc_ss_terminator, e, 0, GFC_SS_SECTION);
 
       ref = e->ref;
-      while (ref->next)
-	ref = ref->next;
+      while (ref)
+	{
+	  if (ref->type == REF_ARRAY
+	      && ref->u.ar.codimen > 0)
+	    break;
+
+	  ref = ref->next;
+	}
 
-      gcc_assert (ref->type == REF_ARRAY && ref->u.ar.codimen > 0);
+      gcc_assert (ref != NULL);
       ref->u.ar.type = AR_FULL;
       ss->data.info.ref = ref;
     }

[-- Attachment #8: pr50420-8.CL --]
[-- Type: text/plain, Size: 137 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* trans-intrinsic.c (walk_coarray): Change AR_ELEMENT to AR_SECTION.

[-- Attachment #9: pr50420-8.diff --]
[-- Type: text/x-diff, Size: 361 bytes --]

diff --git a/trans-intrinsic.c b/trans-intrinsic.c
index 7d12eb9..e4a8873 100644
--- a/trans-intrinsic.c
+++ b/trans-intrinsic.c
@@ -951,7 +951,8 @@ walk_coarray (gfc_expr *e)
 	}
 
       gcc_assert (ref != NULL);
-      ref->u.ar.type = AR_FULL;
+      if (ref->u.ar.type == AR_ELEMENT)
+	ref->u.ar.type = AR_SECTION;
       ss->data.info.ref = ref;
     }
 

[-- Attachment #10: pr50420-9.CL --]
[-- Type: text/plain, Size: 173 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* trans-intrinsic.c (walk_coarray): Use gfc_walk_array_ref for
	the scalarization chain initialization. 

[-- Attachment #11: pr50420-9.diff --]
[-- Type: text/x-diff, Size: 593 bytes --]

diff --git a/trans-intrinsic.c b/trans-intrinsic.c
index e4a8873..95f7f0b 100644
--- a/trans-intrinsic.c
+++ b/trans-intrinsic.c
@@ -938,8 +938,6 @@ walk_coarray (gfc_expr *e)
     {
       gfc_ref *ref;
 
-      ss = gfc_get_array_ss (gfc_ss_terminator, e, 0, GFC_SS_SECTION);
-
       ref = e->ref;
       while (ref)
 	{
@@ -953,7 +951,7 @@ walk_coarray (gfc_expr *e)
       gcc_assert (ref != NULL);
       if (ref->u.ar.type == AR_ELEMENT)
 	ref->u.ar.type = AR_SECTION;
-      ss->data.info.ref = ref;
+      ss = gfc_reverse_ss (gfc_walk_array_ref (ss, e, ref));
     }
 
   return ss;

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

* [Patch, fortran] [10..11/14] Support coarray subreferences: Fix dim_corank_check
  2011-10-07 14:39 [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Mikael Morin
  2011-10-07 14:39 ` [Patch, fortran] [12/14] Support coarray subreferences: Fix simplify_cobound Mikael Morin
@ 2011-10-07 14:39 ` Mikael Morin
  2011-10-07 14:39 ` [Patch, fortran] [01..04/14] Support coarray subreferences: Add subreferences support in gfc_conv_expr_descriptor Mikael Morin
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Mikael Morin @ 2011-10-07 14:39 UTC (permalink / raw)
  To: gfortran, GCC patches

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

dim_corank_check uses gfc_find_array_ref to get coarray's array ref.
It won't work for obvious reasons for the case coarray(1,1) which is a
non-arrray (but still a coarray).
As the whole point of this is to get the corank, patch 10 replaces the call
to gfc_find_array_ref with a call to gfc_get_corank.
Then, in gfc_find_array_ref the coarray-specific code can be removed.
This is patch 11.

OK?

[-- Attachment #2: pr50420-10.CL --]
[-- Type: text/plain, Size: 132 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* check.c (dim_corank_check): Use gfc_get_corank to get corank.

[-- Attachment #3: pr50420-10.diff --]
[-- Type: text/x-diff, Size: 653 bytes --]

diff --git a/check.c b/check.c
index 9b8ec21..9b1e3a9 100644
--- a/check.c
+++ b/check.c
@@ -511,7 +511,6 @@ dim_check (gfc_expr *dim, int n, bool optional)
 static gfc_try
 dim_corank_check (gfc_expr *dim, gfc_expr *array)
 {
-  gfc_array_ref *ar;
   int corank;
 
   gcc_assert (array->expr_type == EXPR_VARIABLE);
@@ -519,8 +518,7 @@ dim_corank_check (gfc_expr *dim, gfc_expr *array)
   if (dim->expr_type != EXPR_CONSTANT)
     return SUCCESS;
 
-  ar = gfc_find_array_ref (array);
-  corank = ar->as->corank;
+  corank = gfc_get_corank (array);
 
   if (mpz_cmp_ui (dim->value.integer, 1) < 0
       || mpz_cmp_ui (dim->value.integer, corank) > 0)

[-- Attachment #4: pr50420-11.CL --]
[-- Type: text/plain, Size: 116 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	* array.c (gfc_find_array_ref): Remove coarray-specific handling.

[-- Attachment #5: pr50420-11.diff --]
[-- Type: text/x-diff, Size: 454 bytes --]

diff --git a/array.c b/array.c
index aa9cc0c..3e6b9d2 100644
--- a/array.c
+++ b/array.c
@@ -2296,8 +2296,7 @@ gfc_find_array_ref (gfc_expr *e)
 
   for (ref = e->ref; ref; ref = ref->next)
     if (ref->type == REF_ARRAY
-	&& (ref->u.ar.type == AR_FULL || ref->u.ar.type == AR_SECTION
-	    || (ref->u.ar.type == AR_ELEMENT && ref->u.ar.dimen == 0)))
+	&& (ref->u.ar.type == AR_FULL || ref->u.ar.type == AR_SECTION))
       break;
 
   if (ref == NULL)

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

* [Patch, fortran] [12/14] Support coarray subreferences: Fix simplify_cobound
  2011-10-07 14:39 [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Mikael Morin
@ 2011-10-07 14:39 ` Mikael Morin
  2011-10-07 14:39 ` [Patch, fortran] [10..11/14] Support coarray subreferences: Fix dim_corank_check Mikael Morin
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Mikael Morin @ 2011-10-07 14:39 UTC (permalink / raw)
  To: gfortran, GCC patches

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

simplify_cobound, when it looks for the coarray reference, in the AR_ELEMENT
case, first checks that it is the last reference in the chain. 
As it is what we are trying to avoid, this patch removes that and uses the
corank field directly.

OK?

[-- Attachment #2: pr50420-12.CL --]
[-- Type: text/plain, Size: 174 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* simplify.c (simplify_cobound): Accept non-last-in-ref-chain coarrays.
	Don't set already set array ref.

[-- Attachment #3: pr50420-12.diff --]
[-- Type: text/x-diff, Size: 517 bytes --]

diff --git a/simplify.c b/simplify.c
index 13a9c51..63689bb 100644
--- a/simplify.c
+++ b/simplify.c
@@ -3512,11 +3512,9 @@ simplify_cobound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper)
 	  switch (ref->u.ar.type)
 	    {
 	    case AR_ELEMENT:
-	      if (ref->next == NULL)
+	      if (ref->u.ar.as->corank > 0)
 		{
-		  gcc_assert (ref->u.ar.as->corank > 0
-			      && ref->u.ar.as->rank == 0);
-		  as = ref->u.ar.as;
+		  gcc_assert (as == ref->u.ar.as);
 		  goto done;
 		}
 	      as = NULL;

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

* [Patch, fortran] [13/14] Support coarray subreferences: don't force coarray lower bound to 1.
  2011-10-07 14:39 [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Mikael Morin
                   ` (3 preceding siblings ...)
  2011-10-07 14:39 ` [Patch, fortran] [05..09/14] Support coarray subreferences: Add support for array elements Mikael Morin
@ 2011-10-07 14:45 ` Mikael Morin
  2011-10-07 14:47 ` [Patch, fortran] [14/14] Support coarray subreferences: fix gfc_build_array_ref Mikael Morin
  2011-10-09 17:01 ` [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Tobias Burnus
  6 siblings, 0 replies; 9+ messages in thread
From: Mikael Morin @ 2011-10-07 14:45 UTC (permalink / raw)
  To: gfortran, GCC patches

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

gfc_build_array_type was forcing the lower bound to zero in cases where it was
unspecified (NULL). This is wrong for deferred (allocatable) coarrays at least,
as their cobound is specified at allocation time.
This patch fixes that. 
I don't think other cases beyond AS_DEFERRED need fixing, but I wouldn't mind
a confirmation. ;-)

OK?
 

[-- Attachment #2: pr50420-13.CL --]
[-- Type: text/plain, Size: 162 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* trans-types.c (gfc_build_array_type): Don't force lower bound to one
	in the deferred case.

[-- Attachment #3: pr50420-13.diff --]
[-- Type: text/x-diff, Size: 456 bytes --]

diff --git a/trans-types.c b/trans-types.c
index 43f1a19..652c009 100644
--- a/trans-types.c
+++ b/trans-types.c
@@ -1256,7 +1256,7 @@ gfc_build_array_type (tree type, gfc_array_spec * as,
 
   for (n = as->rank; n < as->rank + as->corank; n++)
     {
-      if (as->lower[n] == NULL)
+      if (as->type != AS_DEFERRED && as->lower[n] == NULL)
         lbound[n] = gfc_index_one_node;
       else
         lbound[n] = gfc_conv_array_bound (as->lower[n]);

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

* [Patch, fortran] [14/14] Support coarray subreferences: fix gfc_build_array_ref
  2011-10-07 14:39 [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Mikael Morin
                   ` (4 preceding siblings ...)
  2011-10-07 14:45 ` [Patch, fortran] [13/14] Support coarray subreferences: don't force coarray lower bound to 1 Mikael Morin
@ 2011-10-07 14:47 ` Mikael Morin
  2011-10-09 17:01 ` [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Tobias Burnus
  6 siblings, 0 replies; 9+ messages in thread
From: Mikael Morin @ 2011-10-07 14:47 UTC (permalink / raw)
  To: gfortran, GCC patches

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

This fixes a failing assertion in gfc_build_array_ref.

While array(x,:) still refers to an array, array(x,y) is a single element, 
and thus coarray(x,y) is a descriptor whose data component points to something
that is not an array.
gfc_conv_expr_descriptor, to update data pointer with subreferences, calls
gfc_get_dataptr_offset which in turn calls gfc_build_array_ref, which expects
an array.
In the non-array case, as there is no extra offset corresponding to array
element, there is nothing to do here.
This patch returns early in that case.

OK?

PS: I'm not very confident with the span stuff this function is about, so
I wouldn't mind Paul having a look.

[-- Attachment #2: pr50420-14.CL --]
[-- Type: text/plain, Size: 178 bytes --]

2011-10-06  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50420
	* trans.c (gfc_build_array_ref): If type is not an array, check that
	there is nothing to do, and do nothing.

[-- Attachment #3: pr50420-14.diff --]
[-- Type: text/x-diff, Size: 544 bytes --]

diff --git a/trans.c b/trans.c
index 764bdf4..1deff32 100644
--- a/trans.c
+++ b/trans.c
@@ -323,7 +323,14 @@ gfc_build_array_ref (tree base, tree offset, tree decl)
       return fold_convert (TYPE_MAIN_VARIANT (type), base);
     }
 
-  gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
+  /* Scalar coarray, there is nothing to do.  */
+  if (TREE_CODE (type) != ARRAY_TYPE)
+    {
+      gcc_assert (decl == NULL_TREE);
+      gcc_assert (integer_zerop (offset));
+      return base;
+    }
+
   type = TREE_TYPE (type);
 
   if (DECL_P (base))

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

* Re: [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences
  2011-10-07 14:39 [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Mikael Morin
                   ` (5 preceding siblings ...)
  2011-10-07 14:47 ` [Patch, fortran] [14/14] Support coarray subreferences: fix gfc_build_array_ref Mikael Morin
@ 2011-10-09 17:01 ` Tobias Burnus
  2011-10-18 15:51   ` Mikael Morin
  6 siblings, 1 reply; 9+ messages in thread
From: Tobias Burnus @ 2011-10-09 17:01 UTC (permalink / raw)
  To: Mikael Morin; +Cc: gfortran, GCC patches

On 07.10.2011 16:38, Mikael Morin wrote:
> The full patchset has passed the fortran testsuite successfully.
> OK for trunk?

OK for the whole patch set. Thanks for finding and fixing the issue!

Tobias

> Patches layout
>
>   01..04/14: Add support for non-full arrays in descriptor initialization code.
>
>   05..09/14: Make walk_coarray initialize the scalarizer structs properly to
>              accept expression with subreferences.
>
>   10..11/14: Fix corank checking
>
>       12/14: Accept coarray subreferences in simplify_cobound
>
>       13/14: Fix gfc_build_array_type
>
>       14/14: Fix gfc_build_array_ref

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

* Re: [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences
  2011-10-09 17:01 ` [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Tobias Burnus
@ 2011-10-18 15:51   ` Mikael Morin
  0 siblings, 0 replies; 9+ messages in thread
From: Mikael Morin @ 2011-10-18 15:51 UTC (permalink / raw)
  To: fortran; +Cc: Tobias Burnus, GCC patches

On Sunday 09 October 2011 18:25:25 Tobias Burnus wrote:
> On 07.10.2011 16:38, Mikael Morin wrote:
> > The full patchset has passed the fortran testsuite successfully.
> > OK for trunk?
> 
> OK for the whole patch set. Thanks for finding and fixing the issue!
> 
Committed as follows.
I committed 8 and 9 together because I was fearing breakage.

patch  revision
===============
1      180140
2      180141
3      180142
4      180143
5      180144
6      180145
7      180146
8,9    180147
10     180148
11     180149
12     180150
13     180151
14     180152
tests  180153

Mikael

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

end of thread, other threads:[~2011-10-18 15:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-07 14:39 [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Mikael Morin
2011-10-07 14:39 ` [Patch, fortran] [12/14] Support coarray subreferences: Fix simplify_cobound Mikael Morin
2011-10-07 14:39 ` [Patch, fortran] [10..11/14] Support coarray subreferences: Fix dim_corank_check Mikael Morin
2011-10-07 14:39 ` [Patch, fortran] [01..04/14] Support coarray subreferences: Add subreferences support in gfc_conv_expr_descriptor Mikael Morin
2011-10-07 14:39 ` [Patch, fortran] [05..09/14] Support coarray subreferences: Add support for array elements Mikael Morin
2011-10-07 14:45 ` [Patch, fortran] [13/14] Support coarray subreferences: don't force coarray lower bound to 1 Mikael Morin
2011-10-07 14:47 ` [Patch, fortran] [14/14] Support coarray subreferences: fix gfc_build_array_ref Mikael Morin
2011-10-09 17:01 ` [Patch, fortran] [00/14] PR fortran/50420 Support coarray subreferences Tobias Burnus
2011-10-18 15:51   ` Mikael Morin

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).