From patchwork Sun Feb 5 12:43:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Vehreschild X-Patchwork-Id: 724227 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vGVfB0P0fz9s1y for ; Sun, 5 Feb 2017 23:43:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="vJmtwg3I"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type; q=dns; s=default; b=Dw6f9hr3+OGhBwCA 14PiBZVDuXhDW5U6dJpqkjTQ12J54E4H/QOQrBB2bnrK42vEHebb61ggAVJaKnuy RWdDB0JDBvBTCmClsZgsgbctgj/EmHk2hZHlxuHOSadkjnGE6xiUOa9VF9WsM5GQ N2ApYDd1E+0box+BEobnKfN8ubI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type; s=default; bh=mqAMa4OUWcBh54gXqnzDin cTl3w=; b=vJmtwg3IqXiHviIAOBmhHiOiXEw8HqlSwhbOBG9ONaDdFEEM945Ndj /G7W99/ExBBjGNfJFFzIU/2bSiy8ekwmiMXF9PB3AT86R9/rYJ+Is4XwLhxFVTZn jUGEgBNKTsN4RGoEMwjFn1Q01Frp5hudXlQuVvZEOuD6mroEGDWN0= Received: (qmail 33359 invoked by alias); 5 Feb 2017 12:43:24 -0000 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 Received: (qmail 33144 invoked by uid 89); 5 Feb 2017 12:43:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=4.6 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_WEB, SPF_PASS autolearn=no version=3.3.2 spammy=bootstraps, bt_class, BT_CLASS, H*r:Sun X-Spam-User: qpsmtpd, 2 recipients X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.15.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 05 Feb 2017 12:43:11 +0000 Received: from vepi2 ([84.63.213.96]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0Lz3nU-1cNNcI3V2G-014A59; Sun, 05 Feb 2017 13:43:07 +0100 Date: Sun, 5 Feb 2017 13:43:05 +0100 From: Andre Vehreschild To: Paul Richard Thomas Cc: GCC-Patches-ML , GCC-Fortran-ML Subject: Re: [PATCH, Fortran, pr78958, v1] Unallocated memory access after SOURCE-ALLOCATEing unlimited polymorphic object Message-ID: <20170205134305.7793b284@vepi2> In-Reply-To: References: <20170204141156.15c9cc53@vepi2> MIME-Version: 1.0 X-UI-Out-Filterresults: notjunk:1; V01:K0:lXZ6Rmr4Dbs=:TTiuIdwjlVcA1IjbOeH+88 pDWGKDjXEopxrwRgUANMY86bOpV57E25suO0/yayPptCFn1wgiK1xK7aqTITDDWnAph9kpkXw wNggD3sPqnNb9AyRrtAZ3pfFL/WhLQjWg/TBwFSRr+C9qtfChGiMfErG3IYHqnw14SmboVl8+ s76H441gxghfBN0MvgzB8DHNOOgg3dq8kU6qXJtZmkOLiYpraNrxQqC+efRRMKO9LH1YW11bS JyKGew/I9xqAcOzQRNg2L4hmh/+QMy/6GgdIKn2eEILuGWbLpiCIonp7G95z8aMIQp02QTTjh Bv+ytxeyVqRcBa9TmwuLfI4p38h7R/gZJv0ar+/k2Ymahtpx7SBLM16Q/gy3I/t7VRRXlJzeP tgcZrGqigUtkKNrJ0tbx9ejEm6tDee9aydCudDfcBC3jsiLrjwHwLljKNxZcjsRygTa/HlFu5 kqIRyr3qCzIQ0l8tsIilhnUqDERbehzaSFpS/zHrwIHn4f9g4vnCkdGwxgZ67OKTAgfuYPW8S WWVqW+CE1klpMeTQ/UDmkPDsThtSDsFQqLAukitC2tNnrSpyrXdWV1kc4JGKxJNln8Dfje+7W 1Pxa0pucYSl7895KhH5iu6X/kLTi+W8qBjHbPdlmXZ9QoHN5hYdLtKVjSV7N8xr4fgd1H8xx/ phjV6JxImwXYlugBJ6gZsxo334EjuPjRtCU8noB3KfFhKtFjn65BxvBOk57CalWl7OTMOeT8Y krXfTYBlTgs+ctuWRcwrFr4fOB5A58bsVLEtflPjHksxh2HO0eDvaNH/dVo= Hi Paul, thanks for the review. Committed as r245192. Regards, Andre On Sat, 4 Feb 2017 17:07:13 +0000 Paul Richard Thomas wrote: > Hi Andre, > > This looks to be OK for trunk. > > Thanks for the patch. > > Paul > > On 4 February 2017 at 13:11, Andre Vehreschild wrote: > > Hi all, > > > > attached patch takes the _len-component of unlimited polymorphic objects > > into account, when source-ALLOCATEing an unlimited polymorphic object. The > > testcase for this gcc/testsuite/gfortran.dg/alloc_comp_class_5.f03 with > > valgrind/sanitizer. I therefore added no additional testcase. > > > > Bootstraps and regtests ok on x86_64-linux/f25 and as reported in the PR on > > 32bit-hpux. Ok for trunk (when?)? > > > > Regards, > > Andre > > -- > > Andre Vehreschild * Email: vehre ad gmx dot de > > > Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (Revision 245191) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,5 +1,11 @@ 2017-02-05 Andre Vehreschild + PR fortran/78958 + * trans-stmt.c (gfc_trans_allocate): Add the multiplying the _len + component of unlimited polymorphic objects when source-allocating. + +2017-02-05 Andre Vehreschild + PR fortran/79230 * trans-array.c (structure_alloc_comps): Ignore pointer components when freeing structures. Index: gcc/fortran/trans-stmt.c =================================================================== --- gcc/fortran/trans-stmt.c (Revision 245191) +++ gcc/fortran/trans-stmt.c (Arbeitskopie) @@ -6009,14 +6009,21 @@ needs to be provided, which is done most of the time by the pre-evaluation step. */ nelems = NULL_TREE; - if (expr3_len && code->expr3->ts.type == BT_CHARACTER) - /* When al is an array, then the element size for each element - in the array is needed, which is the product of the len and - esize for char arrays. */ - tmp = fold_build2_loc (input_location, MULT_EXPR, - TREE_TYPE (expr3_esize), expr3_esize, - fold_convert (TREE_TYPE (expr3_esize), - expr3_len)); + if (expr3_len && (code->expr3->ts.type == BT_CHARACTER + || code->expr3->ts.type == BT_CLASS)) + { + /* When al is an array, then the element size for each element + in the array is needed, which is the product of the len and + esize for char arrays. For unlimited polymorphics len can be + zero, therefore take the maximum of len and one. */ + tmp = fold_build2_loc (input_location, MAX_EXPR, + TREE_TYPE (expr3_len), + expr3_len, fold_convert (TREE_TYPE (expr3_len), + integer_one_node)); + tmp = fold_build2_loc (input_location, MULT_EXPR, + TREE_TYPE (expr3_esize), expr3_esize, + fold_convert (TREE_TYPE (expr3_esize), tmp)); + } else tmp = expr3_esize; if (!gfc_array_allocate (&se, expr, stat, errmsg, errlen,