From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id BC041385841C; Sun, 5 Feb 2023 19:28:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC041385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675625335; bh=7X2HZBN+ncaH4jUFgTsSUqB0QsagQpwwJpQbEKtEIGs=; h=From:To:Subject:Date:From; b=lofaPInqaqPQWrytbWoNwzwAuCdLal2ekFs9SjWYbvp7s5wRGrMFsjJN9OQgEWVnT Og4a9mzG8wVU8/M98gi0IA0C+pR5KI5hYRUT7s9adpPQCHoXkW1pPvwh+cds0cUyuD gqVKGoNKclwmY2K/PnlbYUextwMh/kF/p4VMW2yk= 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 r12-9107] Fortran: error recovery on invalid array section [PR108609] X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 511928102dc9fa3f9c377e01f9bfb605b4995a61 X-Git-Newrev: 1e60e9124543fd002f3e6dad8172cff8aa1b24b3 Message-Id: <20230205192855.BC041385841C@sourceware.org> Date: Sun, 5 Feb 2023 19:28:55 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1e60e9124543fd002f3e6dad8172cff8aa1b24b3 commit r12-9107-g1e60e9124543fd002f3e6dad8172cff8aa1b24b3 Author: Harald Anlauf Date: Wed Feb 1 21:01:32 2023 +0100 Fortran: error recovery on invalid array section [PR108609] The testcase for PR108527 uncovered a latent issue with invalid array sections that resulted in different paths being taken on different architectures. Detect the invalid array declaration for a clean recovery. gcc/fortran/ChangeLog: PR fortran/108609 * expr.cc (find_array_section): Add check to prevent interpreting an mpz non-integer constant as an integer. gcc/testsuite/ChangeLog: PR fortran/108609 * gfortran.dg/pr108527.f90: Adjust test pattern. (cherry picked from commit 88a2a09dd4529107e7ef7a6e7ce43acf96457173) Diff: --- gcc/fortran/expr.cc | 6 +++++- gcc/testsuite/gfortran.dg/pr108527.f90 | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index ab54d43bce2..15d41d023d3 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -1552,7 +1552,11 @@ find_array_section (gfc_expr *expr, gfc_ref *ref) lower = ref->u.ar.as->lower[d]; upper = ref->u.ar.as->upper[d]; - if (!lower || !upper) + if (!lower || !upper + || lower->expr_type != EXPR_CONSTANT + || upper->expr_type != EXPR_CONSTANT + || lower->ts.type != BT_INTEGER + || upper->ts.type != BT_INTEGER) { t = false; goto cleanup; diff --git a/gcc/testsuite/gfortran.dg/pr108527.f90 b/gcc/testsuite/gfortran.dg/pr108527.f90 index c97ba3111cb..804514810ac 100644 --- a/gcc/testsuite/gfortran.dg/pr108527.f90 +++ b/gcc/testsuite/gfortran.dg/pr108527.f90 @@ -4,7 +4,7 @@ program p integer, parameter :: a((2.)) = [4,8] ! { dg-error "must be of INTEGER type" } - integer(a(1:1)) :: b ! { dg-error "out of bounds" } + integer(a(1:1)) :: b ! { dg-error "Unclassifiable statement" } end ! { dg-prune-output "Parameter array" }