From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.smtpout.orange.fr (smtp-14.smtpout.orange.fr [80.12.242.14]) by sourceware.org (Postfix) with ESMTPS id BE7DE38582BE for ; Thu, 13 Jul 2023 08:52:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE7DE38582BE Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from cyrano.home ([86.215.161.51]) by smtp.orange.fr with ESMTPA id Js3wqzoJKtImzJs44q0yVh; Thu, 13 Jul 2023 10:52:44 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1689238364; bh=BNG4zJnodo7o828Hze2Fi0n8fW7doYgW4UjAPhpoUHM=; h=From:To:Subject:Date:In-Reply-To:References; b=HkQMHma+oVO09cTib9VunHqly6JrtImBl2mOHonxBNvW4ZGeWeCIMkQPn+xYTn2xz 3HjwfeDhvUIAqU8oOb4V5yLD2H4K+DuMMWvqJGp3XCC/9Kv6YtuUqppflax+hKIEux qtnrFWFpMcgW837E0jZ+oK/h1pFuHcNVF21hx3QbzY813dEAZKWIjxRDf05SvDQ6EK ud1gL3imTbst0IWAWIMfNthb6jk+LQU93ydQi6PL8jehVhEGwNdhwr/0H//L1VZTg1 xg/SWcU5rQGqQzjsDVf4t025JVumqwXS3ibKofZA4x2SGzZUMhn6lWOwaxcbUdiIwE uK6RJ6hgiiL7A== X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Thu, 13 Jul 2023 10:52:44 +0200 X-ME-IP: 86.215.161.51 From: Mikael Morin To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 07/14] fortran: Push element size expression generation close to its usage Date: Thu, 13 Jul 2023 10:52:29 +0200 Message-Id: <20230713085236.330222-8-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713085236.330222-1-mikael@gcc.gnu.org> References: <20230713085236.330222-1-mikael@gcc.gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NEUTRAL,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: gfc_add_finalizer_call creates one expression which is only used by the get_final_proc_ref function. Move the expression generation there. gcc/fortran/ChangeLog: * trans.cc (gfc_add_finalizer_call): Remove local variable elem_size. Pass expression to get_elem_size and move the element size expression generation close to its usage there. (get_elem_size): Add argument expr, remove class_size argument and rebuild it from expr. Remove ts argument and use the type of expr instead. --- gcc/fortran/trans.cc | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc index 3750d4eca82..e5ad67199e7 100644 --- a/gcc/fortran/trans.cc +++ b/gcc/fortran/trans.cc @@ -1100,24 +1100,26 @@ get_final_proc_ref (gfc_se *se, gfc_expr *final_wrapper) } -/* Generate the code to obtain the value of the element size whose expression - is passed as argument in CLASS_SIZE. */ +/* Generate the code to obtain the value of the element size of the expression + passed as argument in EXPR. */ static void -get_elem_size (gfc_se *se, gfc_typespec *ts, gfc_expr *class_size) +get_elem_size (gfc_se *se, gfc_expr *expr) { - gcc_assert (ts->type == BT_DERIVED || ts->type == BT_CLASS); + gcc_assert (expr->ts.type == BT_DERIVED || expr->ts.type == BT_CLASS); - if (ts->type == BT_DERIVED) + if (expr->ts.type == BT_DERIVED) { - gcc_assert (!class_size); - se->expr = gfc_typenode_for_spec (ts); + se->expr = gfc_typenode_for_spec (&expr->ts); se->expr = TYPE_SIZE_UNIT (se->expr); se->expr = fold_convert (gfc_array_index_type, se->expr); } else { - gcc_assert (class_size); + gfc_expr *class_size = gfc_copy_expr (expr); + gfc_add_vptr_component (class_size); + gfc_add_size_component (class_size); + gfc_conv_expr (se, class_size); gcc_assert (se->post.head == NULL_TREE); } @@ -1307,7 +1309,6 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2) gfc_ref *ref; gfc_expr *expr; gfc_expr *final_expr = NULL; - gfc_expr *elem_size = NULL; bool has_finalizer = false; if (!expr2 || (expr2->ts.type != BT_DERIVED && expr2->ts.type != BT_CLASS)) @@ -1361,10 +1362,6 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2) final_expr = gfc_copy_expr (expr); gfc_add_vptr_component (final_expr); gfc_add_final_component (final_expr); - - elem_size = gfc_copy_expr (expr); - gfc_add_vptr_component (elem_size); - gfc_add_size_component (elem_size); } gcc_assert (final_expr->expr_type == EXPR_VARIABLE); @@ -1379,7 +1376,7 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2) gfc_se size_se; gfc_init_se (&size_se, NULL); - get_elem_size (&size_se, &expr->ts, elem_size); + get_elem_size (&size_se, expr); gfc_add_block_to_block (&tmp_block, &size_se.pre); gfc_se desc_se; -- 2.40.1