From patchwork Sun Nov 20 14:34:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Vehreschild X-Patchwork-Id: 83151 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1023693qge; Sun, 20 Nov 2016 06:35:10 -0800 (PST) X-Received: by 10.129.85.11 with SMTP id j11mr8666785ywb.123.1479652510481; Sun, 20 Nov 2016 06:35:10 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id f65si3707083ywb.114.2016.11.20.06.35.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Nov 2016 06:35:10 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-442076-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-442076-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-442076-patch=linaro.org@gcc.gnu.org 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=j1O8IourhSq5+Dk9 IaK0NGt3Ql64v56qkYUw1pf7OOqKwciwetPYMX2EH6jROKOBImIcB7Xq1eKX8JD2 GG5aPuyhec+O6h11UBldFbEpcUkvtj8Qpp/bZ8o7azAKbRz8ORd6faSwFtMzLtwp RSf8ETH24SVb5MFpEwH+6HFWJaY= 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=sHlHoOlMq9HRRyfV+jAMsE zf060=; b=PStuB8fLN+qeOw6BahjiIENYW9h98qzw267e1u28V3Y3K4JabITTBC bHTHLOZGQlB+qm3l/kl4aBcS9E9fDyLqnzptYgJsWYqLPgWQnxnvFoi2vtLx2rn3 DRAFydeTyBqHYBtMb8cpJsixeDwbO+6EEHWnRM64vRj7DBPKh0L/k= Received: (qmail 96950 invoked by alias); 20 Nov 2016 14:34:50 -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 96927 invoked by uid 89); 20 Nov 2016 14:34:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=H*MI:sk:2016112, nicht, Hx-languages-length:4714, vehregmxde X-Spam-User: qpsmtpd, 3 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, 20 Nov 2016 14:34:39 +0000 Received: from vepi2 ([92.76.205.227]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0Mdr7l-1cOkas2Q05-00PeQG; Sun, 20 Nov 2016 15:34:35 +0100 Date: Sun, 20 Nov 2016 15:34:34 +0100 From: Andre Vehreschild To: Janus Weil Cc: GCC-Patches-ML , GCC-Fortran-ML Subject: Re: [PATCH, Fortran, pr78395, v1] [OOP] error on polymorphic assignment Message-ID: <20161120153434.399595c1@vepi2> In-Reply-To: <20161120152316.4c175268@vepi2> References: <20161118180017.476fcdaf@vepi2> <20161120152316.4c175268@vepi2> MIME-Version: 1.0 X-UI-Out-Filterresults: notjunk:1; V01:K0:/LMWtTQx7Cs=:yZe+ihso4RoKCCcHKfCkXt jKifu+SOt+bDtlWQ8mhIRQUcuhNbcJbq17SnQngbfKrYujL072h+WP1DsEuGjumKHYAgbBew6 qFzMe6/jlbrESB/ZMCLvCYWnvTd7U1sZIplQ7jCP0IkbxuoFOZls9YWhowuZ6Qx8hX70JWatT FJ/KcTQriaTf5rK02IIsCe2YTedy2rjBIVidVZ9RjtpVHKiSBCG7jKraJXFftGiw3VE14GawN nwUeUBclNKyRc/fMdFn2Sh56e2UQlEOHlAajDprR4D3Q3cq/F005HPg3YCXzi/4P6owLWRvTZ lp2S/SOYtSwmPYNEZoPZ0gcpsAvhnMnfOl9o3WVta3BGgKoCVdKl6JE1XrPaJPSyJk9lqyvBt r3AwO0d0xgSwhrY9hxJxk4LIel6QfPlS+CzNA5jiupILhF+UcMZF7fhtjp8eRA9aiQuAa8Dm7 gd2VLrwgds5kgb9Yg2CkL3YE0fngDUbomkF/L9yeDTtez2I+r+BJb+IUnJykAKwpExe0qBzJs NrITHgE0qk7hm2ct73x0ES6yNRNmHGOiHZ2BEx1AelHJOPPQEjiV4yO6Ixxrt+7Os5W5WaW8f Ph5tdUgW35FwoA/5g3WV2iJnC7gKmPRmFWaQ7GPCzAp93v4LpyVmpyh1WCqlEJIlJJ2UDcwbF nD2xANifha62Nw5g2M2HDXc/puVi44qhpgracs0IdaBTHH0RdKIZZvxSw1m1HSVxlm6orvgIj oNQryHLNqfUutjAGOaJ/KIqtdMP7Y81C1AZ5tbmSD/jqeGX3iUNoiurJWTM= Whoops, hit send to fast. Here's the patch committed. - Andre On Sun, 20 Nov 2016 15:23:16 +0100 Andre Vehreschild wrote: > Hi Janus, > > thanks for the review. Committed to trunk as r242637. Will wait one week > before committing to 6. > > Regards, > Andre > > On Sat, 19 Nov 2016 16:14:54 +0100 > Janus Weil wrote: > > > Hi Andre, > > > > > When checking the shortened example in comment #3 one gets a segfault, > > > because v6 is not allocated explicitly. The initial example made sure, > > > that v6 was allocated. > > > > sorry, I guess that's my fault. I blindly removed the allocate > > statement when looking for a reduced test case for the compile-time > > error. > > > > > > > Btw, when using the in gcc-7 available > > > polymorphic assign, then v6 is actually auto-allocated and the program > > > runs fine. So what are your opinions on the auto-allocation issue? > > > > I suspect that auto-allocation does not apply to defined assignment, > > but I'm not fully sure. Looking in the F08 standard, it seems to be > > mentioned in 7.2.1.3, but not in 7.2.1.4. > > > > As Thomas mentioned, you could take that question to c.l.f. to get a > > more qualified answer and/or open a follow-up PR for it. > > > > > > > This patch fixes the wrong error messages in both gcc-7 and gcc-6. > > > Bootstraped and regtested on x86_64-linux/F23 for gcc-7 and -6. Ok for > > > trunk and gcc-6? > > > > Yes, looks good to me (at least for trunk; gcc-6 if you like). > > > > Thanks for the patch, > > Janus > > -- Andre Vehreschild * Email: vehre ad gmx dot de Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (Revision 242636) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,9 @@ +2016-11-20 Andre Vehreschild + + PR fortran/78395 + * resolve.c (resolve_typebound_function): Prevent stripping of refs, + when the base-expression is a class' typed one. + 2016-11-18 Richard Sandiford Alan Hayward David Sherwood Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (Revision 242636) +++ gcc/fortran/resolve.c (Arbeitskopie) @@ -6140,7 +6140,7 @@ gfc_free_ref_list (class_ref->next); class_ref->next = NULL; } - else if (e->ref && !class_ref) + else if (e->ref && !class_ref && expr->ts.type != BT_CLASS) { gfc_free_ref_list (e->ref); e->ref = NULL; Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (Revision 242636) +++ gcc/testsuite/ChangeLog (Arbeitskopie) @@ -1,3 +1,8 @@ +2016-11-20 Andre Vehreschild + + PR fortran/78395 + * gfortran.dg/typebound_operator_21.f03: New test. + 2016-11-20 Marc Glisse * gcc.dg/tree-ssa/divide-5.c: New file. Index: gcc/testsuite/gfortran.dg/typebound_operator_21.f03 =================================================================== --- gcc/testsuite/gfortran.dg/typebound_operator_21.f03 (nicht existent) +++ gcc/testsuite/gfortran.dg/typebound_operator_21.f03 (Arbeitskopie) @@ -0,0 +1,78 @@ +! { dg-do run } +! +! Test that pr78395 is fixed. +! Contributed by Chris MacMackin and Janus Weil + +module types_mod + implicit none + + type, public :: t1 + integer :: a + contains + procedure :: get_t2 + end type + + type, public :: t2 + integer :: b + contains + procedure, pass(rhs) :: mul2 + procedure :: assign + generic :: operator(*) => mul2 + generic :: assignment(=) => assign + end type + +contains + + function get_t2(this) + class(t1), intent(in) :: this + class(t2), allocatable :: get_t2 + type(t2), allocatable :: local + allocate(local) + local%b = this%a + call move_alloc(local, get_t2) + end function + + function mul2(lhs, rhs) + class(t2), intent(in) :: rhs + integer, intent(in) :: lhs + class(t2), allocatable :: mul2 + type(t2), allocatable :: local + allocate(local) + local%b = rhs%b*lhs + call move_alloc(local, mul2) + end function + + subroutine assign(this, rhs) + class(t2), intent(out) :: this + class(t2), intent(in) :: rhs + select type(rhs) + type is(t2) + this%b = rhs%b + class default + error stop + end select + end subroutine + +end module + + +program minimal + use types_mod + implicit none + + class(t1), allocatable :: v4 + class(t2), allocatable :: v6 + + allocate(v4, source=t1(4)) + allocate(v6) + v6 = 3 * v4%get_t2() + + select type (v6) + type is (t2) + if (v6%b /= 12) error stop + class default + error stop + end select + deallocate(v4, v6) +end +