From patchwork Wed Oct 2 21:02:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 280175 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 40ED82C00A0 for ; Thu, 3 Oct 2013 07:03:15 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=oMU5bJacOexdmt/Qc ADyAZPIHTfyqOyF87KC/FtPXRZT9od2Xr0unw3QYU7xM2JEuTr+xgiGjgVyDkXpF 5itdH1xgOyN9ZoF2f8bDokcbJQLevRBQ9TVKNVdh14BaP2li8JPqW53fiGRI0Oq/ C7t2K+mGH5RHZLeakormac+B2g= 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 :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=LteAeG5KQ2jjojBEi5Bocb8 ijTc=; b=x00bwMvvA49OY3tJcMWMCEWKsbaqXVUjhPwrq48RehaAqRy6GxtZrz4 cV8hAPKG31aw+9FopTr0XCc2ALarmengfIVW6KFZQ40AOkuCpMaAn4OODYy9nBO7 z+Gg4JxFpIXHvh+U+5u7cXe8bi29qpKNGGmXVbDe9Gc2/+WDFLV0= Received: (qmail 14797 invoked by alias); 2 Oct 2013 21:03:01 -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 14775 invoked by uid 89); 2 Oct 2013 21:03:00 -0000 Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 02 Oct 2013 21:03:00 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_PBL, RCVD_IN_RP_RNBL, RCVD_IN_SEMBLACK, RDNS_DYNAMIC autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx02.qsc.de Received: from archimedes.net-b.de (port-92-194-74-217.dynamic.qsc.de [92.194.74.217]) by mx02.qsc.de (Postfix) with ESMTP id D30B027618; Wed, 2 Oct 2013 23:02:55 +0200 (CEST) Message-ID: <524C89FF.6060900@net-b.de> Date: Wed, 02 Oct 2013 23:02:55 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: gcc patches , gfortran Subject: Re: [Patch, Fortran, committed] PR58579 - fix allocation of string temporaries: Avoid overallocation References: <524B37F4.1070603@net-b.de> In-Reply-To: <524B37F4.1070603@net-b.de> Tobias Burnus wrote: > In gfc_conv_string_tmp, gfortran allocates temporary strings. However, > using "TYPE_SIZE (type)" didn't yield one byte as intended but 64 - > which means that gfortran allocated 64 times as much memory as needed. > > Committed (Rev. ) after building and regtesting on x86-64-gnu-linux. I > didn't see a simple way to generate a test case - but the dump of the > PR's test case looks fine both for kind=1 and kind=4 strings. It turned out - see PR58593 - that one sometimes doesn't have an array type but a simple single-character type. Fixed by the attached patch. Committed as Rev. 203135 after build+regtesting on x86-64-gnu-linux. Tobias Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (Revision 203134) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,9 @@ +2013-10-02 Tobias Burnus + + PR fortran/58593 + * trans-expr.c (gfc_conv_string_tmp): Fix obtaining + the byte size of a single character. + 2013-10-01 Tobias Burnus PR fortran/58579 Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (Revision 203134) +++ gcc/fortran/trans-expr.c (Arbeitskopie) @@ -2357,8 +2357,9 @@ gfc_conv_string_tmp (gfc_se * se, tree type, tree var = gfc_create_var (type, "pstr"); gcc_assert (POINTER_TYPE_P (type)); tmp = TREE_TYPE (type); - gcc_assert (TREE_CODE (tmp) == ARRAY_TYPE); - tmp = TYPE_SIZE_UNIT (TREE_TYPE (tmp)); + if (TREE_CODE (tmp) == ARRAY_TYPE) + tmp = TREE_TYPE (tmp); + tmp = TYPE_SIZE_UNIT (tmp); tmp = fold_build2_loc (input_location, MULT_EXPR, size_type_node, fold_convert (size_type_node, len), fold_convert (size_type_node, tmp)); Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (Revision 203134) +++ gcc/testsuite/ChangeLog (Arbeitskopie) @@ -1,3 +1,8 @@ +2013-10-02 Tobias Burnus + + PR fortran/58593 + * gfortran.dg/char_length_19.f90: New. + 2013-10-02 Paolo Carlini PR c++/58535 Index: gcc/testsuite/gfortran.dg/char_length_19.f90 =================================================================== --- gcc/testsuite/gfortran.dg/char_length_19.f90 (Revision 0) +++ gcc/testsuite/gfortran.dg/char_length_19.f90 (Arbeitskopie) @@ -0,0 +1,44 @@ +! { dg-do compile } +! +! PR fortran/58579 +! +! Contributed by Joost VandeVondele +! +! Was ICEing before due to the patch for PR 58593 +! + subroutine test + CHARACTER(len=20) :: tmpStr + CHARACTER(len=20, kind=4) :: tmpStr4 + INTEGER :: output_unit=6 + WRITE (UNIT=output_unit,FMT="(T2,A,T61,A20)")& + "DFT| Self-interaction correction (SIC)",ADJUSTR(TRIM(tmpstr)) + WRITE (UNIT=output_unit,FMT="(T2,A,T61,A20)")& + 4_"DFT| Self-interaction correction (SIC)",ADJUSTR(TRIM(tmpstr4)) + END + +! +! PR fortran/58593 +! Contributed by Albert Bartok +! +! The PR was overallocating memory. I placed it here to check for a +! variant of the test case above, which takes a slightly differnt code +! patch. Thus, its purpose is just to ensure that it won't ICE. +! +program test_char + + implicit none + integer :: i + + read*, i + print*, trim(test(i)) + + contains + + function test(i) + integer, intent(in) :: i + character(len=i) :: test + + test(1:1) = "A" + endfunction test + +endprogram test_char