From patchwork Sat Jan 27 17:06:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1891800 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=anlauf@gmx.de header.a=rsa-sha256 header.s=s31663417 header.b=Q/cwLV9R; 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 4TMgwV54TSz23fJ for ; Sun, 28 Jan 2024 04:07:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 234223858287 for ; Sat, 27 Jan 2024 17:07:19 +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.17.21]) by sourceware.org (Postfix) with ESMTPS id 2153A3858D28; Sat, 27 Jan 2024 17:06:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2153A3858D28 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 2153A3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706375214; cv=none; b=yDLsNKtafeT8QGv/NqzpYuAz7ndQTv8bwrwBi7WtGjqAtdZPy7a0ReoiCGkpgdoMqRSB9+2t0Ch7o63vOvWFAt76BpENsKCDJmRRbPljBriQEf7vzWRVoS8KBjqZN4SAU9eEnASffD0jzc0AUiIpCnJUR+Dvza4M9def5g1Sar8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706375214; c=relaxed/simple; bh=4WixQQCiTma2w4tlKT1f8KLfEh3Rfh1/xVJEaChq+Uw=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=E93d5oSnKS2JTsSM2LLG/ZeigerA6OpTNdZ9dCtH/wCS9bE4JOfLkzcJ8gouCrqXnnGbU/5Dek+ueANTmCkEm8JnGUSD+hgWpaT917+bqLDnX8JtzAqWZwNVyI/p5mMipQzY1P7OhRAEqDD6TlEOjEIfc/iz9rn887k1SSCWnnA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1706375210; x=1706980010; i=anlauf@gmx.de; bh=4WixQQCiTma2w4tlKT1f8KLfEh3Rfh1/xVJEaChq+Uw=; h=X-UI-Sender-Class:From:To:Subject:Date; b=Q/cwLV9RoWCzyK3roatVlZyQxMhrzpmhU9Rd1Zg6EzI1oa0ZPZDDeCiA1QlEDGRp ttFCE563O0BLuFNtJTNRy7ByR8F6pABbKsrq3ZfpF5oQSfTM3ojFWA4MTelaYlQth WE9C7oYt3dzeO4Wv6rVH2INeIty80bWrAnj7H/XrpfV47i63Hco9lSVhkvKv3wV7V 04Gr/BFJl+nnNhvDQm3CGyzgMg7uif/Y26Jt2/KtBJewkY6DjOYzlQ8Wb8DPbrcYf 6NlAdeMmN5OIXVJd3BPNd+uagXyzI/j8tHzYcKPxMsUb9P9aFTCrqC1/7b0A3pHsf ouZ2xJLpL00IMc/jQQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.89.67] ([93.207.89.67]) by web-mail.gmx.net (3c-app-gmx-bap50.server.lan [172.19.172.120]) (via HTTP); Sat, 27 Jan 2024 18:06:50 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH, committed] Fortran: fix bounds-checking errors for CLASS array dummies [PR104908] Date: Sat, 27 Jan 2024 18:06:50 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:qPK9gl1gynX5D6GlRv/CepCMgQtegEN+jaPNeDmkU57ASY/DoRAf1QDbIsbbcJAbCuYy8 YAmUq3WqcD1HofWuzGssC4ZTapRQsKQgjCcXZhj6kbtbVhZqXs61DLzbb0mh8QV2Aobz7D7NVbWr 0s9gPnCQuEVBC+MV4JVscliEvoAPWSytdLdR3BO9hbrrBD2XaAjxcl+btqzgXBJMSeqIiZCpkfrZ ignxxiqJA8cs5qKuFAT50iGBE7eVRBNecCPROXVVCr3ZpVsEj1qFVURx2+T8r8tvXJVq18Uo322q 58= UI-OutboundReport: notjunk:1;M01:P0:FEcVF7g2hik=;l81jffd9wXFXiqljPv9SaHNjz8/ 18RXqhu9/VF9X2q34rTqPsFxUNHWYvqAMm7f6kepKSR3vXsezkTsCt44e4j6SeLXvNG6hHOGJ 1xF1+Y7nKgYbbxgmRLDF2YpFsVdNvFD0+95UELvuVgC++RC9IbPETVwsfm6i1UxQaXJWCqBnS iqtv+H24pyzEUCXkScrrGresifIr9OaHOnqk2rXMOGJa74uDvb/9Hq9A45dRRosIILPfDQBQ1 S2wjIEmLP5yoR7PHpy0F9ncxwKIPIq6oYkyQZTftF3c9peluOrU3zvDZ23NI4cL87QcA0cE+y Y9VckSmuH6ulgUEzi382NVc5Ai6cWvpGfJaLUs3MQbDzWG0G0DjmV1Nhdf+T9d7bkN/rPHyfN PPtHEiZOsPBMcDpxgrEaL5f/dCJemWOrSUcVDBc+WR1v/m2tgE6eA/mP3jGCWgUuLXSwas5ro YONdG4jdH0oAI/m7Zxy05m0dwFZ3R8Y8lJ+CP9qASQpnBHSLs2Qp6pkqhk78MiLv7uY+SVawm XyJO+08sBDJvop7uoUSWaCzhh73NXpgAUj+9T2UjO/3Q4cF1LF7t0hDlFEdorMROx3oum2vbS yVu3Ar93yM1aXs+sHmjhouKNjGPyZ9lpEnVi7cCAZfJpXBPs3WNRHvVUXt8Yltqlc47JiU7mt +0YzxzRqWA5yBk4qn0UxKPPpSDa6RkcU5q8WqFGEervCVnV4xYfXKBLmSeTGUYPBbRK7CsaWq k8jF31sgR8SyQ4UevWCoVI21phvEAZJpj3wPjHgAvmOUmElFm1GIWITZgXt6cbViPbpeBtYZC T0U62b4eEb8/OuxnlHmeBTCg== X-Spam-Status: No, score=-12.5 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_H4, 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 Dear all, commit r11-1235 for pr95331 addressed array bounds issues with unlimited polymorphic array dummies, but caused regressions for CLASS array dummies that lead to either wrong code with bounds-checking, or an ICE. The solution is simple: add a check whether the dummy is unlimited polymorphic and otherwise restore the previous behavior. The attached patch regtested fine on x86_64-pc-linux-gnu and was OK'ed in the PR by Jerry. Pushed as: r14-8471-gce61de1b8a1bb3 Since this is a 11/12/13/14 regression and appears safe otherwise, I intend to backport as suitable, unless there are comments. Thanks, Harald From ce61de1b8a1bb3a22118e900376f380768f2ba59 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sat, 27 Jan 2024 17:41:43 +0100 Subject: [PATCH] Fortran: fix bounds-checking errors for CLASS array dummies [PR104908] Commit r11-1235 addressed issues with bounds of unlimited polymorphic array dummies. However, using the descriptor from sym->backend_decl does break the case of CLASS array dummies. The obvious solution is to restrict the fix to the unlimited polymorphic case, thus keeping the original descriptor in the ordinary case. gcc/fortran/ChangeLog: PR fortran/104908 * trans-array.cc (gfc_conv_array_ref): Restrict use of transformed descriptor (sym->backend_decl) to the unlimited polymorphic case. gcc/testsuite/ChangeLog: PR fortran/104908 * gfortran.dg/pr104908.f90: New test. --- gcc/fortran/trans-array.cc | 5 +++- gcc/testsuite/gfortran.dg/pr104908.f90 | 32 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr104908.f90 diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 878a92aff18..1e0d698a949 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -4063,7 +4063,10 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_expr *expr, } decl = se->expr; - if (IS_CLASS_ARRAY (sym) && sym->attr.dummy && ar->as->type != AS_DEFERRED) + if (UNLIMITED_POLY(sym) + && IS_CLASS_ARRAY (sym) + && sym->attr.dummy + && ar->as->type != AS_DEFERRED) decl = sym->backend_decl; cst_offset = offset = gfc_index_zero_node; diff --git a/gcc/testsuite/gfortran.dg/pr104908.f90 b/gcc/testsuite/gfortran.dg/pr104908.f90 new file mode 100644 index 00000000000..c3a30b0003c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr104908.f90 @@ -0,0 +1,32 @@ +! { dg-do compile } +! { dg-additional-options "-fcheck=bounds -fdump-tree-original" } +! +! PR fortran/104908 - incorrect out-of-bounds runtime error + +program test + implicit none + type vec + integer :: x(3) = [2,4,6] + end type vec + type(vec) :: w(2) + call sub(w) +contains + subroutine sub (v) + class(vec), intent(in) :: v(:) + integer :: k, q(3) + q = [ (v(1)%x(k), k = 1, 3) ] ! <-- was failing here after r11-1235 + print *, q + end +end + +subroutine sub2 (zz) + implicit none + type vec + integer :: x(2,1) + end type vec + class(vec), intent(in) :: zz(:) ! used to ICE after r11-1235 + integer :: k + k = zz(1)%x(2,1) +end + +! { dg-final { scan-tree-dump-times " above upper bound " 4 "original" } } -- 2.35.3