From patchwork Tue Dec 6 14:19:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 129696 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 957D31007D8 for ; Wed, 7 Dec 2011 01:20:12 +1100 (EST) Received: (qmail 32522 invoked by alias); 6 Dec 2011 14:20:00 -0000 Received: (qmail 32504 invoked by uid 22791); 6 Dec 2011 14:19:59 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 06 Dec 2011 14:19:44 +0000 Received: from [192.168.178.22] (port-92-204-55-232.dynamic.qsc.de [92.204.55.232]) by mx01.qsc.de (Postfix) with ESMTP id DD6DA3CB08; Tue, 6 Dec 2011 15:19:41 +0100 (CET) Message-ID: <4EDE247C.2080103@net-b.de> Date: Tue, 06 Dec 2011 15:19:40 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] [4.6/4.7] PR 51435 - fix default initialization of pointers Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 2011-12-06 Tobias Burnus PR fortran/51435 * expr.c (gfc_has_default_initializer): Fix handling of DT with initialized pointer components. 2011-12-06 Tobias Burnus 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" } }