From patchwork Sun Mar 27 16:49:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Vehreschild X-Patchwork-Id: 602369 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 3qY31G2Dfkz9sBf for ; Mon, 28 Mar 2016 03:49:51 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=KPTykPJV; 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:mime-version:content-type; q=dns; s= default; b=L+g1Jjgj/oShbp4FDVZvidkjX2WC86Ov/9C1Z3xWtqRzTgaYcf2TJ gXzPB2Xyx8uNXvij2qiTidOaxuyYH7p37hhEsANsbc7Rc6Plt+HUn6VbuoY9N5HC eD1ktjbgwakZcQwF6E4Fg4UbG4Meuz3CJQ8BLwBIz8wx7iAKFKR8zs= 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:mime-version:content-type; s= default; bh=OSdvSr5Jj6qA1J4rvm4Zh94iixM=; b=KPTykPJVpYFNliWP4cM9 v6MOuKPOTyMdRTRJcHJq+ec8FUea1ddUvALHEeJdVYQHGcUSXP0YcffqdLfhOdUX fb3Aat6cCg9pjdfTFlOpkG8pEG3MQ+YnKpSS9kZRGSSh7scXfU0ZsnCMaq6x2gGJ SNxgnVLoOcLkfL3tncNKhEo= Received: (qmail 130558 invoked by alias); 27 Mar 2016 16:49:38 -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 130531 invoked by uid 89); 27 Mar 2016 16:49:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=poly, unlimited, weber, Weber X-Spam-User: qpsmtpd, 2 recipients X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.17.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sun, 27 Mar 2016 16:49:27 +0000 Received: from nb-priv.private ([82.113.99.150]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0MKHik-1alrls1IFa-001fk4; Sun, 27 Mar 2016 18:49:22 +0200 Date: Sun, 27 Mar 2016 18:49:18 +0200 From: Andre Vehreschild To: fortran@gcc.gnu.org, gcc patches Subject: [Patch, Fortran, pr70397, gcc-5, v1] [5/6 Regression] ice while allocating ultimate polymorphic Message-ID: <20160327184918.2cf9352b@nb-priv.private> MIME-Version: 1.0 X-UI-Out-Filterresults: notjunk:1; V01:K0:1x/6h/myvP4=:/y/SWNCZl4RWxzN4KPtrq/ RorFTbVP80yCplLNMZVvA5YK/IRhLDCgsaC0964WwA2UEu/FghYWwNQgcRzeNNt1NkYDXh2Jw De3D8hr9+7r15Nb2T/WnJhJDmhIrxCuM/3oMB2QnPDmWtKN3b0HFon8exEI46//B2mXgP2PVS F3nXjArUhBnJvdgBgQWh38Ti2W6UKoH52QeEDQ8nWoBZNoNeTFO9xfO39vtnOM6oBYEnNiY/L faopFxPTU9FUChB8VgMdpgP18zRzcmf3m5TGgAS5GWm9tfX9Bp/hS1D6Y2krB/KJU8M3rSfg+ fBqdOVETcem3IqxQWxWty5ZagNtwzK5lkZklONRwBwIKK6gU9cYJlTnqitEJkcqGzgtBap2D9 8Oz6nLu60H9r8zrkw1JG53Ps9qIgb4HJ3xu6/LIGltMhLn8eJy3q/9lEodH/CWnwdcRI0PAHp qlv1bTmcamTmKiEVgwRbmARxP9WNxBqyz0g3VgC9x4M97NRuiil/sclRCxfcg85jq/K/8ENYT ipsWIqQxJfAhs38oThbD4MY27p/fBOtdAhBnR7QjjRFXxcaMxntYUTsPiIRtHSsUgupUBuu+F YRzrLR7a8gHM5Nz7ekoBPG+6iBKLOEVlQOljN5dKF8lGXk3BkoAbMOSpbf055HtlbmppxZXu1 9reswr9rmMGgBpWGwz3fa1ycL8RxrtGiM//y/bRb1e6p3F6pJp2a7hXFu9t4A9fFiVn+lZLtJ w3hfM39rOo3d5mdyRr/35HEzPE+uVThU/HLRca/qk9wzCCFK2fShqvkmFklHspxPEW7tvEjJV 8NKOpYu Hi all, attached is a patch to fix an ICE on allocating an unlimited polymorphic entity from a non-poly class or type without an length component. The routine gfc_copy_class_to_class() assumed that both the source and destination object's type is unlimited polymorphic, but in this case it is true for the destination only, which made gfortran look for a non-existent _len component in the source object and therefore ICE. This is fixed by the patch by adding a function to return either the _len component, when it exists, or a constant zero node to init the destination object's _len component with. Bootstrapped and regtested ok on x86_64-linux-gnu/F23. (Might have some line deltas, because my git is a bit older. Sorry, only have limited/slow net-access currently.) The same patch should be adaptable to trunk. To come... Ok for 5-trunk? Regards, Andre diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 1681d14..642ce26 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -173,6 +173,24 @@ gfc_class_len_get (tree decl) } +/* Try to get the _len component of a class. When the class is not unlimited + poly, i.e. no _len field exists, then return a zero node. */ + +tree +gfc_class_len_or_zero_get (tree decl) +{ + tree len; + if (POINTER_TYPE_P (TREE_TYPE (decl))) + decl = build_fold_indirect_ref_loc (input_location, decl); + len = gfc_advance_chain (TYPE_FIELDS (TREE_TYPE (decl)), + CLASS_LEN_FIELD); + return len != NULL_TREE ? fold_build3_loc (input_location, COMPONENT_REF, + TREE_TYPE (len), decl, len, + NULL_TREE) + : integer_zero_node; +} + + /* Get the specified FIELD from the VPTR. */ static tree @@ -250,6 +268,7 @@ gfc_vptr_size_get (tree vptr) #undef CLASS_DATA_FIELD #undef CLASS_VPTR_FIELD +#undef CLASS_LEN_FIELD #undef VTABLE_HASH_FIELD #undef VTABLE_SIZE_FIELD #undef VTABLE_EXTENDS_FIELD @@ -1070,7 +1089,7 @@ gfc_copy_class_to_class (tree from, tree to, tree nelems, bool unlimited) if (unlimited) { if (from_class_base != NULL_TREE) - from_len = gfc_class_len_get (from_class_base); + from_len = gfc_class_len_or_zero_get (from_class_base); else from_len = integer_zero_node; } diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index e6544f9..38cffa4 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -356,6 +356,7 @@ tree gfc_class_set_static_fields (tree, tree, tree); tree gfc_class_data_get (tree); tree gfc_class_vptr_get (tree); tree gfc_class_len_get (tree); +tree gfc_class_len_get_try (tree); gfc_expr * gfc_find_and_cut_at_last_class_ref (gfc_expr *); /* Get an accessor to the class' vtab's * field, when a class handle is available. */ diff --git a/gcc/testsuite/gfortran.dg/unlimited_polymorphic_25.f90 b/gcc/testsuite/gfortran.dg/unlimited_polymorphic_25.f90 new file mode 100644 index 0000000..d0b2a2e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/unlimited_polymorphic_25.f90 @@ -0,0 +1,40 @@ +! { dg-do run } +! +! Test contributed by Valery Weber + +module mod + + TYPE, PUBLIC :: base_type + END TYPE base_type + + TYPE, PUBLIC :: dict_entry_type + CLASS( * ), ALLOCATABLE :: key + CLASS( * ), ALLOCATABLE :: val + END TYPE dict_entry_type + + +contains + + SUBROUTINE dict_put ( this, key, val ) + CLASS(dict_entry_type), INTENT(INOUT) :: this + CLASS(base_type), INTENT(IN) :: key, val + INTEGER :: istat + ALLOCATE( this%key, SOURCE=key, STAT=istat ) + end SUBROUTINE dict_put +end module mod + +program test + use mod + type(dict_entry_type) :: t + type(base_type) :: a, b + call dict_put(t, a, b) + + if (.NOT. allocated(t%key)) call abort() + select type (x => t%key) + type is (base_type) + class default + call abort() + end select + deallocate(t%key) +end + diff --git a/gcc/testsuite/gfortran.dg/unlimited_polymorphic_26.f90 b/gcc/testsuite/gfortran.dg/unlimited_polymorphic_26.f90 new file mode 100644 index 0000000..1300069 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/unlimited_polymorphic_26.f90 @@ -0,0 +1,47 @@ +! { dg-do run } +! +! Test contributed by Valery Weber + +module mod + + TYPE, PUBLIC :: dict_entry_type + CLASS( * ), ALLOCATABLE :: key + CLASS( * ), ALLOCATABLE :: val + END TYPE dict_entry_type + + +contains + + SUBROUTINE dict_put ( this, key, val ) + CLASS(dict_entry_type), INTENT(INOUT) :: this + CLASS(*), INTENT(IN) :: key, val + INTEGER :: istat + ALLOCATE( this%key, SOURCE=key, STAT=istat ) + ALLOCATE( this%val, SOURCE=val, STAT=istat ) + end SUBROUTINE dict_put +end module mod + +program test + use mod + type(dict_entry_type) :: t + call dict_put(t, "foo", 42) + + if (.NOT. allocated(t%key)) call abort() + select type (x => t%key) + type is (CHARACTER(*)) + if (x /= "foo") call abort() + class default + call abort() + end select + deallocate(t%key) + + if (.NOT. allocated(t%val)) call abort() + select type (x => t%val) + type is (INTEGER) + if (x /= 42) call abort() + class default + call abort() + end select + deallocate(t%val) +end +