From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 208993858D32; Sun, 8 Jan 2023 20:52:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 208993858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673211153; bh=Ad2oW3beTlBm9ksjWltojBhPwCaQCYEO0Y9pXbyOE0w=; h=From:To:Subject:Date:From; b=g1rb2BB2uoBCZ719yPDYWNHQw3smy8QyFvugzV58MzyVu0j+PiwBGmWTs/sWTlPRU xFI+hSsUC8qCQ1rITxCRSOZR4Eao1FwOOfL//UorwsESIhPYBqyybGWBtT7jn/LPrZ IyuP6+OUQIu+GGYSQhgv84DbRvg2spRjzwQkx6Vc= 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-10458] Fortran: incorrect array bounds when bound intrinsic used in decl [PR108131] X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: b5b5244e6e671ca3c07941fe623d28f1e544fc89 X-Git-Newrev: 04310741924e7e6ef1ec637a1a9c3e2972345926 Message-Id: <20230108205233.208993858D32@sourceware.org> Date: Sun, 8 Jan 2023 20:52:33 +0000 (GMT) List-Id: https://gcc.gnu.org/g:04310741924e7e6ef1ec637a1a9c3e2972345926 commit r11-10458-g04310741924e7e6ef1ec637a1a9c3e2972345926 Author: Harald Anlauf Date: Sat Dec 17 22:04:32 2022 +0100 Fortran: incorrect array bounds when bound intrinsic used in decl [PR108131] gcc/fortran/ChangeLog: PR fortran/108131 * array.c (match_array_element_spec): Avoid too early simplification of matched array element specs that can lead to a misinterpretation when used as array bounds in array declarations. gcc/testsuite/ChangeLog: PR fortran/108131 * gfortran.dg/pr103505.f90: Adjust expected patterns. * gfortran.dg/pr108131.f90: New test. (cherry picked from commit 6a95f0e0a06d78d94138d4c3dd64d41591197281) Diff: --- gcc/fortran/array.c | 4 ---- gcc/testsuite/gfortran.dg/pr103505.f90 | 8 +++++--- gcc/testsuite/gfortran.dg/pr108131.f90 | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index b406f6d1f6e..bb6f2bb9045 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -492,8 +492,6 @@ match_array_element_spec (gfc_array_spec *as) if (!gfc_expr_check_typed (*upper, gfc_current_ns, false)) return AS_UNKNOWN; - gfc_try_simplify_expr (*upper, 0); - if (((*upper)->expr_type == EXPR_CONSTANT && (*upper)->ts.type != BT_INTEGER) || ((*upper)->expr_type == EXPR_FUNCTION @@ -526,8 +524,6 @@ match_array_element_spec (gfc_array_spec *as) if (!gfc_expr_check_typed (*upper, gfc_current_ns, false)) return AS_UNKNOWN; - gfc_try_simplify_expr (*upper, 0); - if (((*upper)->expr_type == EXPR_CONSTANT && (*upper)->ts.type != BT_INTEGER) || ((*upper)->expr_type == EXPR_FUNCTION diff --git a/gcc/testsuite/gfortran.dg/pr103505.f90 b/gcc/testsuite/gfortran.dg/pr103505.f90 index 522e53efcb2..01308019b2c 100644 --- a/gcc/testsuite/gfortran.dg/pr103505.f90 +++ b/gcc/testsuite/gfortran.dg/pr103505.f90 @@ -3,7 +3,9 @@ ! Testcase by G.Steinmetz program p - integer, parameter :: a((2.)) = [4,8] ! { dg-error "scalar INTEGER" } - integer, parameter :: z(1:(2.)) = [4,8] ! { dg-error "scalar INTEGER" } - print *, a(1:1) ! { dg-error "Syntax error" } + integer, parameter :: a((2.)) = [4,8] ! { dg-error "INTEGER type" } + integer, parameter :: z(1:(2.)) = [4,8] ! { dg-error "INTEGER type" } + print *, a(1:1) end + +! { dg-prune-output "Parameter array" } diff --git a/gcc/testsuite/gfortran.dg/pr108131.f90 b/gcc/testsuite/gfortran.dg/pr108131.f90 new file mode 100644 index 00000000000..8bf36d361ba --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr108131.f90 @@ -0,0 +1,25 @@ +! { dg-do run } +! { dg-additional-options "-fdump-tree-original" } +! PR fortran/108131 +! +! Incorrect array bounds when bound intrinsic used in declaration + +program test + implicit none + integer, parameter :: mg(7:10) = 0 + integer, parameter :: u = ubound(mg, dim=1) + integer, parameter :: cx(-1:ubound(mg, dim=1)) = 1 + integer, parameter :: dx(lbound(mg, dim=1):ubound(cx, dim=1)) = 2 + + write(*,*) ubound(mg, dim=1) + write(*,*) ubound(cx, dim=1) + if (u /= 10) stop 1 + if (ubound(mg, dim=1) /= 10) stop 2 + if (ubound(cx, dim=1) /= 10) stop 3 + if (ubound(dx, dim=1) /= 10) stop 4 + if (lbound(mg, dim=1) /= 7) stop 5 + if (lbound(cx, dim=1) /= -1) stop 6 + if (lbound(dx, dim=1) /= 7) stop 7 +end program test + +! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "original" } }