public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR 43331 - Fix Cray pointer (middle-end) type declaration
@ 2010-03-11 20:15 Tobias Burnus
  2010-03-11 21:14 ` Tobias Burnus
  2010-03-17  7:38 ` *PING* " Tobias Burnus
  0 siblings, 2 replies; 5+ messages in thread
From: Tobias Burnus @ 2010-03-11 20:15 UTC (permalink / raw)
  To: gcc patches, gfortran

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

For some reason, assumed-size Cray pointees had an upper bound of one,
which causes problems with middle-end optimizations (see PR).

This patch changes it have an unknown upper bound. The patch is straight
forward, except for the change in trans-decl.c's
gfc_trans_deferred_vars, where I simply ignore Cray pointees. I am not
sure whether this is correct, but it seems to work and I cannot imagine
initializations to Cray pointees for which one would need to pass the
symbol to gfc_trans_g77_array. If one does the call, it ICEs due to a
NULL pointer.

Build and regtested on x86-64-linux. OK for the trunk?

Tobias

PS: I have not added a test case as - unpatched - the
cray_pointers_2.f90 test would fail as soon as the middle-end change is in.

[-- Attachment #2: crayptr.diff --]
[-- Type: text/x-patch, Size: 6243 bytes --]

2010-03-11  Tobias Burnus  <burnus@net-b.de>

	PR fortran/43331
	* trans-array.c (gfc_conv_array_index_offset,gfc_conv_array_ref,
	gfc_conv_ss_startstride): Remove no-longer-needed cp_was_assumed
	check.
	* decl.c (gfc_match_derived_decl): Don't mark assumed-size Cray
	pointees as having explizit size.
	* expr.c (gfc_check_assign): Remove now unreachable Cray pointee
	check.
	* trans-types.c (gfc_is_nodesc_array): Add cp_was_assumed to assert.
	* resolve.c (resolve_symbol): Handle cp_was_assumed.
	* trans-decl.c (gfc_trans_deferred_vars): Ditto.

2010-03-11  Tobias Burnus  <burnus@net-b.de>

	PR fortran/43331
	* gfortran.dg/cray_pointers_1.f90: Update dg-error message.

Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(revision 157384)
+++ gcc/fortran/trans-array.c	(working copy)
@@ -2404,8 +2404,8 @@ gfc_conv_array_index_offset (gfc_se * se
 
 	  index = gfc_trans_array_bound_check (se, info->descriptor,
 			index, dim, &ar->where,
-			(ar->as->type != AS_ASSUMED_SIZE
-			 && !ar->as->cp_was_assumed) || dim < ar->dimen - 1);
+			ar->as->type != AS_ASSUMED_SIZE
+			|| dim < ar->dimen - 1);
 	  break;
 
 	case DIMEN_VECTOR:
@@ -2431,8 +2431,8 @@ gfc_conv_array_index_offset (gfc_se * se
 	  /* Do any bounds checking on the final info->descriptor index.  */
 	  index = gfc_trans_array_bound_check (se, info->descriptor,
 			index, dim, &ar->where,
-			(ar->as->type != AS_ASSUMED_SIZE
-			 && !ar->as->cp_was_assumed) || dim < ar->dimen - 1);
+			ar->as->type != AS_ASSUMED_SIZE
+			|| dim < ar->dimen - 1);
 	  break;
 
 	case DIMEN_RANGE:
@@ -2581,8 +2581,7 @@ gfc_conv_array_ref (gfc_se * se, gfc_arr
 
 	  /* Upper bound, but not for the last dimension of assumed-size
 	     arrays.  */
-	  if (n < ar->dimen - 1
-	      || (ar->as->type != AS_ASSUMED_SIZE && !ar->as->cp_was_assumed))
+	  if (n < ar->dimen - 1 || ar->as->type != AS_ASSUMED_SIZE)
 	    {
 	      tmp = gfc_conv_array_ubound (se->expr, n);
 	      if (sym->attr.temporary)
@@ -3207,8 +3206,7 @@ gfc_conv_ss_startstride (gfc_loopinfo *
 		continue;
 
 	      if (dim == info->ref->u.ar.dimen - 1
-		  && (info->ref->u.ar.as->type == AS_ASSUMED_SIZE
-		      || info->ref->u.ar.as->cp_was_assumed))
+		  && info->ref->u.ar.as->type == AS_ASSUMED_SIZE)
 		check_upper = false;
 	      else
 		check_upper = true;
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 157384)
+++ gcc/fortran/decl.c	(working copy)
@@ -6969,22 +6969,14 @@ gfc_match_derived_decl (void)
 
 
 /* Cray Pointees can be declared as: 
-      pointer (ipt, a (n,m,...,*)) 
-   By default, this is treated as an AS_ASSUMED_SIZE array.  We'll
-   cheat and set a constant bound of 1 for the last dimension, if this
-   is the case. Since there is no bounds-checking for Cray Pointees,
-   this will be okay.  */
+      pointer (ipt, a (n,m,...,*))  */
 
 match
 gfc_mod_pointee_as (gfc_array_spec *as)
 {
   as->cray_pointee = true; /* This will be useful to know later.  */
   if (as->type == AS_ASSUMED_SIZE)
-    {
-      as->type = AS_EXPLICIT;
-      as->upper[as->rank - 1] = gfc_int_expr (1);
-      as->cp_was_assumed = true;
-    }
+    as->cp_was_assumed = true;
   else if (as->type == AS_ASSUMED_SHAPE)
     {
       gfc_error ("Cray Pointee at %C cannot be assumed shape array");
Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 157384)
+++ gcc/fortran/expr.c	(working copy)
@@ -3010,16 +3010,6 @@ gfc_check_assign (gfc_expr *lvalue, gfc_
 	}
     }
 
-   if (sym->attr.cray_pointee
-       && lvalue->ref != NULL
-       && lvalue->ref->u.ar.type == AR_FULL
-       && lvalue->ref->u.ar.as->cp_was_assumed)
-     {
-       gfc_error ("Vector assignment to assumed-size Cray Pointee at %L "
-		  "is illegal", &lvalue->where);
-       return FAILURE;
-     }
-
   /* This is possibly a typo: x = f() instead of x => f().  */
   if (gfc_option.warn_surprising 
       && rvalue->expr_type == EXPR_FUNCTION
Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c	(revision 157384)
+++ gcc/fortran/trans-types.c	(working copy)
@@ -1193,7 +1193,7 @@ gfc_is_nodesc_array (gfc_symbol * sym)
   if (sym->attr.result || sym->attr.function)
     return 0;
 
-  gcc_assert (sym->as->type == AS_EXPLICIT);
+  gcc_assert (sym->as->type == AS_EXPLICIT || sym->as->cp_was_assumed);
 
   return 1;
 }
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 157384)
+++ gcc/fortran/resolve.c	(working copy)
@@ -10995,7 +10995,7 @@ resolve_symbol (gfc_symbol *sym)
      arguments.  */
 
   if (sym->as != NULL
-      && (sym->as->type == AS_ASSUMED_SIZE
+      && ((sym->as->type == AS_ASSUMED_SIZE && !sym->as->cp_was_assumed)
 	  || sym->as->type == AS_ASSUMED_SHAPE)
       && sym->attr.dummy == 0)
     {
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 157384)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -3159,10 +3159,11 @@ gfc_trans_deferred_vars (gfc_symbol * pr
 
 	    case AS_ASSUMED_SIZE:
 	      /* Must be a dummy parameter.  */
-	      gcc_assert (sym->attr.dummy);
+	      gcc_assert (sym->attr.dummy || sym->as->cp_was_assumed);
 
 	      /* We should always pass assumed size arrays the g77 way.  */
-	      fnbody = gfc_trans_g77_array (sym, fnbody);
+	      if (sym->attr.dummy)
+		fnbody = gfc_trans_g77_array (sym, fnbody);
               break;
 
 	    case AS_ASSUMED_SHAPE:
Index: gcc/testsuite/gfortran.dg/cray_pointers_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/cray_pointers_1.f90	(revision 157384)
+++ gcc/testsuite/gfortran.dg/cray_pointers_1.f90	(working copy)
@@ -21,7 +21,7 @@ subroutine err3
   real array(*)
   pointer (ipt, array)
   ipt = loc (target)
-  array = 0    ! { dg-error "Vector assignment" }
+  array = 0    ! { dg-error "upper bound in the last dimension" }
 end subroutine err3
 
 subroutine err4

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

* Re: [Patch, Fortran] PR 43331 - Fix Cray pointer (middle-end) type  declaration
  2010-03-11 20:15 [Patch, Fortran] PR 43331 - Fix Cray pointer (middle-end) type declaration Tobias Burnus
@ 2010-03-11 21:14 ` Tobias Burnus
  2010-03-12 11:00   ` Richard Guenther
  2010-03-17  7:38 ` *PING* " Tobias Burnus
  1 sibling, 1 reply; 5+ messages in thread
From: Tobias Burnus @ 2010-03-11 21:14 UTC (permalink / raw)
  To: gcc patches, gfortran

Tobias Burnus wrote:
> This patch changes it have an unknown upper bound. The patch is straight
> forward, except for the change in trans-decl.c's
> gfc_trans_deferred_vars
>   

I just saw that the patch has a problem, which one sees in the dump; it
changes from
   integer(kind=4) ipte1[1] [value-expr: *(integer(kind=4)[1] *) iptr4];
to
   integer(kind=4)[0:] * restrict ipte1 [value-expr:
(integer(kind=4)[0:] * restrict) iptr4];

The [1] vs. [0:] is the reason for this patch; I think that also the
change from "integer" to "integer *" is correct. However, my according
to (limited) understanding of Cray pointer, the "restrict" qualifier is
wrong.

Tobias

PS: Patch
--- trans-decl.c    (Revision 157391)
+++ trans-decl.c
@@ -598,6 +598,7 @@ gfc_finish_var_decl (tree decl, gfc_symb
 
   if (!sym->attr.target
       && !sym->attr.pointer
+      && !sym->attr.cray_pointee
       && !sym->attr.proc_pointer)
     DECL_RESTRICTED_P (decl) = 1;
 }
--- trans-types.c    (Revision 157391)
+++ trans-types.c
@@ -1775,7 +1775,7 @@ gfc_sym_type (gfc_symbol * sym)
     byref = 0;
 
   restricted = !sym->attr.target && !sym->attr.pointer
-               && !sym->attr.proc_pointer;
+               && !sym->attr.proc_pointer && !sym->attr.cray_pointee;
   if (sym->attr.dimension)
     {
       if (gfc_is_nodesc_array (sym))

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

* Re: [Patch, Fortran] PR 43331 - Fix Cray pointer (middle-end) type   declaration
  2010-03-11 21:14 ` Tobias Burnus
@ 2010-03-12 11:00   ` Richard Guenther
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Guenther @ 2010-03-12 11:00 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc patches, gfortran

On Thu, Mar 11, 2010 at 9:31 PM, Tobias Burnus <burnus@net-b.de> wrote:
> Tobias Burnus wrote:
>> This patch changes it have an unknown upper bound. The patch is straight
>> forward, except for the change in trans-decl.c's
>> gfc_trans_deferred_vars
>>
>
> I just saw that the patch has a problem, which one sees in the dump; it
> changes from
>   integer(kind=4) ipte1[1] [value-expr: *(integer(kind=4)[1] *) iptr4];
> to
>   integer(kind=4)[0:] * restrict ipte1 [value-expr:
> (integer(kind=4)[0:] * restrict) iptr4];
>
> The [1] vs. [0:] is the reason for this patch; I think that also the
> change from "integer" to "integer *" is correct. However, my according
> to (limited) understanding of Cray pointer, the "restrict" qualifier is
> wrong.

Yep.  Without the restrict qualifier it looks sensible to me.
Note that you changed ipte1 from being an array to being
a pointer - no idea if that causes problems for the frontend
when creating accesses via ipte1 or if it magically can cope
with that change.  But it's certainly way more straight-forward
to have a pointer represented as a pointer ;)

Btw, we don't necessarily need to make this change for 4.5.

Thanks,
Richard.

> Tobias
>
> PS: Patch
> --- trans-decl.c    (Revision 157391)
> +++ trans-decl.c
> @@ -598,6 +598,7 @@ gfc_finish_var_decl (tree decl, gfc_symb
>
>   if (!sym->attr.target
>       && !sym->attr.pointer
> +      && !sym->attr.cray_pointee
>       && !sym->attr.proc_pointer)
>     DECL_RESTRICTED_P (decl) = 1;
>  }
> --- trans-types.c    (Revision 157391)
> +++ trans-types.c
> @@ -1775,7 +1775,7 @@ gfc_sym_type (gfc_symbol * sym)
>     byref = 0;
>
>   restricted = !sym->attr.target && !sym->attr.pointer
> -               && !sym->attr.proc_pointer;
> +               && !sym->attr.proc_pointer && !sym->attr.cray_pointee;
>   if (sym->attr.dimension)
>     {
>       if (gfc_is_nodesc_array (sym))
>
>

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

* *PING* Re: [Patch, Fortran] PR 43331 - Fix Cray pointer (middle-end)  type declaration
  2010-03-11 20:15 [Patch, Fortran] PR 43331 - Fix Cray pointer (middle-end) type declaration Tobias Burnus
  2010-03-11 21:14 ` Tobias Burnus
@ 2010-03-17  7:38 ` Tobias Burnus
  2010-03-17  8:01   ` Paul Richard Thomas
  1 sibling, 1 reply; 5+ messages in thread
From: Tobias Burnus @ 2010-03-17  7:38 UTC (permalink / raw)
  To: gcc patches, gfortran

*PING*

I am pinging for the combination of the following two patches:
  http://gcc.gnu.org/ml/fortran/2010-03/msg00061.html
  http://gcc.gnu.org/ml/fortran/2010-03/msg00062.html

Asher was so kind to run their programs with those patches: "the patch
is an improvement, since it removes some unneeded complexity: I never
liked having that artificial constant bound!  I tested the changes on a
few codes, and it seems fine."

OK for the trunk?

Tobias

On 11 March 2010 20:46, Tobias Burnus wrote:
> For some reason, assumed-size Cray pointees had an upper bound of one,
> which causes problems with middle-end optimizations (see PR).
>
> This patch changes it have an unknown upper bound. The patch is straight
> forward, except for the change in trans-decl.c's
> gfc_trans_deferred_vars, where I simply ignore Cray pointees. I am not
> sure whether this is correct, but it seems to work and I cannot imagine
> initializations to Cray pointees for which one would need to pass the
> symbol to gfc_trans_g77_array. If one does the call, it ICEs due to a
> NULL pointer.
>
> Build and regtested on x86-64-linux. OK for the trunk?
>
> Tobias
>
> PS: I have not added a test case as - unpatched - the
> cray_pointers_2.f90 test would fail as soon as the middle-end change is in.
>   

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

* Re: *PING* Re: [Patch, Fortran] PR 43331 - Fix Cray pointer   (middle-end) type declaration
  2010-03-17  7:38 ` *PING* " Tobias Burnus
@ 2010-03-17  8:01   ` Paul Richard Thomas
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Richard Thomas @ 2010-03-17  8:01 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc patches, gfortran

Tobias,

> Asher was so kind to run their programs with those patches: "the patch
> is an improvement, since it removes some unneeded complexity: I never
> liked having that artificial constant bound!  I tested the changes on a
> few codes, and it seems fine."
>
> OK for the trunk?

The patches are OK for trunk.

Thanks for taking care of it.

Paul

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

end of thread, other threads:[~2010-03-17  7:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-11 20:15 [Patch, Fortran] PR 43331 - Fix Cray pointer (middle-end) type declaration Tobias Burnus
2010-03-11 21:14 ` Tobias Burnus
2010-03-12 11:00   ` Richard Guenther
2010-03-17  7:38 ` *PING* " Tobias Burnus
2010-03-17  8:01   ` Paul Richard Thomas

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