public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4688] Fortran: out of bounds access with nested implied-do IO [PR111837]
@ 2023-10-17 17:06 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2023-10-17 17:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5ac63ec5da2e93226457bea4dbb3a4f78d5d82c2

commit r14-4688-g5ac63ec5da2e93226457bea4dbb3a4f78d5d82c2
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Oct 16 21:02:20 2023 +0200

    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.

Diff:
---
 gcc/fortran/frontend-passes.cc                |  2 +-
 gcc/testsuite/gfortran.dg/implied_do_io_8.f90 | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index 136a292807d3..536884b13f09 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 000000000000..c66a0f6fde66
--- /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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-17 17:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-17 17:06 [gcc r14-4688] Fortran: out of bounds access with nested implied-do IO [PR111837] Harald Anlauf

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).