From patchwork Fri Nov 27 12:20:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Vehreschild X-Patchwork-Id: 549416 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 39E931402D4 for ; Fri, 27 Nov 2015 23:20:45 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Wj+KfkMg; 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:subject:message-id:in-reply-to:references:mime-version :content-type; q=dns; s=default; b=Y3Z9mvZ52IznwFk1ZEW4hgMWFd2rs W/kRACahJILj0ucDdBn029QvS2wcVSFcPfpqHjwlnpdW1jFzPyjbhmeBVLoRDLUm ahs0JvlWPiF0TosC6d3M7daGhMwNKhrRDxbHBjZyy+mnW98mVwdZkRFEMikc8wBY +ayfgEX7Sxch5o= 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:subject:message-id:in-reply-to:references:mime-version :content-type; s=default; bh=ZozOcy4uwgDZI1yuO9XvWDH72iw=; b=Wj+ KfkMgZf7aeKbibCmooLmtyiN9+67SHkLQrVX2KNrItjgU8QEmbB47Xer0JOK2mwc V/g6KKMiCK0nUKhz+EFajQRhOJPZkBqg+pF6k1vYUwdp3p1Q3tEHJCOGMjWydwxR T2vnstAPdQkTeHBp9lQqxmQKhNQ0mvyd+eaetox4= Received: (qmail 53721 invoked by alias); 27 Nov 2015 12:20:30 -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 53700 invoked by uid 89); 27 Nov 2015 12:20:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.17.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 27 Nov 2015 12:20:27 +0000 Received: from vepi2 ([92.213.0.123]) by mail.gmx.com (mrgmx101) with ESMTPSA (Nemesis) id 0MYKGj-1ZpLk62wIz-00VB6N; Fri, 27 Nov 2015 13:20:23 +0100 Date: Fri, 27 Nov 2015 13:20:22 +0100 From: Andre Vehreschild To: GCC-Patches-ML , GCC-Fortran-ML Subject: Re: [Fortran, patch, pr68218, backport to 5 and 4.9, v1] ALLOCATE with size given by a module function Message-ID: <20151127132022.137034e4@vepi2> In-Reply-To: <20151108184850.6fe0ad54@vepi2> References: <20151105152920.65f52c89@vepi2> <20151108184850.6fe0ad54@vepi2> MIME-Version: 1.0 X-UI-Out-Filterresults: notjunk:1; V01:K0:9AfMGopfiw0=:f+7kwmKgNSYx/B/hbTlXaw rE5o4elnYJJgzTWKDNkZDm7HRKrFrw1+migyJ/3hA8nry/j1t4A354Z6+8Le6tqE/J9fcO3XC Wvp7edoyPpkHIKmHbfXEFl4Q3g+WX761ZeBla9Od8kQ1fUJ9gW6noOgHv9Y34Pi6h7aCmxfGw fddq7MlSf2CNG34MOq+9rMhxuMkZJ9mt/HZMLO21e/sUsKVHu0rzBd3fxn8jgWJzrhjpZpUuU DresBW1xOoTdY3aIUfcpxzTVqIvtXbz5Rib70Xe+9P6OUFRP4YgQ1Ew37wKPRo5TpYGQa2jnW a1swsWOhaOjCU37pKIj0Zr+Qj2lyr39+zr/LgkSl5DoSNWz+6fuj5FiSTp9sagaFMz1/uXt8r ito7dW8R1wORH1WeMG8hTJyP6P0Obga2oY7BYvjHLDZItK7ejaQkrrOtw/9VRrjxMftTXqjNj 5uCn878TY7kwaLGQj3fwBfzR/PvDjzHc8ZwY/Ya0TLdWnj5ZV0y5o1u9YvKblQzxCzNZsXzoi 3aOarMpsVjyDa21v0lJJ8o7hcldGIS8npsWLkPfSLMGf2vKllcUjwKsji28tf0zVyVTw6XfLi ycc1+kHGT0H5u1v8x2m6vDiG98uKO3aReyj6zKthCFclg4MhsKLGnZlZBTFrcwTQwGmfcftgh ZxYV5dLdvMqpvs5vAzqlC4nDiI5u9Xa9L4RptdO/GdzwnrkLQhJ2f39+GQ4x/GPAvfCSXiven 94St/6U6CxwbjbNLI/ZDrdVZe/b+KuSFXwYjbYboVD1TIVre1QD3CNDK8rg= Hi all, I have backported the patch for 68218 (multiple calls of the same function, where only one call is expected and reasonable) to gcc-5-branch and gcc-4_9-branch. Bootstrapped and regtested on x86_64-linux-gnu/f21. Ok for gcc-5-branch? Ok for gcc-4_9-branch? The Changelog is identical for both patches. The patches are mostly, too, just a slight shift. Regards, Andre On Sun, 8 Nov 2015 18:48:50 +0100 Andre Vehreschild wrote: > Hi Paul, > > thanks for the review. Comitted as r229956. > > In 5 and 4.9 the same issue exists. Currently checking whether the same > patch helps. > > Regards, > Andre > > On Sat, 7 Nov 2015 14:58:35 +0100 > Paul Richard Thomas wrote: > > > Dear Andre, > > > > OK for trunk. > > > > I understand that you have investigated the issue(s) reported to you > > by Dominique and can find no sign of them. > > > > Thanks > > > > Paul > > > > On 5 November 2015 at 15:29, Andre Vehreschild wrote: > > > Hi all, > > > > > > attached is a rather trivial patch to prevent multiple evaluations of a > > > function in: > > > > > > allocate( array(func()) ) > > > > > > The patch tests whether the upper bound of the array is a function > > > and calls gfc_evaluate_now(). > > > > > > Bootstrapped and regtested for x86_64-linux-gnu/f21. > > > > > > Ok for trunk? > > > > > > Regards, > > > Andre > > > -- > > > Andre Vehreschild * Email: vehre ad gmx dot de > > > > > > > > diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 9c175b1..3c2c640 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -5030,6 +5030,8 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset, gcc_assert (ubound); gfc_conv_expr_type (&se, ubound, gfc_array_index_type); gfc_add_block_to_block (pblock, &se.pre); + if (ubound->expr_type == EXPR_FUNCTION) + se.expr = gfc_evaluate_now (se.expr, pblock); gfc_conv_descriptor_ubound_set (descriptor_block, descriptor, gfc_rank_cst[n], se.expr); diff --git a/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90 b/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90 new file mode 100644 index 0000000..686b612 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90 @@ -0,0 +1,29 @@ +! { dg-do run } +! { dg-options "-fdump-tree-original" } + +MODULE mo_test + + integer :: n = 0 +CONTAINS + + FUNCTION nquery() + INTEGER :: nquery + WRITE (0,*) "hello!" + n = n + 1 + nquery = n + END FUNCTION nquery + +END MODULE mo_test + + +! ---------------------------------------------------------------------- +! MAIN PROGRAM +! ---------------------------------------------------------------------- +PROGRAM example + USE mo_test + INTEGER, ALLOCATABLE :: query_buf(:) + ALLOCATE(query_buf(nquery())) + if (n /= 1 .or. size(query_buf) /= n) call abort() +END PROGRAM example + +! { dg-final { scan-tree-dump-times "nquery" 5 "original" } }