From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23490 invoked by alias); 15 Apr 2015 18:03:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 23454 invoked by uid 89); 15 Apr 2015 18:03:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham 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.15.18) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 15 Apr 2015 18:03:10 +0000 Received: from localhost ([88.75.104.20]) by mail.gmx.com (mrgmx001) with ESMTPSA (Nemesis) id 0MFLhE-1YcvLZ31Lo-00EIwf; Wed, 15 Apr 2015 20:03:05 +0200 Date: Wed, 15 Apr 2015 18:03:00 -0000 From: Andre Vehreschild To: GCC-Patches-ML , GCC-Fortran-ML Subject: [Patch, Fortran, PR58586, v1] ICE with derived type with allocatable component passed by value Message-ID: <20150415200304.7101aca9@gmx.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/plpFjPhWwDc7OKxVHeIZLGQ" X-UI-Out-Filterresults: notjunk:1; X-SW-Source: 2015-04/txt/msg00776.txt.bz2 --MP_/plpFjPhWwDc7OKxVHeIZLGQ Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 817 Hi all, by accident I patched this pr. For short, when a structure constructor for a structure with an allocatable component or a function returning a type with an allocatable component is passed as actual argument to a function, then gfortran ICEs. This patch fixes, both the ICE and a segfault at runtime. I was pointed to the patch in comment #44 of pr61831 which seemingly fixes the #3 comment of pr58586, too, but causes a memory leak. I therefore like to point out, that adding the a->expr.expr_type != EXPR_STRUCTURE of Mikael's patch in pr61831 should not be added to trans-expr.c::gfc_conv_procedure_call (), when this patch for 58586 is applied. Bootstraps and regtests ok on x86_64-linux-gnu/F21. Ok, for trunk 6.0, when open again? Regards, Andre -- Andre Vehreschild * Email: vehre ad gmx dot de --MP_/plpFjPhWwDc7OKxVHeIZLGQ Content-Type: application/octet-stream; name=pr58586_1.clog Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=pr58586_1.clog Content-length: 533 Z2NjL3Rlc3RzdWl0ZS9DaGFuZ2VMb2c6CgoyMDE1LTA0LTE1ICBBbmRyZSBW ZWhyZXNjaGlsZCAgPHZlaHJlQGdteC5kZT4KCgkqIGdmb3J0cmFuLmRnL2Fs bG9jX2NvbXBfY2xhc3NfMy5mOTA6IE5ldyB0ZXN0LgoKCmdjYy9mb3J0cmFu L0NoYW5nZUxvZzoKCjIwMTUtMDQtMTUgIEFuZHJlIFZlaHJlc2NoaWxkICA8 dmVocmVAZ214LmRlPgoKCSogdHJhbnMtZXhwci5jIChnZmNfY29udl9wcm9j ZWR1cmVfY2FsbCk6IEZvciBFWFBSX1NUUlVDVFVSRQoJaGFuZCB0aGUgdHJl ZSB3aXRob3V0IGluZGlyZWN0IHJlZi4gQW5kIGZvciBFWFBSX0ZVTkNUSU9O cwoJYWRkIGEgdGVtcG9yYXJ5IHZhcmlhYmxlIHRvIHByZXZlbnQgY2FsbGlu ZyB0aGUgZnVuY3Rpb24KCW11bHRpcGxlIHRpbWVzLgoK --MP_/plpFjPhWwDc7OKxVHeIZLGQ Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=pr58586_1.patch Content-length: 1951 diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 9e6432f..80dfed1 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -5344,8 +5344,19 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && (e->expr_type != EXPR_VARIABLE && !e->rank)) { int parm_rank; - tmp = build_fold_indirect_ref_loc (input_location, - parmse.expr); + /* It is known the e returns a structure type with at least one + allocatable component. When e is a function, ensure that the + function is called once only by using a temporary variable. */ + if (e->expr_type == EXPR_FUNCTION) + parmse.expr = gfc_evaluate_now_loc (input_location, + parmse.expr, &se->pre); + + if (POINTER_TYPE_P (TREE_TYPE (parmse.expr))) + tmp = build_fold_indirect_ref_loc (input_location, + parmse.expr); + else + tmp = parmse.expr; + parm_rank = e->rank; switch (parm_kind) { diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f90 b/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f90 new file mode 100644 index 0000000..297fae1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f90 @@ -0,0 +1,41 @@ +! { dg-do run } +! +! Check that pr58586 is fixed now. +! Based on a contribution by Vladimir Fuka +! Contibuted by Andre Vehreschild + +program test_pr58586 + implicit none + + type :: a + end type + + type :: c + type(a), allocatable :: a + end type + + type :: b + integer, allocatable :: a + end type + + ! These two are merely to check, if compilation works + call add(b()) + call add(b(null())) + + ! This needs to execute, to see whether the segfault at runtime is resolved + call add_c(c_init()) + +contains + + subroutine add (d) + type(b), value :: d + end subroutine + + subroutine add_c (d) + type(c), value :: d + end subroutine + + type(c) function c_init() + end function +end program test_pr58586 + --MP_/plpFjPhWwDc7OKxVHeIZLGQ--