Comments
Patch
2011-12-06 Tobias Burnus <burnus@net-b.de>
PR fortran/51435
* expr.c (gfc_has_default_initializer): Fix handling of
DT with initialized pointer components.
2011-12-06 Tobias Burnus <burnus@net-b.de>
PR fortran/51435
* gfortran.dg/default_initialization_5.f90: New.
@@ -3735,6 +3735,8 @@ gfc_has_default_initializer (gfc_symbol *der)
if (!c->attr.pointer
&& gfc_has_default_initializer (c->ts.u.derived))
return true;
+ if (c->attr.pointer && c->initializer)
+ return true;
}
else
{
@@ -3745,6 +3747,7 @@ gfc_has_default_initializer (gfc_symbol *der)
return false;
}
+
/* Get an expression for a default initializer. */
gfc_expr *
@@ -0,0 +1,66 @@
+! { dg-do run }
+! { dg-options "-fdump-tree-original" }
+!
+! PR fortran/51435
+!
+! Contributed by darmar.xxl@gmail.com
+!
+module arr_m
+ type arr_t
+ real(8), dimension(:), allocatable :: rsk
+ end type
+ type arr_t2
+ integer :: a = 77
+ end type
+end module arr_m
+!*********************
+module list_m
+ use arr_m
+ implicit none
+
+ type(arr_t2), target :: tgt
+
+ type my_list
+ type(arr_t), pointer :: head => null()
+ end type my_list
+ type my_list2
+ type(arr_t2), pointer :: head => tgt
+ end type my_list2
+end module list_m
+!***********************
+module worker_mod
+ use list_m
+ implicit none
+
+ type data_all_t
+ type(my_list) :: my_data
+ end type data_all_t
+ type data_all_t2
+ type(my_list2) :: my_data
+ end type data_all_t2
+contains
+ subroutine do_job()
+ type(data_all_t) :: dum
+ type(data_all_t2) :: dum2
+
+ if (associated(dum%my_data%head)) then
+ call abort()
+ else
+ print *, 'OK: do_job my_data%head is NOT associated'
+ end if
+
+ if (dum2%my_data%head%a /= 77) &
+ call abort()
+ end subroutine
+end module
+!***************
+program hello
+ use worker_mod
+ implicit none
+ call do_job()
+end program
+
+! { dg-final { scan-tree-dump-times "my_data.head = 0B" 1 "original" } }
+! { dg-final { scan-tree-dump-times "my_data.head = &tgt" 1 "original" } }
+! { dg-final { cleanup-tree-dump "original" } }
+! { dg-final { cleanup-modules "arr_m list_m worker_mod" } }
This patch fixes issues with the "=> null()" initialization of pointers; the "=> tgt" initialization was working before. The check has to take into account that allocatable components do not count as default initializer, even if they are internally handled as NULL initialization. With patch: struct data_all_t dum; { struct data_all_t data_all_t.2; data_all_t.2.my_data.head = 0B; dum = data_all_t.2; } without: struct data_all_t dum; Build and regtested on x86-64-linux. OK for the trunk and for 4.6? Tobias PS: Other patches which still need to be reviewed: - http://gcc.gnu.org/ml/fortran/2011-11/msg00250.html - no -fcheck=bounds for character(LEN=:) to avoid ICE - http://gcc.gnu.org/ml/fortran/2011-11/msg00253.html - (Re)enable warning if a function result variable is not set [4.4-4.7 diagnostics regression] - http://gcc.gnu.org/ml/fortran/2011-12/msg00025.html - I/O: Allow real BOZ w/ F2008 - http://gcc.gnu.org/ml/fortran/2011-12/msg00026.html - Toon's -finit-* doc patch