First, I am looking for someone to review my patch at http://gcc.gnu.org/ml/fortran/2012-01/msg00241.html

This patch contains two patches:

a) Marking the polymorphic _copy function as pure. First, it helps with code generation as the function is actually pure. Secondly, if one defines the derived type in a PURE function, one currently gets an error as the impure function _copy is called.

b) We need to build a different class container type for coarrays - the attached test case is an example why (missing diagnosis as the container didn't have the coarray attribute). At the same time, I fixes the hash function criterion. Since the polymorphic array patch, one some long module + type names were cropped instead of triggering the hash mechanism, increasing the chance for name collision.

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

Tobias
2012-01-30  Tobias Burnus  <bur...@net-b.de>

	PR fortran/52013
	* class.c (get_unique_hashed_string): Adapt trim length.
	(gfc_build_class_symbol) Encode also corank in the container name.

2012-01-30  Tobias Burnus  <bur...@net-b.de>

	PR fortran/52013
	* gfortran.dg/elemental_args_check_6.f90: New.

Index: gcc/fortran/class.c
===================================================================
--- gcc/fortran/class.c	(Revision 183737)
+++ gcc/fortran/class.c	(Arbeitskopie)
@@ -294,8 +294,10 @@ get_unique_hashed_string (char *string, gfc_symbol
   char tmp[2*GFC_MAX_SYMBOL_LEN+2];
   get_unique_type_string (&tmp[0], derived);
   /* If string is too long, use hash value in hex representation (allow for
-     extra decoration, cf. gfc_build_class_symbol & gfc_find_derived_vtab).  */
-  if (strlen (tmp) > GFC_MAX_SYMBOL_LEN - 11)
+     extra decoration, cf. gfc_build_class_symbol & gfc_find_derived_vtab).
+     We need space to for 15 characters "__class_" + symbol name + "_%d_%da",
+     where %d is the (co)rank which can be up to n = 15.  */
+  if (strlen (tmp) > GFC_MAX_SYMBOL_LEN - 15)
     {
       int h = gfc_hash_value (derived);
       sprintf (string, "%X", h);
@@ -360,10 +362,10 @@ gfc_build_class_symbol (gfc_typespec *ts, symbol_a
 
   /* Determine the name of the encapsulating type.  */
   get_unique_hashed_string (tname, ts->u.derived);
-  if ((*as) && (*as)->rank && attr->allocatable)
-    sprintf (name, "__class_%s_%d_a", tname, (*as)->rank);
-  else if ((*as) && (*as)->rank)
-    sprintf (name, "__class_%s_%d", tname, (*as)->rank);
+  if ((*as) && attr->allocatable)
+    sprintf (name, "__class_%s_%d_%da", tname, (*as)->rank, (*as)->corank);
+  else if ((*as))
+    sprintf (name, "__class_%s_%d_%d", tname, (*as)->rank, (*as)->corank);
   else if (attr->pointer)
     sprintf (name, "__class_%s_p", tname);
   else if (attr->allocatable)
Index: gcc/testsuite/gfortran.dg/elemental_args_check_6.f90
===================================================================
--- gcc/testsuite/gfortran.dg/elemental_args_check_6.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/elemental_args_check_6.f90	(Arbeitskopie)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+!
+! PR fortran/52013
+!
+type t
+end type t
+contains
+  elemental subroutine f(x) 
+    class(t), intent(inout) :: x ! Valid
+  end subroutine
+  elemental subroutine g(y) ! { dg-error "Coarray dummy argument 'y' at .1. to elemental procedure" }
+    class(t), intent(inout) :: y[*]
+  end subroutine
+end
2012-01-30  Tobias Burnus  <bur...@net-b.de>

	PR fortran/52029
	* class.c (gfc_find_derived_vtab): Mark _copy function as pure.

2012-01-30  Tobias Burnus  <bur...@net-b.de>

	PR fortran/52029
	* gfortran.dg/class_49.f90: New.

Index: gcc/fortran/class.c
===================================================================
--- gcc/fortran/class.c	(Revision 183737)
+++ gcc/fortran/class.c	(Arbeitskopie)
@@ -715,6 +717,7 @@ gfc_find_derived_vtab (gfc_symbol *derived)
 		  sub_ns->proc_name = copy;
 		  copy->attr.flavor = FL_PROCEDURE;
 		  copy->attr.subroutine = 1;
+		  copy->attr.pure = 1;
 		  copy->attr.if_source = IFSRC_DECL;
 		  /* This is elemental so that arrays are automatically
 		     treated correctly by the scalarizer.  */
Index: gcc/testsuite/gfortran.dg/class_49.f90
===================================================================
--- gcc/testsuite/gfortran.dg/class_49.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/class_49.f90	(Arbeitskopie)
@@ -0,0 +1,11 @@
+! { dg-do compile }
+!
+! PR fortran/52029
+!
+
+elemental subroutine foo()
+  type t
+  end type t
+  class(t), allocatable :: x
+  if (allocated(x)) i = 5
+end

Reply via email to