]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/40440 (Automatic deallocation component of DT function return value)
authorPaul Thomas <pault@gcc.gnu.org>
Sun, 11 Oct 2009 12:20:09 +0000 (12:20 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sun, 11 Oct 2009 12:20:09 +0000 (12:20 +0000)
2009-10-11  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/40440
* decl.c (hash_value): New function.
(gfc_match_derived_decl): Call it.

2009-10-11  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/40440
* gfortran.dg/class_4a.f03: New test with class_4b,c and d.f03.
* gfortran.dg/class_4b.f03: As above.
* gfortran.dg/class_4c.f03: As above.
* gfortran.dg/class_4d.f03: As above.

From-SVN: r152640

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/class_4a.f03 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/class_4b.f03 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/class_4c.f03 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/class_4d.f03 [new file with mode: 0644]

index f6426c716d488da269af7518ee369db4cc6b33b0..9058926d96dd23f2e596eb3217bdbcbe250989c2 100644 (file)
@@ -1,3 +1,9 @@
+2009-10-11  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/40440
+       * decl.c (hash_value): New function.
+       (gfc_match_derived_decl): Call it.
+
 2009-10-09  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/41585
index 1856d89927a3c94832e64f6770447de6ac1ee8de..69449a32ce989ee6b87800c92f434ee13adbaa01 100644 (file)
@@ -6747,8 +6747,44 @@ gfc_get_type_attr_spec (symbol_attribute *attr, char *name)
 }
 
 
-/* Counter for assigning a unique vindex number to each derived type.  */
-static int vindex_counter = 0;
+/* Assign a hash value for a derived type. The algorithm is that of
+   SDBM. The hashed string is '[module_name #] derived_name'.  */
+static unsigned int
+hash_value (gfc_symbol *sym)
+{
+  unsigned int hash = 0;
+  const char *c;
+  int i, len;
+
+  /* Hash of the module or procedure name.  */
+  if (sym->module != NULL)
+    c = sym->module;
+  else if (sym->ns && sym->ns->proc_name
+            && sym->ns->proc_name->attr.flavor == FL_MODULE)
+    c = sym->ns->proc_name->name;
+  else
+    c = NULL;
+
+  if (c)
+    { 
+      len = strlen (c);
+      for (i = 0; i < len; i++, c++)
+       hash =  (hash << 6) + (hash << 16) - hash + (*c);
+
+      /* Disambiguate between 'a' in 'aa' and 'aa' in 'a'.  */ 
+      hash =  (hash << 6) + (hash << 16) - hash + '#';
+    }
+
+  /* Hash of the derived type name.  */
+  len = strlen (sym->name);
+  c = sym->name;
+  for (i = 0; i < len; i++, c++)
+    hash = (hash << 6) + (hash << 16) - hash + (*c);
+
+  /* Return the hash but take the modulus for the sake of module read,
+     even though this slightly increases the chance of collision.  */
+  return (hash % 100000000);
+}
 
 
 /* Match the beginning of a derived type declaration.  If a type name
@@ -6872,8 +6908,8 @@ gfc_match_derived_decl (void)
     }
 
   if (!sym->vindex)
-    /* Set the vindex for this type and increment the counter.  */
-    sym->vindex = ++vindex_counter;
+    /* Set the vindex for this type.  */
+    sym->vindex = hash_value (sym);
 
   /* Take over the ABSTRACT attribute.  */
   sym->attr.abstract = attr.abstract;
index 45c792032957fcd49a487ec39b4450443bf59969..ce4b8e6ea6d91934da0cfdb327772fb9f069382d 100644 (file)
@@ -1,3 +1,11 @@
+2009-10-11  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/40440
+       * gfortran.dg/class_4a.f03: New test with class_4b,c and d.f03.
+       * gfortran.dg/class_4b.f03: As above.
+       * gfortran.dg/class_4c.f03: As above.
+       * gfortran.dg/class_4d.f03: As above.
+
 2009-10-11  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/41555
diff --git a/gcc/testsuite/gfortran.dg/class_4a.f03 b/gcc/testsuite/gfortran.dg/class_4a.f03
new file mode 100644 (file)
index 0000000..3cf0b7a
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do compile }
+!
+! Test the fix for PR41583, in which the different source files
+! would generate the same 'vindex' for different class declared
+! types.
+!
+! The test comprises class_4a, class_4b class_4c and class_4d.f03
+
+! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+!
+module m
+  type t
+  end type t
+end module m
diff --git a/gcc/testsuite/gfortran.dg/class_4b.f03 b/gcc/testsuite/gfortran.dg/class_4b.f03
new file mode 100644 (file)
index 0000000..4658b8c
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do compile }
+!
+! Test the fix for PR41583, in which the different source files
+! would generate the same 'vindex' for different class declared
+! types.
+!
+! The test comprises class_4a, class_4b class_4c and class_4d.f03
+!
+! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+!
+module m2
+  use m
+  type, extends(t) :: t2
+  end type t2
+end module m2
diff --git a/gcc/testsuite/gfortran.dg/class_4c.f03 b/gcc/testsuite/gfortran.dg/class_4c.f03
new file mode 100644 (file)
index 0000000..7909c0e
--- /dev/null
@@ -0,0 +1,28 @@
+! { dg-do run }
+!
+! Test the fix for PR41583, in which the different source files
+! would generate the same 'vindex' for different class declared
+! types.
+!
+! The test comprises class_4a, class_4b class_4c and class_4d.f03
+!
+! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+!
+  use m
+  use m2
+  type,extends(t) :: t3
+  end type t3
+
+  integer :: i
+  class(t), allocatable :: a
+  allocate(t3 :: a)
+  select type(a)
+    type is(t)
+      i = 1
+    type is(t2)
+      i = 2
+    type is(t3)
+      i = 3
+  end select
+  print *, i
+end
diff --git a/gcc/testsuite/gfortran.dg/class_4d.f03 b/gcc/testsuite/gfortran.dg/class_4d.f03
new file mode 100644 (file)
index 0000000..7a962aa
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do compile }
+!
+! Test the fix for PR41583, in which the different source files
+! would generate the same 'vindex' for different class declared
+! types.
+!
+! This file does nothing other than clean up the modules.
+!
+! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+!
+module m
+  type t
+  end type t
+end module m
+! { dg-final { cleanup-modules "m m2" } }