From patchwork Fri Aug 16 12:10:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Vehreschild X-Patchwork-Id: 1973235 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=BH2HKz3e; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Wlgnl47y5z1yfB for ; Fri, 16 Aug 2024 22:11:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE0F4385DDCD for ; Fri, 16 Aug 2024 12:11:18 +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.19]) by sourceware.org (Postfix) with ESMTPS id 21A6C385DC3C; Fri, 16 Aug 2024 12:10:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 21A6C385DC3C 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 21A6C385DC3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723810256; cv=none; b=YWO1xgHGPoJ2Gf7l395VJyrcbG0uKqAniCAzyajsW1XTimaENo1TPZIKSRNJ0IfB0448MEZKkGl0pgSF6FreIP9gbFnVVQSfOM2JkypqDGOt/zyYnr/gPDTyC0YAwERwqMST2rn8P/Pv9mV88TDZekTFETR/KYOUaQQ0u8P8/rU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723810256; c=relaxed/simple; bh=aC5+/Jd3d/e5IsBK3Ao7WwuEQXAyxQGgn6s0ijg+yIs=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=bcYHUpLV02GJw8p5Nt652U5S4SI/mUbP9IaF/ejngxgRM5AMM3tWIvVHYGSTy1tuW9pqQjncG3rb+fnuBCPXJ9b2ej6pSRji+paN5m1MGxTFufvAb07qkN37qpu5i/CNP/qh4z7O2PXj8gzDXTPrJAQACIeXYflJGeFUn8S6yeM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1723810250; x=1724415050; i=vehre@gmx.de; bh=vhPAtrgXUPobkJZJy/uiZvZgcgCnlUCzlJXDQgy4n4Y=; 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=BH2HKz3eifXudkgxwy+Rskbd9J89vlVpAqHp49WxPQ5oacLhhpQQUOKM+3hCIVbp SG4bzIluAGx7FqF9IKuAM8lEKFAOnoymcC+8Zr2Zy2cYaUIZgjxsa1C0YiGGRlxNY f0G43kSmZn3zpl9DaDHkWAduLscXAqt14SPt+LddsdOcZzlXxabLae60is3zllCnz LboCGqqco1d4nupcmPZPt5qzib54C4HgLPPsV+zIHfP5CYGhDfOGmhh2er2Gq4KWz pfMh1N0Sa9Na6lvi0IrwCMbdehkhfaCNkTKv9+JgzPG7n9omHXRhzApmIOoHB7gR0 pNaV45X8OfwTsncMLg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from vepi2 ([79.194.172.234]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1My32L-1sEuI91Cud-00sjiN; Fri, 16 Aug 2024 14:10:50 +0200 Date: Fri, 16 Aug 2024 14:10:49 +0200 From: Andre Vehreschild To: GCC-Patches-ML , GCC-Fortran-ML , Paul Richard Thomas Subject: [Fortran, Patch, PR46371, v1] Fix coarrays use in select type Message-ID: <20240816141049.073a5ed3@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:+ucmy8zDLKBYPoXugRaKoFgsN0pGBq1t1py/5eWBwHtJyoTqx76 Q+XP1Ohnbmec+M54mxhulYJyTGliOvtt2MNumPmb4qrTUPWxegH9c7bFtybM7UysCf24hnX ijd/P57eLc5X0Qtqfal1Pu32kjFM+SOXNd/7LDXgnlG2nnoocO930P9nyig6ovr5FPT9u4E UiQGMK/d12SiYai9yHRTA== UI-OutboundReport: notjunk:1;M01:P0:Ve2dO03oFvo=;rzPFI5lz9PJf5pSkLiyAqBhwB4Z 0lefAOXtqaq6mLxJqWuS/e/lj6vmpIfP0ETwk03fR60Vial+wEoAKDk+VnGRMM2py9aPt94Cc oSFGryKT4FA+VUvylwNSABbjcBPM5NaRccb2IJgvAayYCH4EfH/1v0LjJmrlSfzJ/SoH5/ju+ SdJ1iJyWLFrYQUCpjmsr9IPsvh41/VRoCGmRc20SSRjGKIvC28r9Rdtsa1FjeGM7hobFQkBd1 pEN9KlR6dBsIKGj/FP38hq7PpRQ5mqZzTx3TmM0WR3PDYjow123R0pwRiBQj9YB5KoABnroew BIShLUZx8Z+eh58Co7WBKvITS35Tq7IUpwYvP7/ptWkeTUeoNefVYARoqtCFW4/hU/g0BMkGS Rgcdj+qhPgIJLjYR/V8Ffz5qa0v1PFj80sUT1n//DOaVKB48DwQAK5WW2JBd9cLo1UVNj7QKx rIXFr2HCWOSo4G37X1h77/xjj6K5PXR2T2FeB6HLou4Erli4TUN62zbhnopxnvZy9Fv8cYfsP 6pkp0oKvkV5M7fVbrfR7v81otkUVEUM5hSiO/rQH6vyxiRo+QUl4aHZqhoFKgAE3c7HJ0/Dxs 6C+g1co/uS4iu5UlhlMet4j6K6JfDdQEKFlkqOUM0Y5XWQheu0ZwkV3y6t9dzT7wqpZWbX84m LSpv2V/+fdni7+vd5r23A2O+tQPpq08puiadPy219j1ENaR9DhFCgjfAjPXiS/6HFibWjSeOd dYYBOZjTr3hx/J3Z3JWyMvm1/taEtRxBNVPKHscnCmJ2PGxlwvfBsvmzBZ09lE8cNQxwm4s4T f3UYA4jj7U41LnyoEMXSqMqA== X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 is a follow up on the pr110033 patch and fixes two ICEs reported in pr46371. With the patch also pr56496 is fixed, although that could have been fixed by pr110033 already. I just added the testcase from pr56496 here as coarray/select_type_3.f90 (I like it when the name of the test gives a rough idea on what is tested instead of having just the pr#) to have it covered. Bootstraps and regtests ok on x86_64-pc-linux-gnu. Ok for mainline? Regards, Andre --- Andre Vehreschild * Email: vehre ad gmx dot de From 205e001e9df7d7b84667a16deee776d2cc8129ca Mon Sep 17 00:00:00 2001 From: Andre Vehreschild Date: Thu, 15 Aug 2024 20:23:23 +0200 Subject: [PATCH] [Fortran] Allow coarrays in select type. [PR46371, PR56496] Fix ICE when scalar coarrays are used in a select type. Prevent coindexing in associate/select type/select rank selector expression. gcc/fortran/ChangeLog: PR fortran/46371 PR fortran/56496 * expr.cc (gfc_is_coindexed): Detect is coindexed also when rewritten to caf_get. * trans-stmt.cc (trans_associate_var): Always accept a descriptor for coarrays. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/select_type_1.f90: New test. * gfortran.dg/coarray/select_type_2.f90: New test. * gfortran.dg/coarray/select_type_3.f90: New test. --- gcc/fortran/expr.cc | 4 +++ gcc/fortran/trans-stmt.cc | 10 ++---- .../gfortran.dg/coarray/select_type_1.f90 | 34 +++++++++++++++++++ .../gfortran.dg/coarray/select_type_2.f90 | 19 +++++++++++ .../gfortran.dg/coarray/select_type_3.f90 | 23 +++++++++++++ 5 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/coarray/select_type_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/coarray/select_type_2.f90 create mode 100644 gcc/testsuite/gfortran.dg/coarray/select_type_3.f90 diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index d3a1f8c0ba1..4f2d80c04f8 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -5803,6 +5803,10 @@ gfc_is_coindexed (gfc_expr *e) { gfc_ref *ref; + if (e->expr_type == EXPR_FUNCTION && e->value.function.isym + && e->value.function.isym->id == GFC_ISYM_CAF_GET) + e = e->value.function.actual->expr; + for (ref = e->ref; ref; ref = ref->next) if (ref->type == REF_ARRAY && ref->u.ar.codimen > 0) return !gfc_ref_this_image (ref); diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc index 3b09a139dc0..023b1739b85 100644 --- a/gcc/fortran/trans-stmt.cc +++ b/gcc/fortran/trans-stmt.cc @@ -2200,16 +2200,12 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block *block) else stmp = gfc_class_data_get (ctmp); - /* Coarray scalar component expressions can emerge from - the front end as array elements of the _data field. */ - if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (stmp))) - stmp = gfc_conv_descriptor_data_get (stmp); - - if (!POINTER_TYPE_P (TREE_TYPE (stmp))) + if (!CLASS_DATA (sym)->attr.codimension + && !POINTER_TYPE_P (TREE_TYPE (stmp))) stmp = gfc_build_addr_expr (NULL, stmp); dtmp = gfc_class_data_get (ctree); - stmp = fold_convert (TREE_TYPE (dtmp), stmp); + stmp = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (dtmp), stmp); gfc_add_modify (&se.pre, dtmp, stmp); stmp = gfc_class_vptr_get (ctmp); dtmp = gfc_class_vptr_get (ctree); diff --git a/gcc/testsuite/gfortran.dg/coarray/select_type_1.f90 b/gcc/testsuite/gfortran.dg/coarray/select_type_1.f90 new file mode 100644 index 00000000000..7f12fb9aec7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray/select_type_1.f90 @@ -0,0 +1,34 @@ +!{ dg-do run } + +! Check PR46371 is fixed. +! Contributed by Tobias Burnus + +program pr46371 + type :: foo + integer :: i = 0 + end type + + class(foo), allocatable :: o_foo[:] + integer :: j + + allocate(foo :: o_foo[*]) + if (this_image() == 1) then + + select type(a => o_foo) + type is(foo) + j = a[1]%i + a[1]%i = 3 + end select + + if (j /= 0) stop 1 + + select type(o_foo) + type is(foo) + j = o_foo[1]%i + end select + + if (o_foo[1]%i /= 3) stop 2 + if (j /= 3) stop 3 + end if +end program pr46371 + diff --git a/gcc/testsuite/gfortran.dg/coarray/select_type_2.f90 b/gcc/testsuite/gfortran.dg/coarray/select_type_2.f90 new file mode 100644 index 00000000000..1694d095708 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray/select_type_2.f90 @@ -0,0 +1,19 @@ +!{ dg-do compile } + +! Check PR46371 is fixed. +! Contributed by Tobias Burnus + +program pr46371 + type :: foo + integer :: i = 0 + end type + + class(foo), allocatable :: o_foo[:] + integer :: j + + select type(a => o_foo[2]) !{ dg-error "must not be coindexed" } + type is(foo) + j = a%i + end select +end program pr46371 + diff --git a/gcc/testsuite/gfortran.dg/coarray/select_type_3.f90 b/gcc/testsuite/gfortran.dg/coarray/select_type_3.f90 new file mode 100644 index 00000000000..50f27893ccc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray/select_type_3.f90 @@ -0,0 +1,23 @@ +!{ dg-do run } + +! Check pr56496 is fixed. +! Contributed by Tobias Burnus + +program pr56496 + + class(*), allocatable :: a[:] + + allocate(integer :: a[*]) + select type(a) + type is (integer) + a= 5 + if (a /= 5) stop 1 + end select + + select type(a) + type is (integer) + if (a /= 5) stop 2 + end select + +end + -- 2.46.0