From patchwork Sun Oct 24 19:08:26 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 69045 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 9009BB6EF0 for ; Mon, 25 Oct 2010 06:08:41 +1100 (EST) Received: (qmail 28060 invoked by alias); 24 Oct 2010 19:08:36 -0000 Received: (qmail 28039 invoked by uid 22791); 24 Oct 2010 19:08:34 -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 mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 24 Oct 2010 19:08:29 +0000 Received: from [192.168.178.22] (port-92-204-92-55.dynamic.qsc.de [92.204.92.55]) by mx02.qsc.de (Postfix) with ESMTP id 025851E8D0; Sun, 24 Oct 2010 21:08:26 +0200 (CEST) Message-ID: <4CC4842A.8010201@net-b.de> Date: Sun, 24 Oct 2010 21:08:26 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.11) Gecko/20101013 SUSE/3.1.5 Thunderbird/3.1.5 MIME-Version: 1.0 To: Janus Weil CC: gfortran , gcc-patches Subject: Re: [Patch, Fortran] PR 42647: Missed initialization/dealloc of allocatable scalar DT with allocatable component References: <4CB4C678.5050008@net-b.de> <4CB5AE74.4080602@net-b.de> <4CC418AD.9070708@net-b.de> In-Reply-To: <4CC418AD.9070708@net-b.de> 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 Am 24.10.2010 13:29, schrieb Tobias Burnus: > Janus Weil wrote: >> In the meantime: Any further comments on this patch? > > It does not solve the related issues of PR 43018 and PR 45451. > > Regarding the former: For the following program, valgrind shows: > Invalid read of size 8 > at 0x40087A: MAIN__ (alloc_comp_scalar_1.f90:8) > for the line "a1 = a2". > > The dump looks quite unspectacular. Does anyone see the problem? Well, one couldn't easily see it - it was hidden in the "myalloc" dump. If one looks at the optimized dump, one sees: D.1504 = (void * restrict) __builtin_malloc (4); D.1506 = (void * restrict) __builtin_malloc (8); __builtin_memcpy (a1.entry, a2.entry, 8); The problem is that "entry" is a pointer to an integer(4). The first malloc correctly allocates 4 bytes to store the integer - but in the assignment, not the size of the target is used (4 bytes) but the size of the pointer (8 bytes on x86-64-linux) - thus, the program works with -m32 ... The issue is seemingly in trans-array.c's duplicate_allocatable. The following works for me - I will create a proper, regtested patch later. tmp = gfc_call_malloc (&block, type, size); Tobias PS: For those hoping for collateral fixing: That patch together with Janus' patch for PR 42647 does not help with PR 45451. --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -6072,7 +6072,7 @@ duplicate_allocatable (tree dest, tree src, tree type, int rank, null_data = gfc_finish_block (&block); gfc_init_block (&block); - size = TYPE_SIZE_UNIT (type); + size = TYPE_SIZE_UNIT (TREE_TYPE (type)); if (!no_malloc) {