From 35ca2d4ea7495018ae7c378e10baaa6eb2dbd06f Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Tue, 13 Aug 2019 18:43:00 +0000 Subject: [PATCH] re PR fortran/90563 (Out of bounds error when compiling with -Wextra) 2013-08-13 Thomas Koenig PR fortran/90563 * frontend-passes.c (insert_index): Suppress errors while simplifying the resulting expression. 2013-08-13 Thomas Koenig PR fortran/90563 * gfortran.dg/do_subsript_5.f90: New test. From-SVN: r274394 --- gcc/fortran/ChangeLog | 8 +++++++- gcc/fortran/frontend-passes.c | 5 +++++ gcc/testsuite/ChangeLog | 7 ++++++- gcc/testsuite/gfortran.dg/do_subscript_5.f90 | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/do_subscript_5.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 6a908eb88a0..08908d26d92 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,7 +1,13 @@ +2013-08-13 Thomas Koenig + + PR fortran/90563 + * frontend-passes.c (insert_index): Suppress errors while + simplifying the resulting expression. + 2019-08-13 Steven G. Kargl PR fortran/89647 - resolve.c (resolve_typebound_procedure): Allow host associated + resolve.c (resolve_typebound_procedure): Allow host associated procedure to be a binding target. While here, wrap long line. 2019-08-13 Steven G. Kargl diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 37c767f96f2..be99a06c3fc 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -2518,7 +2518,12 @@ insert_index (gfc_expr *e, gfc_symbol *sym, mpz_t val, mpz_t ret) data.sym = sym; mpz_init_set (data.val, val); gfc_expr_walker (&n, callback_insert_index, (void *) &data); + + /* Suppress errors here - we could get errors here such as an + out of bounds access for arrays, see PR 90563. */ + gfc_push_suppress_errors (); gfc_simplify_expr (n, 0); + gfc_pop_suppress_errors (); if (n->expr_type == EXPR_CONSTANT) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e7ec05b55bc..4514664a751 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-08-13 Thomas Koenig + + PR fortran/90563 + * gfortran.dg/do_subsript_5.f90: New test. + 2019-08-13 Steven G. Kargl PR fortran/89647 @@ -22,7 +27,7 @@ * gnat.dg/casesi.ad[bs], test_casesi.adb: New test. -2019-08-13 Wilco Dijkstra +2019-08-13 Wilco Dijkstra PR target/81800 * gcc.target/aarch64/no-inline-lrint_3.c: New test. diff --git a/gcc/testsuite/gfortran.dg/do_subscript_5.f90 b/gcc/testsuite/gfortran.dg/do_subscript_5.f90 new file mode 100644 index 00000000000..29fefbcb6f2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/do_subscript_5.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! PR 90563 - this used to be rejected, wrongly +! Original test case by Tobias Neumann +program test + implicit none + integer, parameter :: swap(4) = [2,1,3,4] + real :: p(20) + integer :: j + + p = 0.0 + + do j=1,6 + if (j<5) then + p(j) = p(swap(j)) + endif + enddo +end program -- 2.30.2