public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-11071] Fortran: out of bounds access with nested implied-do IO [PR111837] Date: Sat, 21 Oct 2023 20:22:15 +0000 (GMT) [thread overview] Message-ID: <20231021202215.897EE3858C54@sourceware.org> (raw) https://gcc.gnu.org/g:9b569e0a1cf79519eea2e62422232c8d2d483f07 commit r11-11071-g9b569e0a1cf79519eea2e62422232c8d2d483f07 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.c (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. (cherry picked from commit 5ac63ec5da2e93226457bea4dbb3a4f78d5d82c2) Diff: --- gcc/fortran/frontend-passes.c | 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.c b/gcc/fortran/frontend-passes.c index ad1ba397803a..ebc5a7f36995 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -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
reply other threads:[~2023-10-21 20:22 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20231021202215.897EE3858C54@sourceware.org \ --to=anlauf@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).