From patchwork Mon Oct 16 19:11:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 153721 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3670498vqb; Mon, 16 Oct 2023 12:12:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0qH4W8rl4+m6kU85w5JyzPZ4kPJhPfNCDPd5HG0fY3LkKq6xMfUQbKHbvT9ZUHFTXMTBE X-Received: by 2002:a05:622a:1455:b0:405:45e1:de14 with SMTP id v21-20020a05622a145500b0040545e1de14mr251998qtx.27.1697483530890; Mon, 16 Oct 2023 12:12:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697483530; cv=pass; d=google.com; s=arc-20160816; b=iCRtT/awOOYwR0TI2OIqa7n9eSWQnM/oA2PrjXWOjk8KrG9i+iBsciPsAKTf6s20iV 81fXLshXblbqoxv2ct1sVBAPhwPfIfcQDEVVulwsC8dUl4VCLBmv9qQm4pncSbC0meB0 1N2f4vltmmgz4Cb1lS1/l8ZZ+A93fXhOsbQ6nQKnieM9VlQTCeWr75Zs+EqWdMxXx7dx FcKbYDIuFyDEHxzJMtj1JnNHYxlrEMxE58Kgi09yOrZkghQ8BsLCNMDwJhuBKPgF8ptF oZVBJiGfIJLrdBD0Xnnddg9QRQAnFzkgV2qfnHDf/vY1EumrzuuC5HRg0Q+8Nxc7QxZO o95g== 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=S4jB9az3j9I3HLhVNSsDv1NSSWjwLTUAeYniTpjPM9k=; fh=+IEfvAe+9BRgPHWhQEl2uIBTtAiiGDh1ExRZeB5JJoc=; b=bGeAtPOEH+Kjf2cTf6AApYBMQXD7ehwbubd8YLWfNf8fqDIlcX90L+pRnvbROqj8Br SspjPLZkA36CIuTdnxE0XxGuCOeaWULP5LUNDU/7NOj7b5r2Yw0RDDkyxKlWFM85SKRu P6ADja83DXULn+0zzJuOytlf/nNu6s59WI7ZqRyWhS9m5/vMmFbr8LoYvvbxvJTcTbF3 E14eTHGACtF/aS68Ql+UUdc/bhY/1TXRQl0DADHYsyp0SqFyUMcqgBiBR0vTYXFta/9g oI0OZjqapjVC6v1PTOcQSc8bW0f1MLjQP4PbUccFwOKRJRU6t+grpcf7q4ocH4+HsL6j oIbw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=tsv2UNZn; 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=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p18-20020a05622a049200b0040306253e31si5839809qtx.416.2023.10.16.12.12.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 12:12:10 -0700 (PDT) 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=tsv2UNZn; 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=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4531B3857355 for ; Mon, 16 Oct 2023 19:12:10 +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.20]) by sourceware.org (Postfix) with ESMTPS id F0FED3858C54; Mon, 16 Oct 2023 19:11:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F0FED3858C54 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 F0FED3858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697483506; cv=none; b=DYZeKs0Tq/SaOgqO1GNTUKM6kzxlfgPXn7aFjLYyGNJu1K+4m8cG5SR3RsRddQIcsDvCxYIxTUH3AtBdRzQcotIeLRSEhIX6vlTXz1I3RqeFXbW+larmID6JcqESns+4lwygZUUkNe3h1ikzhtzyGmkGsF5Y1LxMXEFnYlIQvPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697483506; c=relaxed/simple; bh=xjXDtvItLfhyZpG/PqoQ9kIi2XWAtaBBfZOc7sZONnk=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=lb7l3NBNE05D2HkRz0Dp9sLooQV5bAqceGEdTsLNn1Dwps3Wce4HS4EN/HI7hV/QMQLvm4j8ukIAbFdhZ7ufw6/IJS03DbeagZOX69xHhjSPk8MjBiPO0UJ7a4FVpHtGNi+sd0sLfeY8VW4qW5LtlMiaF2OUG9Bb3LQh9I5lfQc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1697483503; x=1698088303; i=anlauf@gmx.de; bh=xjXDtvItLfhyZpG/PqoQ9kIi2XWAtaBBfZOc7sZONnk=; h=X-UI-Sender-Class:From:To:Subject:Date; b=tsv2UNZnjLQkHw+cZCuMAw1sXcAPxyzRn/exvnCR6Tep4lT37K4ZwCyfmhrE7iOFPM3quvFFCoV NCW8nbhybioZDWaGOHit1wbCBjeImaxEsLqm6swapFr8MbFPplNT8bQoWehCUi4Wh3dNjoe5Pk7Oc 5bqQi+DKhXY6FTW9kgYLwLJLC9Dy7v4qVE6+StrEAv7Mr4QHgVxunpKDTLNbmP9qkOPkrf7IVqlpL 3qDvV+lcItmMMNIYXQLydRUHe4ss2zcSQ+FyNLd/dRJAUG89sxmpXsJTn36Q8EBKM+RkigkPWZfAJ YpUXm9P0rfVVMOB9QGLhnOiqDA3fEwImH8Kg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.82.75] ([93.207.82.75]) by web-mail.gmx.net (3c-app-gmx-bap45.server.lan [172.19.172.115]) (via HTTP); Mon, 16 Oct 2023 21:11:43 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: out of bounds access with nested implied-do IO [PR111837] Date: Mon, 16 Oct 2023 21:11:43 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:LWS6vRd2hPvkFZ/PTY/E6xkT9LGAwCfY4S+RHj6K0uwbWAeW8JU2+aLdp4Rucr+JZNTQ7 pqR/feEPWIfm1UbmTxSEEzvxvwjle65jEA7SXvnhiSndruUdO1DWf/UUgMGHkPrdyhdkWz4dem02 HSPi1VjfpkuuygCKmMhwF1U6XFmd74FS9MQsxFjjRFSe6eJij+WIIHqhsNex5TflwvuDLprs081P t1+U3GM6fc++ylNoStiWj9E+gHwGSFZ6VUf4a95ZrUfAalbSM+aAv8dv6Fx3G6jBIY+xhjv0hDFv L8= UI-OutboundReport: notjunk:1;M01:P0:zejxX6Nb31E=;OCZkG9tG2LcYA30uguQBabKrovP QsZOTqIlDNmUzc99EoqFRZXupa4RqIYPxPFnMUUtJvTLTKLqhfua7mk4AFGOMYle5CDg1olz1 eYaQfXbq0YUVaU8aI2pJkAGeCksuPDyzQV0zCjO3OqTJpQOXceUk7dgs3nNoIlysw4QA3l0FL gF0XB7djhJWkCetRF0/3DYRCdr4oSB3LJso+gExap9c8AjUnt5mP4+u1e+ksgQIKYmT1Q0Wuv Fl2ofPK/Zy+mzpSZXUhFIKFy5PUP/Umf/pvD2F6ZWuQtD6J+mxQ7y/dqA7LEh22X2oBJnS79K u4/K//0dGK3MwhSu7caJ+14QCKJkCyqNKCuuPf+hYmgxatgarfGPmhVVQP16H9g+1hBOUAh2Q oOtB80cN3zoCJ7M7tiPmzx7nC5H90R6jLX5TKwx25mH7nGwKE+3dQZ664C1lhuBElTfdWI+1k UZwxq0veJyDZd7AtkY9vYjV9rPe1cqKtCEm/AxySJ18V54QblUy07zwU6ZYTsDeA/trogt6HN JQkRzN71FQjy1eDOBfJ9sTVN5WMTB65VvjJkZMK4ZcStgOIIBabN9ckEkguq9+LIDQ+4sFxJe Csv/PrDZ2InJfC5UM5wwtxlDq8Ycwtov3Mn/O3VR3ZnIGkk59vnNGD1jwJOgwbvXIUplqe4+2 kAe/VuVcBFehAqeRMtSE+1TOw78Gma+USKI69eMA2zF68/QRFNSwH19bMggpDRialszxbfC1Q jsd7waVq1VGLY9mbU7Gg7PQQ1d9u+1ljXa3fPazfoiFBFQICzMENF7lHJN1dMCL7Y4HPSS65M mK6sr/Vz1CODhtfBtcIfIhKw== X-Spam-Status: No, score=-11.8 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 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: 1779940490973061390 X-GMAIL-MSGID: 1779940490973061390 Dear All, the attached patch fixes a dependency check in frontend optimzation for nested implied-do IO. The problem appeared for >= 3 loops only as the check considered dependencies to be only of band form instead of triangular form. Regtested on x86_64-pc-linux-gnu. OK for mainline? As this fixes a regression since 8-release, I plan to backport to all active branches. Thanks, Harald From 43ec8b856a67a1b70744e5c0d50ea7fa2dd9a8ee Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 16 Oct 2023 21:02:20 +0200 Subject: [PATCH] Fortran: out of bounds access with nested implied-do IO [PR111837] gcc/fortran/ChangeLog: PR fortran/111837 * frontend-passes.cc (traverse_io_block): Dependency check of loop nest shall be triangular, not banded. gcc/testsuite/ChangeLog: PR fortran/111837 * gfortran.dg/implied_do_io_8.f90: New test. --- gcc/fortran/frontend-passes.cc | 2 +- gcc/testsuite/gfortran.dg/implied_do_io_8.f90 | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/implied_do_io_8.f90 diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc index 136a292807d..536884b13f0 100644 --- a/gcc/fortran/frontend-passes.cc +++ b/gcc/fortran/frontend-passes.cc @@ -1326,7 +1326,7 @@ traverse_io_block (gfc_code *code, bool *has_reached, gfc_code *prev) if (iters[i]) { gfc_expr *var = iters[i]->var; - for (int j = i - 1; j < i; j++) + for (int j = 0; j < i; j++) { if (iters[j] && (var_in_expr (var, iters[j]->start) diff --git a/gcc/testsuite/gfortran.dg/implied_do_io_8.f90 b/gcc/testsuite/gfortran.dg/implied_do_io_8.f90 new file mode 100644 index 00000000000..c66a0f6fde6 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/implied_do_io_8.f90 @@ -0,0 +1,18 @@ +! { dg-do run } +! { dg-additional-options "-fcheck=bounds" } +! PR fortran/111837 - out of bounds access with front-end optimization + +program implied_do_bug + implicit none + integer :: i,j,k + real :: arr(1,1,1) + integer :: ni(1) + ni(1) = 1 + arr = 1 + write(*,*) (((arr(i,j,k), i=1,ni(k)), k=1,1), j=1,1) + write(*,*) (((arr(i,j,k), i=1,ni(k)), j=1,1), k=1,1) + write(*,*) (((arr(k,i,j), i=1,ni(k)), k=1,1), j=1,1) + write(*,*) (((arr(k,i,j), i=1,ni(k)), j=1,1), k=1,1) + write(*,*) (((arr(j,k,i), i=1,ni(k)), k=1,1), j=1,1) + write(*,*) (((arr(j,k,i), i=1,ni(k)), j=1,1), k=1,1) +end -- 2.35.3