From patchwork Fri Jan 19 20:32:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 189680 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1295358dyb; Fri, 19 Jan 2024 13:37:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEcqHF+IppVxxxAzVSypqHHrt4XHg1NBWyd7mxgqI+YngzN2a7uWLEn0Pp7KXK2ENnwYy3 X-Received: by 2002:a05:620a:2a14:b0:783:71fa:5366 with SMTP id o20-20020a05620a2a1400b0078371fa5366mr581845qkp.92.1705700253577; Fri, 19 Jan 2024 13:37:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705700253; cv=pass; d=google.com; s=arc-20160816; b=tEKeDfUBUFGWqdSwVy+MHrHkd2XG8OT/Gg6jec2y+p2UknB7KYN/56k9vPL02Ep5wH LcJTGsQIch8SFc3oAW1ElsOdgMjb+V+faA/GvHQMwdPQvaqj7zKj9OWrXAxH7f6sTX7q xiGYlpMCxKs2hfONRa8h/b20SS6ZR+OAmtra5QlTXylCMj13VzsDjhTG7Dnq0SHyDlhY Ndfdq7MUh0pJtFoqiHs00VmcJmJt3IK0gvAKNIhb6GPJKVyVtHb54tz79BiBlZrnTdev 5eVW8JHpM5UnsMqyYd4yK10U7DdWkZUmsnUoLZG4stNi9xfX6U8SG4EFkSx8rpyTCEtl yd9Q== 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=ML1eGchIMAWixcXa+XsCjXwEtP12mrOJkxC5LB0sPm0=; fh=+IEfvAe+9BRgPHWhQEl2uIBTtAiiGDh1ExRZeB5JJoc=; b=c70XjYhCmrgFJRe1MVl9hOneeT/m1cFmW6cS8lqAReHyFkEGEDCZgZ+Orr+NMESYNW J6Ba5LVnsbT30kGjch386HexYskdHVV9xBPDNF7dVCajw0bNttH3yQVK98mPFEht2YCE TOZorW5JgCqXP7riixRo43HNWJLrUCkMn7zNNWwNRrzoNwGAG2vwCfsYOz9UJFME09l0 3Tsp0+0ghnP8I8YNDshf7hl+m+u+pETQIC1v76C49eTP9RT3bQNvJOfLckyQJF4D2CGD M27kHI+XHLBGxAqMB5huSvAy7bLuqYHZqxZAtbRiAsDn/BE93+0sC4VUFTf6+w9AF+jd MDbA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=SrfgATKo; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id oq6-20020a05620a610600b0078322a5d4a0si119040qkn.473.2024.01.19.13.37.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 13:37:33 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=SrfgATKo; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 5B7703857831 for ; Fri, 19 Jan 2024 20:33:43 +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 2C2943857C4A; Fri, 19 Jan 2024 20:32:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C2943857C4A 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 2C2943857C4A 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=1705696381; cv=none; b=HO7QGCeDTXzhJABsoWaTniCAi70H2hXLmsIG71s6lAqt4I8I+OSU6g//b+gbuwmGC/ailW9AzXCxF3/U1xgopGD4ur58jcjhsJ9pUesMn9xYdu+MFITRAYofHuDXSwJ3VhsE5BRHCv1iYEP83ALk0kdzVoCR0L6Aw16zszy1cKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705696381; c=relaxed/simple; bh=riINEDw0PVnulxKUGtHLQhdPBIp4CP3q98EDs8PLXjM=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=O9wCz01Yl1tI2ge2WPTEfvxKkyKXsg+MSWSqrHixLE12U/4YoI29EkzwUQFQVIHhhWEGWIr0Egjo+8L/iBtNk5tAxqvsSv2CvaZaFIxlkGJJkOVxnnIb23SX0Gt1O7/j7ag5cjC4VpwuiO+sEzOpz2tIW/q7IR+utOVDHAPe0os= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1705696377; x=1706301177; i=anlauf@gmx.de; bh=riINEDw0PVnulxKUGtHLQhdPBIp4CP3q98EDs8PLXjM=; h=X-UI-Sender-Class:From:To:Subject:Date; b=SrfgATKo430jjuY9xYlxmEEEVsEo84K52ai1CnbpvypS0r9gz/4tKjX5AtXMsXOM i6dKHaho4Jr9ius11Ba3SS5JltQcM198CsUp/JIeP4BWpKAqvpVtGrAv34TboT/YD SLjOaQ/ThRS03kXtcuFLRHaM/9IePfix4aVIeTW3Bg1mq430jCaa5skPDiVzX695/ fZkf0fcLGbcrqkELNHtzLS2tMSB0O6Kxy0AaWNj8JU6T3Ng7SJm1t/bxpZMtAnmff JeroRYayyXSqjJtKUEU1fgaglNXVE4LC6doBVI1k3i0BK2wedmspZRfaTWFrYP/8M MYywpeMKlsra994w3g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.83.237] ([93.207.83.237]) by web-mail.gmx.net (3c-app-gmx-bap08.server.lan [172.19.172.78]) (via HTTP); Fri, 19 Jan 2024 21:32:57 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH, committed] Fortran: fix wrong array bounds check [PR113471] Date: Fri, 19 Jan 2024 21:32:57 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:gHTnYNqpAx3M3kpWi/j/+Fe4mIK4RwJWkLMk4Yc6f1wwKRv/3gzcfY5nacvjSxxAJ7fdS tUR3nnda9UfnsLlzXFXh9YzphVxch3x/xcM56iPNS5IGkRafCmK+d6txQgmkio/MsDgaitBoTq5A hJwBbovHClPFp4x07Mt12aO0PQjvHNm+2plzpzShXngdNAXZAkCfPDeMMwrmGmJxyX1EZqeTbbVQ D+WjnBsUAMZom4Ba7WEPjrSleXmjo8LpI0gfF4p0D8PyS1xz502cK2Uf/Jnv09CDqTQX5lGZeq1G Fk= UI-OutboundReport: notjunk:1;M01:P0:ihyHMknhaBQ=;FCpNYWw2+vPE6eY7VIZWZpTiwfR UqIIJTtnN55N6IpQl4TQS9ExAs4h5ywsDXE/vYG03JsvqZrr3NWo6PEiIZIPN80P6SReuIcs8 hsFPCzGOj8XPfFBNx3vekwHbkoXPtf8xrAgQ/GTMnNDxmDPeGu9ElnUciUWo4xtBr3g/evH5M mr7ygGxyoG05n2GsZ3ceOuEukjpFXqq34gu02x1B9cIuuZcDG3ryedRZsVevJlFBRBq13hM04 9irZY774bSIOcBXZxGq3BOzH7w/jcb2xq0aC6CWDiHyreGz2m//cRAFGdKKZBxBdFV116ewhC aOn+0smBwuaMYAHDXAqNea/httrmumBhW0KXUg3uBz0nFVQLqRc0Wz8zb+KDrnOtOpA1zki++ T3utp8HVIYm03ALQNIjzvmH2S6/fiO6IhrxxC1dA7Ez3qHLyceHCBP4XgpYBWw0QkbFLKn70M hk7lb7qGbN7rBAlQaUtX2/wLSLJy26iJbHcvrtqzpaHZ1zgkxvcIwNjOCGgJpvc4t/2S7TrFN 9ezE469YhPBR0Ip14Blvnl/uCWIMFs+/kS2XfNYINct5syuqKkWAVYClsr+rJwhCJ+sjfi4FN 5EQ33AKKo2A3cYj1H05Awye8DsBrHz0AOfta9uhvsY8sCgxiwhKcJiclzTDkPhEJzkq634KgM nJFn98AQMw7pTApRKxIgK4nFDCTueYCCPHdK5pJXYtdoXwfIbYN8OCeyuXR+O4OE7AKmeYCcI H2dyVss4LXTsL3SzeL0Sm9UTr5S4nPx41C66UdkGr3BAgItbTS+bPwSLNSbeuKyAFAz0gfrM4 49tVHq+dxt0x/UulC2Tiuklw== 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, KAM_SHORT, 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: 1788556349083126514 X-GMAIL-MSGID: 1788556349083126514 Dear all, I've pushed the attached obvious patch for a regression due to a wrong array bounds check after regtesting on x86_64-pc-linux-gnu and verification of the fix by the reporter in the PR. https://gcc.gnu.org/g:94b2e6cb1cc4feb122bf77f19a657c97bffa9b42 Thanks, Harald From 94b2e6cb1cc4feb122bf77f19a657c97bffa9b42 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Fri, 19 Jan 2024 21:20:44 +0100 Subject: [PATCH] Fortran: fix wrong array bounds check [PR113471] gcc/fortran/ChangeLog: PR fortran/113471 * trans-array.cc (array_bound_check_elemental): Array bounds check shall apply here to elemental dimensions of an array section only. gcc/testsuite/ChangeLog: PR fortran/113471 * gfortran.dg/bounds_check_24.f90: New test. --- gcc/fortran/trans-array.cc | 2 +- gcc/testsuite/gfortran.dg/bounds_check_24.f90 | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/bounds_check_24.f90 diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 26e7adaa03f..878a92aff18 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -3600,7 +3600,7 @@ array_bound_check_elemental (gfc_se * se, gfc_ss * ss, gfc_expr * expr) continue; } - if (ref->type == REF_ARRAY && ref->u.ar.dimen > 0) + if (ref->type == REF_ARRAY && ref->u.ar.type == AR_SECTION) { ar = &ref->u.ar; for (dim = 0; dim < ar->dimen; dim++) diff --git a/gcc/testsuite/gfortran.dg/bounds_check_24.f90 b/gcc/testsuite/gfortran.dg/bounds_check_24.f90 new file mode 100644 index 00000000000..d0251e8455b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bounds_check_24.f90 @@ -0,0 +1,28 @@ +! { dg-do compile } +! { dg-additional-options "-fcheck=bounds -fdump-tree-original" } +! +! PR fortran/113471 - wrong array bounds check + +program pr113471 + implicit none + type t + integer, dimension(2) :: c1 = 0 + end type t + type(t) :: cc(7), bb(7) + integer :: kk = 1 + + ! no bounds check (can be determined at compile time): + call foo (cc(7)% c1) + + ! bounds check involving kk, but no "outside of expected range" + call foo (bb(kk)% c1) + +contains + subroutine foo (c) + integer, intent(in) :: c(:) + end +end + +! { dg-final { scan-tree-dump-times "below lower bound" 2 "original" } } +! { dg-final { scan-tree-dump-times "above upper bound" 2 "original" } } +! { dg-final { scan-tree-dump-not "outside of expected range" "original" } } -- 2.35.3