diff mbox

[Fortran,4.6/4.7] PR 51435 - fix default initialization of pointers

Message ID 4EDE247C.2080103@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Dec. 6, 2011, 2:19 p.m. UTC
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

Comments

Steve Kargl Dec. 6, 2011, 4:10 p.m. UTC | #1
On Tue, Dec 06, 2011 at 03:19:40PM +0100, Tobias Burnus wrote:
> 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?

OK with a proper ChangeLog entry.
Tobias Burnus Dec. 6, 2011, 4:14 p.m. UTC | #2
On 12/06/2011 05:10 PM, Steve Kargl wrote:
> OK with a proper ChangeLog entry

Thanks for the review - but what's wrong with the current changelog, cf. 
http://gcc.gnu.org/ml/fortran/2011-12/msg00030.html - I had:

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.


Tobias
Steve Kargl Dec. 6, 2011, 4:23 p.m. UTC | #3
On Tue, Dec 06, 2011 at 05:14:32PM +0100, Tobias Burnus wrote:
> On 12/06/2011 05:10 PM, Steve Kargl wrote:
> >OK with a proper ChangeLog entry
> 
> Thanks for the review - but what's wrong with the current changelog, cf. 
> http://gcc.gnu.org/ml/fortran/2011-12/msg00030.html - I had:

It belongs in the body of the email message.  I appear to
have subconsciously skipped right over the entry in the
diff.
diff mbox

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.

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 8817c2c..1c63566 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -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 *
--- /dev/null	2011-12-05 08:01:27.731544563 +0100
+++ gcc/gcc/testsuite/gfortran.dg/default_initialization_5.f90	2011-12-06 11:53:36.000000000 +0100
@@ -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" } }