From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fortran: out of bounds access with nested implied-do IO [PR111837]
Date: Mon, 16 Oct 2023 21:11:43 +0200 [thread overview]
Message-ID: <trinity-327edd0e-7e3a-45b6-9546-0df8a1315f96-1697483503726@3c-app-gmx-bap45> (raw)
[-- Attachment #1: Type: text/plain, Size: 394 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr111837.diff --]
[-- Type: text/x-patch, Size: 2125 bytes --]
From 43ec8b856a67a1b70744e5c0d50ea7fa2dd9a8ee Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
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
next reply other threads:[~2023-10-16 19:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-16 19:11 Harald Anlauf [this message]
2023-10-17 0:32 ` Jerry D
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-327edd0e-7e3a-45b6-9546-0df8a1315f96-1697483503726@3c-app-gmx-bap45 \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).