From patchwork Tue Aug 13 11:07:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Vehreschild X-Patchwork-Id: 1971891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=vehre@gmx.de header.a=rsa-sha256 header.s=s31663417 header.b=GaZ47Pwv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WjpWx3gThz1yXl for ; Tue, 13 Aug 2024 21:07:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A4653858CD9 for ; Tue, 13 Aug 2024 11:07:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by sourceware.org (Postfix) with ESMTPS id 3A52D3858D20; Tue, 13 Aug 2024 11:07:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A52D3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3A52D3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723547251; cv=none; b=ft2XwjtFfQdm1mjPoQNHBRSnOVryN6UjNxQklsK9ZhRP9LxsMj6PwKZKOGsuZEAdk2CTdPvlG41JuvePzGezzwhS4NQqoSCaJ98nlVKPWIKHk2IIBcHuyEaggLKtT0A0SoeXuXgiJ4MUOgPqnUmKH6ZBKwubZCri2MMNiACcLrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723547251; c=relaxed/simple; bh=uZoGVW7gCpkI4peyjxHYRiDEdf03yTuJFITwcSR+GHA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=WkZ+2zgI5Yn7enyhWUGfOj76eweCHQLWf3DDjhXTjKy5jxezrU3m2nK6aRXbRkmAt6bFR6c27op1yV8bcF/jgkAKgDlWQrO3yZ2OzWSgC66ZXNpDaryRCZ7Z/fH4abeXtwCup7S87jYIOn6qQSQ4VTHutwawHWo1+jUu6IPcpns= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1723547248; x=1724152048; i=vehre@gmx.de; bh=6ffpyMimPokomIFA+Y0tHPgLv3x2Is/8qv+PZcZkK2Q=; h=X-UI-Sender-Class:Date:From:To:Subject:Message-ID:MIME-Version: Content-Type:cc:content-transfer-encoding:content-type:date:from: message-id:mime-version:reply-to:subject:to; b=GaZ47Pwve+sZThh/jtSlf+cC0uUhQlxZJKG3xy9Ow+j5WVTU7+6V8AjDQMQgMTRt YsGKFNybfC4tWW+8su07JIAjXXZWKkTwcgjVMFsev95LkyL/L2c5oqc7Hh9pJcqQk mkJQeQKZP+OcI8LgTz9H1lmfo2/38mMjRYn7SR1kjQfUtn61Yi1FdVT8cLxWP5Zvk C56BNyJTDZ2fdDaqS7jMeE5ho7M34fBFLDEMUWfzCGUtO51FC5gIhUi2zgFfqs223 S+EgF2vhRIbu7cbIPRVdtlqFD+40Gaix3H0OJ+NhOYGT8DDhHe+m+KXBW7gcitfAn o7pILzeHDYpywB3nBA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from vepi2 ([79.194.172.234]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MpDNl-1rpZuS3F2V-00oowU; Tue, 13 Aug 2024 13:07:27 +0200 Date: Tue, 13 Aug 2024 13:07:24 +0200 From: Andre Vehreschild To: GCC-Patches-ML , GCC-Fortran-ML Subject: [Fortran, Patch, PR116292, v1] Fix 15-regression in move_alloc Message-ID: <20240813130724.02bf6ce8@vepi2> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.43; x86_64-redhat-linux-gnu) MIME-Version: 1.0 X-Provags-ID: V03:K1:C6hB0RvsBbKznSTAcaO3uy408Kl/O+ZvgaKIXzRRavWSyCeS4rY uNAYbCJmEUwdNdI0vhVG2/M/TL3uvb9oBMOMK/KuOeIJZtBer0EDp1v0h88bi4QVJt2wrcH x6IN7xiuMrZKiZPWaXLa7FK7G3TziyM4jocPd1sxf6nb988OajVLTxDrGE4LrV/oT/eD/Mr fl1c3DVXNbAQZMw6ap13A== UI-OutboundReport: notjunk:1;M01:P0:ePLg1LYabxU=;fTkJzjlc+JOF6qN+i7q6o2GUNTu 8BW2SSC6punOop1up8vBXTQTvh689GgzHoDyU9Ra87AImZpND0+s88WoVgXEwaZIfqljnLCee p8mpLbQFitsD6DxZkwWUFDHkH4Jhx2Kr+H1Y8D7rvgWMA3eHUYL0GbUjgpN+MjqY/tx8asj8A uD2w6b3wEwUQMaYwZ6JP8L3WY7OTI8L6qLQEdsNQ93Nrs29g+m/63covv56fB7QCez+ebANrX thP33cNwbbop4O0AHuPoHM85BrYdvGWN3IIfiXMnrqKZqvOkpXFfaYbk2DWupVXnYKzk2WjyC e8heLfPtyIw00h4KCUeJ0julx629Eyz+8kjY1c/MVjgfFRQA9p4jfF5BiVrEFeJ3RRY+c6yGO g1FIkmthe0KYFOECy4sX6QsS+WsL33DzdTZU49y+FxJEVBM3lBQER737OYWVKvRXpZsr67q/7 3vZGO0mjxots2Ii78LHFcG8uwBANaBAEmKQJZ6w/tZg/cmzBHi9AslBPHkkq2WKRn5vjiacfk 2Ztre+GFgCUFv5W0zt2ogQB/yuFy/xs5ZxXGJioL7B0Cg0sPxROtIU8qz/lNTnDmRFPNtQyRt 1BdTBJ/KhoJ9/BHQzWUgZAgXWnkfID10tWyLwn9lMM7svydJnci2BnLg4GEiNUMc2JODzbFYw 7ltil9uRU8w5kz1TLzrkm4li15jWnIfKWpJa7e0jpuOOht0ZmdIbj/E+ZgMQwpt+IvZZQ45mq ypmvqg34JIr0JVn5OJSNdtbExGFyrwSWz//fX210RsPDcB1XdUV13u8f+8JEihwcoDPYJdANZ incZF3oVWiih5VoI8dwV+YYw== X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi all, attached patch fixes a regression introduced by my previous patch on handling _vptr's more consistently. The patch gets the _vptr only of a derived or class type now and not of every type. Regression tested ok on x86_64-pc-linux-gnu / Fedora 39. Ok for mainline? Regards, Andre PS. This patch was made with all of my other pending patches on the same branch. So it may not apply clean to master. --- Andre Vehreschild * Email: vehre ad gmx dot de From 4b19d871a3f5a4cdaf0fef6200ddaf51d6c8a8c4 Mon Sep 17 00:00:00 2001 From: Andre Vehreschild Date: Fri, 9 Aug 2024 16:19:23 +0200 Subject: [PATCH] [Fortran] Fix ICE in build_function_decl [PR116292] Fix ICE by getting the vtype only when a derived or class type is prevent. Also take care about the _len component for unlimited polymorphics. gcc/fortran/ChangeLog: PR fortran/116292 * trans-intrinsic.cc (conv_intrinsic_move_alloc): Get the vtab only for derived types and classes and adjust _len for class types. gcc/testsuite/ChangeLog: * gfortran.dg/move_alloc_19.f90: New test. --- gcc/fortran/trans-intrinsic.cc | 20 ++++++++++-- gcc/testsuite/gfortran.dg/move_alloc_19.f90 | 34 +++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/move_alloc_19.f90 diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc index 34115c2679b..0ecb0439778 100644 --- a/gcc/fortran/trans-intrinsic.cc +++ b/gcc/fortran/trans-intrinsic.cc @@ -12774,9 +12774,12 @@ conv_intrinsic_move_alloc (gfc_code *code) gfc_symbol *vtab; from_tree = from_se.expr; - vtab = gfc_find_vtab (&from_expr->ts); - gcc_assert (vtab); - from_se.expr = gfc_get_symbol_decl (vtab); + if (to_expr->ts.type == BT_CLASS) + { + vtab = gfc_find_vtab (&from_expr->ts); + gcc_assert (vtab); + from_se.expr = gfc_get_symbol_decl (vtab); + } } gfc_add_block_to_block (&block, &from_se.pre); @@ -12821,6 +12824,15 @@ conv_intrinsic_move_alloc (gfc_code *code) gfc_class_set_vptr (&block, to_se.expr, from_se.expr); if (from_is_class) gfc_reset_vptr (&block, from_expr); + if (UNLIMITED_POLY (to_expr)) + { + tree to_len = gfc_class_len_get (to_se.class_container); + tmp = from_expr->ts.type == BT_CHARACTER && from_se.string_length + ? from_se.string_length + : size_zero_node; + gfc_add_modify_loc (input_location, &block, to_len, + fold_convert (TREE_TYPE (to_len), tmp)); + } } if (from_is_scalar) @@ -12835,6 +12847,8 @@ conv_intrinsic_move_alloc (gfc_code *code) input_location, &block, from_se.string_length, build_int_cst (TREE_TYPE (from_se.string_length), 0)); } + if (UNLIMITED_POLY (from_expr)) + gfc_reset_len (&block, from_expr); return gfc_finish_block (&block); } diff --git a/gcc/testsuite/gfortran.dg/move_alloc_19.f90 b/gcc/testsuite/gfortran.dg/move_alloc_19.f90 new file mode 100644 index 00000000000..d23d9809ba1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/move_alloc_19.f90 @@ -0,0 +1,34 @@ +!{ dg-do run } + +! Check PR 116292 is fixed. + +! Contributed by Harald Anlauf +! Sam James + +program move_alloc_19 + character, allocatable :: buffer, dummy, dummy2 + class(*), allocatable :: poly + + dummy = 'C' + dummy2 = 'A' + call s() + if (allocated (dummy)) stop 1 + if (allocated (dummy2)) stop 2 + if (.not. allocated (buffer)) stop 3 + if (.not. allocated (poly)) stop 4 + if (buffer /= 'C') stop 5 + select type (poly) + type is (character(*)) + if (poly /= 'A') stop 6 + if (len (poly) /= 1) stop 7 + class default + stop 8 + end select + deallocate (poly, buffer) +contains + subroutine s + call move_alloc (dummy, buffer) + call move_alloc (dummy2, poly) + end +end + -- 2.46.0