This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR 43331 - Fix Cray pointer (middle-end) type declaration


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]