From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26003 invoked by alias); 28 Jan 2012 15:59:23 -0000 Received: (qmail 25993 invoked by uid 22791); 28 Jan 2012 15:59:22 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 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; Sat, 28 Jan 2012 15:59:09 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/51972] [OOP] ALLOCATE misses memset/calloc, causing segfault Date: Sat, 28 Jan 2012 16:50:00 -0000 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: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: CC 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 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: 2012-01/txt/msg03308.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51972 Tobias Burnus changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu.org --- Comment #1 from Tobias Burnus 2012-01-28 15:58:37 UTC --- The following patch fixes the test case. However, if one comments the "STOP 'Success'" line, one sees that there is another bug (double free). The problem is that _copy does not properly do a deep copy. Expected: A deep copy of both attractor%state and attractor%integrand%quadrature. Currently: __copy_lorenz_module_Lorenz { *dst = *src; dst->integrand = src->integrand; __builtin_memcpy (dst->state.data, src->state.data, D.1953 * 4); Thus, there is no deep copy of "attractor%integrand%quadrature"; thus, both src->integrand->quadrature->_data and dst->integrand->quadrature->_data point to the same memory, causing - for the example program - a segfault at the end of the main program. --- trans-stmt.c (Revision 183664) +++ trans-stmt.c (Arbeitskopie) @@ -4953 +4953,2 @@ gfc_trans_allocate (gfc_code * code) - if (expr->ts.type == BT_DERIVED && expr->ts.u.derived->attr.alloc_comp) + if (al->expr->ts.type == BT_DERIVED + && expr->ts.u.derived->attr.alloc_comp)