From: Thomas Koenig Date: Tue, 13 Aug 2019 22:25:32 +0000 (+0000) Subject: backport: re PR fortran/90563 (Out of bounds error when compiling with -Wextra) X-Git-Tag: releases/gcc-9.3.0~731 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=088f5f1596e795c19a31cbaeeb8a294b1e076fc6;p=thirdparty%2Fgcc.git backport: re PR fortran/90563 (Out of bounds error when compiling with -Wextra) 2013-08-13 Thomas Koenig Backport from trunk PR fortran/90563 * frontend-passes.c (insert_index): Suppress errors while simplifying the resulting expression. 2013-08-13 Thomas Koenig Backport from trunk PR fortran/90563 * gfortran.dg/do_subsript_5.f90: New test. From-SVN: r274405 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 954e80b260b9..9484b9992e53 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,7 +1,14 @@ +2013-08-13 Thomas Koenig + + Backport from trunk + PR fortran/90563 + * frontend-passes.c (insert_index): Suppress errors while + simplifying the resulting expression. + 2019-08-13 Steven G. Kargl PR fortran/88072 - * misc.c (gfc_typename): Do not point to something that ought not to + * misc.c (gfc_typename): Do not point to something that ought not to be pointed at. 2019-08-13 Thomas Koenig diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 75b2d05fc85e..08503ea5d1d6 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -2519,7 +2519,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 187467d47013..e8b462ac3973 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2013-08-13 Thomas Koenig + + Backport from trunk + PR fortran/90563 + * gfortran.dg/do_subsript_5.f90: New test. + 2019-08-13 Steven G. Kargl PR fortran/88072 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 000000000000..54a4f1ba51ac --- /dev/null +++ b/gcc/testsuite/gfortran.dg/do_subscript_5.f90 @@ -0,0 +1,20 @@ +! { dg-do compile } +! { dg-additional-options "-Wdo-subscript" } +! 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 + + ! The following warnings are actually bogus, but we are not yet + ! clever enough to suppress them. + do j=1,6 ! { dg-warning "out of bounds" } + if (j<5) then + p(j) = p(swap(j)) ! { dg-warning "out of bounds" } + endif + enddo +end program