+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
}
/* 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);
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);
--- /dev/null
+! { 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