From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 878883858D3C; Wed, 8 Dec 2021 19:18:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 878883858D3C MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9365] Fortran: perform array subscript checks only for valid INTEGER bounds X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: bd918acae2dd85e0fa79d582e3e221e0caff034e X-Git-Newrev: 8ff9ed7f4f7e80b4602524689dc486cf35e84e87 Message-Id: <20211208191849.878883858D3C@sourceware.org> Date: Wed, 8 Dec 2021 19:18:49 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Dec 2021 19:18:49 -0000 https://gcc.gnu.org/g:8ff9ed7f4f7e80b4602524689dc486cf35e84e87 commit r11-9365-g8ff9ed7f4f7e80b4602524689dc486cf35e84e87 Author: Harald Anlauf Date: Tue Dec 7 21:34:31 2021 +0100 Fortran: perform array subscript checks only for valid INTEGER bounds gcc/fortran/ChangeLog: PR fortran/103607 * frontend-passes.c (do_subscript): Ensure that array bounds are of type INTEGER before performing checks on array subscripts. gcc/testsuite/ChangeLog: PR fortran/103607 * gfortran.dg/pr103607.f90: New test. (cherry picked from commit 9eec77c0df9e5c67454a2e8f83246104458ba4f0) Diff: --- gcc/fortran/frontend-passes.c | 4 ++++ gcc/testsuite/gfortran.dg/pr103607.f90 | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index cc91fc95ee0..287b7d70876 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -2914,6 +2914,7 @@ do_subscript (gfc_expr **e) { if (ar->as->lower[i] && ar->as->lower[i]->expr_type == EXPR_CONSTANT + && ar->as->lower[i]->ts.type == BT_INTEGER && mpz_cmp (val, ar->as->lower[i]->value.integer) < 0) gfc_warning (warn, "Array reference at %L out of bounds " "(%ld < %ld) in loop beginning at %L", @@ -2923,6 +2924,7 @@ do_subscript (gfc_expr **e) if (ar->as->upper[i] && ar->as->upper[i]->expr_type == EXPR_CONSTANT + && ar->as->upper[i]->ts.type == BT_INTEGER && mpz_cmp (val, ar->as->upper[i]->value.integer) > 0) gfc_warning (warn, "Array reference at %L out of bounds " "(%ld > %ld) in loop beginning at %L", @@ -2938,6 +2940,7 @@ do_subscript (gfc_expr **e) { if (ar->as->lower[i] && ar->as->lower[i]->expr_type == EXPR_CONSTANT + && ar->as->lower[i]->ts.type == BT_INTEGER && mpz_cmp (val, ar->as->lower[i]->value.integer) < 0) gfc_warning (warn, "Array reference at %L out of bounds " "(%ld < %ld) in loop beginning at %L", @@ -2947,6 +2950,7 @@ do_subscript (gfc_expr **e) if (ar->as->upper[i] && ar->as->upper[i]->expr_type == EXPR_CONSTANT + && ar->as->upper[i]->ts.type == BT_INTEGER && mpz_cmp (val, ar->as->upper[i]->value.integer) > 0) gfc_warning (warn, "Array reference at %L out of bounds " "(%ld > %ld) in loop beginning at %L", diff --git a/gcc/testsuite/gfortran.dg/pr103607.f90 b/gcc/testsuite/gfortran.dg/pr103607.f90 new file mode 100644 index 00000000000..a6a2c4fdfd0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103607.f90 @@ -0,0 +1,12 @@ +! { dg-do compile } +! PR fortran/103607 - ICE in do_subscript, at fortran/frontend-passes.c:2927 +! Contributed by G.Steinmetz + +program p + integer :: i, x(abs(2.)) ! { dg-error "must be of INTEGER type" } + do i = 1, 2 + x(i) = 0 + end do +end + +! { dg-prune-output "must have constant shape" }