From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14847 invoked by alias); 2 Jan 2011 15:58:35 -0000 Received: (qmail 14836 invoked by uid 22791); 2 Jan 2011 15:58:34 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_CP X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 02 Jan 2011 15:58:29 +0000 From: "janus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/46408] [OOP] Segfault when running gfortran.dg/class_allocate_6.f03 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: janus at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sun, 02 Jan 2011 15:58:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-01/txt/msg00064.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46408 --- Comment #4 from janus at gcc dot gnu.org 2011-01-02 15:58:13 UTC --- Reduced test case: type t end type type, extends(t) :: t2 integer, allocatable :: a end type class(t), allocatable :: x, y allocate(t2 :: x) allocate(y, source=x) end As far as I can see, the copying routine itself is alright. The problem seems to be with the default initialization of x%a. From the dump: MAIN__ () { static struct t __def_init_MAIN___t; static struct t2 __def_init_MAIN___t2 = {}; static struct __vtype_MAIN___t __vtab_MAIN___t = {._hash=6232021, ._size=0, ._extends=0B, ._def_init=&__def_init_MAIN___t, ._copy=__copy_MAIN___t}; static struct __vtype_MAIN___t2 __vtab_MAIN___t2 = {._hash=43807140, ._size=8, ._extends=&__vtab_MAIN___t, ._def_init=&__def_init_MAIN___t2, ._copy=__copy_MAIN___t2}; static struct __class_MAIN___t_a x = {}; static struct __class_MAIN___t_a y = {}; static void __copy_MAIN___t (struct t & restrict, struct t & restrict); static void __copy_MAIN___t2 (struct t2 & restrict, struct t2 & restrict); try { x._data = 0B; y._data = 0B; ! [ ... allocation of x._data ... ] (void) __builtin_memcpy ((void *) x._data, (void *) x._vptr->_def_init, () x._vptr->_size); ! [ ... allocation of y.data ... ] x._vptr->_copy (x._data, y._data); (struct __vtype_MAIN___t *) y._vptr = (struct __vtype_MAIN___t *) x._vptr; } finally { [...] } } x%a should get default-initialized to NULL via the memcpy call from x._vptr->_def_init. The memcpy itself is done alright, but apparently the _def_init variable is not properly initialized (is it?): static struct t2 __def_init_MAIN___t2 = {};