From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 115687 invoked by alias); 6 Jul 2015 11:55:05 -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 115665 invoked by uid 89); 6 Jul 2015 11:55:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL,BAYES_50,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.17.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 06 Jul 2015 11:55:02 +0000 Received: from vepi2 ([84.63.202.252]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0Lkzph-1YeOGN1HLp-00ajvS; Mon, 06 Jul 2015 13:54:58 +0200 Date: Mon, 06 Jul 2015 11:55:00 -0000 From: Andre Vehreschild To: GCC-Patches-ML , GCC-Fortran-ML Cc: Paul Richard Thomas Subject: Re: [Patch, Fortran, 66035, v2] [5/6 Regression] gfortran ICE segfault Message-ID: <20150706135457.429f0e35@vepi2> In-Reply-To: <20150511124006.62b5c58b@gmx.de> References: <20150508152950.182a4c1a@gmx.de> <554F573D.9030909@sfr.fr> <20150511124006.62b5c58b@gmx.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/ICk.ZpUyxSiG.akyim3n_0G" X-UI-Out-Filterresults: notjunk:1;V01:K0:96jHdiFBV94=:KLjFfjOUIEzmsh8l+c5rFT kNOa7rH4oNA+/QuL9I7bRRvPtanfhvB4YNulnZS+xe0Ulqk675dHRjwH9+iK6FqQ+nR8q5VZP iP9OSgzLr/5pHFZoH+9/pO0dH4GpWS6yk6Gqfnlz4/EY6TNHdmrPwsxbs2rFsbrTGsVDI8Hig fQ35y/CHR4P3zOuPs85Um2jrQKHsdjtZfF8z/2Cl88Zx/CUtAf6I2FukZupgNo9OcAZy+XCj+ Wpdyquw+rbQG6AfnE8ozF1zgd5SWQrKa16stmexKNq5X7rtcMIBziyR9pvzAOBO5mKZ4ocQaH uwQXiNPpTokiup53maVbgswBf8aARVbvPdD4UILXGBwhT59zVvu7LHuBbnwObX9oHLnA3rj04 Ev3t5VpilvX/zbg8tSMFCA3SJ4695C0Dz2zFVt2AxXWb7k7cYi1UnrWmFBEGIJ5sul031u69v kn9sFLizd/38vN1xoKjTQdD6n5dAqPy/wt0P7zpA4UEaOZqz7XwI7zYKXB1EKtniVAiJUPms2 XhTxXJxfs7j/cNT3JR3lMP/iiulQK/38VijSpeRqEktWjd/LN0fcAZfUbpKnskkYF5h0HiB0s Ti71ZQWfV4iF3FFeHjzGBJjFodfajF26olyu46yeTaZjs7pDVFJmuCXixiHsB2ZYMEKSse6B7 PTQvXwRdk/EzGy8b/ySsiomp3/dqPGpAWKSTrJyZanrPRcA== X-SW-Source: 2015-07/txt/msg00315.txt.bz2 --MP_/ICk.ZpUyxSiG.akyim3n_0G Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 669 Hi all, please find attached the next version of the patch for pr66035 fixing an ICE. Scope (copied from first submit): An ICE occurred when in a structure constructor an allocatable component of type class was initialized with an existing class object. This was caused by - the size of the memory to allocate for the component was miscalculated, - the vptr was not set correctly, and - when the class object to be used for init was allocatable already, it was copied wasting some memory instead of a view_convert inserted. Bootstraps and regtests fine on x86_64-linux-gnu/f21. Ok for trunk? Regards, Andre -- Andre Vehreschild * Email: vehre ad gmx dot de --MP_/ICk.ZpUyxSiG.akyim3n_0G Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=pr66035_2.clog Content-length: 711 gcc/fortran/ChangeLog: 2015-07-06 Andre Vehreschild PR fortran/66035 * trans-expr.c (alloc_scalar_allocatable_for_subcomponent_assignment): Compute the size to allocate for class and derived type objects correclty. (gfc_trans_subcomponent_assign): Only allocate memory for a component when the object to assign is not an allocatable class object (the memory is already present for allocatable class objects). Furthermore use copy_class_to_class for assigning the rhs to the component (may happen for dummy class objects on the rhs). gcc/testsuite/ChangeLog: 2015-07-06 Andre Vehreschild PR fortran/66035 * gfortran.dg/structure_constructor_13.f03: New test. --MP_/ICk.ZpUyxSiG.akyim3n_0G Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=pr66035_2.patch Content-length: 3051 diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 195f7a4..74af725 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -6903,6 +6903,29 @@ alloc_scalar_allocatable_for_subcomponent_assignment (stmtblock_t *block, TREE_TYPE (tmp), tmp, fold_convert (TREE_TYPE (tmp), size)); } + else if (cm->ts.type == BT_CLASS) + { + gcc_assert (expr2->ts.type == BT_CLASS || expr2->ts.type == BT_DERIVED); + if (expr2->ts.type == BT_DERIVED) + { + tmp = gfc_get_symbol_decl (expr2->ts.u.derived); + size = TYPE_SIZE_UNIT (tmp); + } + else + { + gfc_expr *e2vtab; + gfc_se se; + e2vtab = gfc_find_and_cut_at_last_class_ref (expr2); + gfc_add_vptr_component (e2vtab); + gfc_add_size_component (e2vtab); + gfc_init_se (&se, NULL); + gfc_conv_expr (&se, e2vtab); + gfc_add_block_to_block (block, &se.pre); + size = fold_convert (size_type_node, se.expr); + gfc_free_expr (e2vtab); + } + size_in_bytes = size; + } else { /* Otherwise use the length in bytes of the rhs. */ @@ -7030,7 +7053,8 @@ gfc_trans_subcomponent_assign (tree dest, gfc_component * cm, gfc_expr * expr, gfc_add_expr_to_block (&block, tmp); } else if (init && (cm->attr.allocatable - || (cm->ts.type == BT_CLASS && CLASS_DATA (cm)->attr.allocatable))) + || (cm->ts.type == BT_CLASS && CLASS_DATA (cm)->attr.allocatable + && expr->ts.type != BT_CLASS))) { /* Take care about non-array allocatable components here. The alloc_* routine below is motivated by the alloc_scalar_allocatable_for_ @@ -7074,6 +7098,14 @@ gfc_trans_subcomponent_assign (tree dest, gfc_component * cm, gfc_expr * expr, tmp = gfc_build_memcpy_call (tmp, se.expr, size); gfc_add_expr_to_block (&block, tmp); } + else if (cm->ts.type == BT_CLASS && expr->ts.type == BT_CLASS) + { + tmp = gfc_copy_class_to_class (se.expr, dest, integer_one_node, + CLASS_DATA (cm)->attr.unlimited_polymorphic); + gfc_add_expr_to_block (&block, tmp); + gfc_add_modify (&block, gfc_class_vptr_get (dest), + gfc_class_vptr_get (se.expr)); + } else gfc_add_modify (&block, tmp, fold_convert (TREE_TYPE (tmp), se.expr)); diff --git a/gcc/testsuite/gfortran.dg/structure_constructor_13.f03 b/gcc/testsuite/gfortran.dg/structure_constructor_13.f03 new file mode 100644 index 0000000..c74e325 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/structure_constructor_13.f03 @@ -0,0 +1,28 @@ +! { dg-do run } +! +! Contributed by Melven Roehrig-Zoellner +! PR fortran/66035 + +program test_pr66035 + type t + end type t + type w + class(t), allocatable :: c + end type w + + type(t) :: o + + call test(o) +contains + subroutine test(o) + class(t), intent(inout) :: o + type(w), dimension(:), allocatable :: list + + select type (o) + class is (t) + list = [w(o)] ! This caused an ICE + class default + call abort() + end select + end subroutine +end program --MP_/ICk.ZpUyxSiG.akyim3n_0G--