re PR fortran/34681 (SAVEd derived type with allocatable components causes ICE)
authorPaul Thomas <pault@gcc.gnu.org>
Tue, 8 Jan 2008 15:12:34 +0000 (15:12 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Tue, 8 Jan 2008 15:12:34 +0000 (15:12 +0000)
2008-01-08  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/34681
* trans_array.c (gfc_trans_deferred_array): Do not null the
data pointer on entering scope, nor deallocate it on leaving
scope, if the symbol has the 'save' attribute.

PR fortran/34704
* trans_decl.c (gfc_finish_var_decl): Derived types with
allocatable components and an initializer must be TREE_STATIC.

2008-01-08  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/34681
PR fortran/34704
* gfortran.dg/alloc_comp_default_init_1.f90: New test.

From-SVN: r131395

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/fortran/trans-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/alloc_comp_default_init_1.f90 [new file with mode: 0644]

index 19f822f83780371b3b0141e01d9b23e04086a682..dd2492dc97e4f26af4b11375e6e620ab68549084 100644 (file)
@@ -1,3 +1,14 @@
+2008-01-08  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/34681
+       * trans_array.c (gfc_trans_deferred_array): Do not null the
+       data pointer on entering scope, nor deallocate it on leaving
+       scope, if the symbol has the 'save' attribute.
+
+       PR fortran/34704
+       * trans_decl.c (gfc_finish_var_decl): Derived types with
+       allocatable components and an initializer must be TREE_STATIC.
+
 2008-01-07  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/34672
index 2ebb36545796981827770f016cf8ba3aa40edbb6..f8d90820f9cee051492026cfad98211b1a252394 100644 (file)
@@ -5527,7 +5527,7 @@ gfc_trans_deferred_array (gfc_symbol * sym, tree body)
     }
   
   /* NULLIFY the data pointer.  */
-  if (GFC_DESCRIPTOR_TYPE_P (type))
+  if (GFC_DESCRIPTOR_TYPE_P (type) && !sym->attr.save)
     gfc_conv_descriptor_data_set (&fnblock, descriptor, null_pointer_node);
 
   gfc_add_expr_to_block (&fnblock, body);
@@ -5545,7 +5545,7 @@ gfc_trans_deferred_array (gfc_symbol * sym, tree body)
       gfc_add_expr_to_block (&fnblock, tmp);
     }
 
-  if (sym->attr.allocatable)
+  if (sym->attr.allocatable && !sym->attr.save)
     {
       tmp = gfc_trans_dealloc_allocated (sym->backend_decl);
       gfc_add_expr_to_block (&fnblock, tmp);
index f97870cf7c94324a8bfecba62ea3878882538135..79a3e8b8c316021de76ea5524cd3fc2bf8816e2e 100644 (file)
@@ -525,6 +525,9 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
      SAVE_EXPLICIT.  */
   if (!sym->attr.use_assoc
        && (sym->attr.save != SAVE_NONE || sym->attr.data
+             || (sym->ts.type == BT_DERIVED
+                   && sym->ts.derived->attr.alloc_comp
+                   && sym->value)
              || (sym->value && sym->ns->proc_name->attr.is_main_program)))
     TREE_STATIC (decl) = 1;
 
index b559fc8630bab8980559a46473181739b8a2a059..5b95e2969f5a1b2d86e430633a82cd523df762fe 100644 (file)
@@ -1,3 +1,9 @@
+2008-01-08  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/34681
+       PR fortran/34704
+       * gfortran.dg/alloc_comp_default_init_1.f90: New test.
+
 2008-01-07  Janis Johnson  <janis187@us.ibm.com>
 
        * lib/target-supports.exp (check_effective_target_powerpc_spu): New.
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_default_init_1.f90 b/gcc/testsuite/gfortran.dg/alloc_comp_default_init_1.f90
new file mode 100644 (file)
index 0000000..48947cd
--- /dev/null
@@ -0,0 +1,84 @@
+! { dg-do run }
+! Checks the fixes for PR34681 and PR34704, in which various mixtures\r
+! of default initializer and allocatable array were not being handled\r
+! correctly for derived types with allocatable components.
+!
+! Contributed by Paolo Giannozzi <p.giannozzi@fisica.uniud.it>
+!
+program boh
+  integer :: c1, c2, c3, c4, c5\r
+  !\r
+  call mah (0, c1) ! These calls deal with PR34681\r
+  call mah (1, c2)\r
+  call mah (2, c3)\r
+  !
+  if (c1 /= c2) call abort
+  if (c1 /= c3) call abort\r
+  !\r
+  call mah0 (c4) ! These calls deal with PR34704\r
+  call mah1 (c5)\r
+  !
+  if (c4 /= c5) call abort
+  !\r
+end program boh\r
+!\r
+subroutine mah (i, c)\r
+  !\r
+  integer, intent(in) :: i\r
+  integer, intent(OUT) :: c\r
+  !\r
+  type mix_type\r
+     real(8), allocatable :: a(:)\r
+     complex(8), allocatable :: b(:)\r
+  end type mix_type\r
+  type(mix_type), allocatable, save :: t(:)\r
+  integer :: j, n=1024\r
+  !\r
+  if (i==0) then\r
+     allocate (t(1))\r
+     allocate (t(1)%a(n))\r
+     allocate (t(1)%b(n))\r
+     do j=1,n\r
+        t(1)%a(j) = j\r
+        t(1)%b(j) = n-j\r
+     end do\r
+  end if\r
+  c = sum( t(1)%a(:) ) + sum( t(1)%b(:) )\r
+  if ( i==2) then\r
+     deallocate (t(1)%b)\r
+     deallocate (t(1)%a)\r
+     deallocate (t)\r
+  end if\r
+end subroutine mah
+
+subroutine mah0 (c)\r
+  !\r
+  integer, intent(OUT) :: c\r
+  type mix_type\r
+     real(8), allocatable :: a(:)\r
+     integer :: n=1023\r
+  end type mix_type\r
+  type(mix_type) :: t\r
+  !\r
+  allocate(t%a(1))\r
+  t%a=3.1415926\r
+  c = t%n\r
+  deallocate(t%a)\r
+  !\r
+end subroutine mah0\r
+!\r
+subroutine mah1 (c)\r
+  !\r
+  integer, intent(OUT) :: c\r
+  type mix_type\r
+     real(8), allocatable :: a(:)\r
+     integer :: n=1023\r
+  end type mix_type\r
+  type(mix_type), save :: t\r
+  !\r
+  allocate(t%a(1))\r
+  t%a=3.1415926\r
+  c = t%n\r
+  deallocate(t%a)\r
+  !\r
+end subroutine mah1\r