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: 193076 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2395:b0:106:343:edcb with SMTP id gw21csp611137dyb; Sat, 27 Jan 2024 10:11:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEAB0RZJQMLnFEKjO3fM+R3cnWRDBVc65k3NlLc1sT9WX/xW9drUNnnXEuAk0akLb8AHseO X-Received: by 2002:a37:c44c:0:b0:783:e224:5b29 with SMTP id h12-20020a37c44c000000b00783e2245b29mr1767818qkm.114.1706379070202; Sat, 27 Jan 2024 10:11:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706379070; cv=pass; d=google.com; s=arc-20160816; b=s72GDX7HyFPN4u6hJTFf9L3EndILqdd4DvCpzXhfQz8FlF13OBuhK6hTWcfZ5uPn3a X5K4rhyWfJy+KPP1nZdWIlPHM72JJGi4LRBXsa9RmVEtllEwEWeY8/Y5Wz63KHMHxBYX AwoJKXhPGva8+eorKH+ExTdJH88v7/tdcLSmwgQZZ5mvsJboFxRuxKwAVxf8NUNgleSi SwUGYsa3ja+TmBs6pMOmc2Fgy5fLBlaMI0PA2o2liwx4v8lacWEBn2dTayRwHp/yxahn gEpvc1l2cXCXsOC+aFb5zOGNx0VlfVD4NOUhuEkkRxGlD/z/nfntaJ/LjFA1BEVILp4F g0YA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:ui-outboundreport:sensitivity :importance:date:subject:to:from:message-id:mime-version :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=ji6Hg2CqxYpZVh96kP2JkEDBH9JBIFL6dM13Ujboyc0=; fh=+IEfvAe+9BRgPHWhQEl2uIBTtAiiGDh1ExRZeB5JJoc=; b=ntK9tOVDuLzx1So1F1vthL/pRZXniuTkhfnbP4vMKAftMF3NNLklaW+G50sjicvFlj sxajdXx+EcTm9GnT0ZwUzz7Ml2epQX1nD4bPzH96TUjHe6T/X6r0PkTY86TwmJUlSajC y+9re6tnGnatuVDUmlByesU1AMoDNgAoDb/6wPaoVAzrpKzQkh+O0H9t2tcPvsU9LJcs IXAouFjlh5slyV9UxG/dIiEwh4xij8rqHd+/UAHq1oV0NvpSaY1HN8VJzEiBttTFD4wI oVLPgLJoxMqy7P5M35Jno9wspGmsqkFxiZrGHN5LLwoYKQrIvhdgWSaeGcEJuWRnLThB 7qKg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b="Q/cwLV9R"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id os17-20020a05620a811100b00783c5a29ec8si3958608qkn.194.2024.01.27.10.11.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 10:11:10 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b="Q/cwLV9R"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB0AD3858420 for ; Sat, 27 Jan 2024 17:07:39 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789268140109537520 X-GMAIL-MSGID: 1789268140109537520 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