From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by sourceware.org (Postfix) with ESMTPS id C45F03858439; Sat, 17 Dec 2022 21:21:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C45F03858439 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1671312077; bh=eSDKe37PCRmaV9s4LClGrkzdtFXou8SZ/u+iaZB5YIg=; h=X-UI-Sender-Class:From:To:Subject:Date; b=QwbXMCD1Sxgv+KdWjwKBa5GzHr84kv29yPgoNDWpWR1+5nPQimu5Uuhzd/gT14/o4 0hhM4nvFS+naa2fRzuzrHXfGmdsIrjk+vz4W6Y8cMU1l/3EU7/FzYHXDe25AaU+hFP EaGMwqUlPI+b5ffBSJ83ZLzpdXI2uqIiGLq0D+q8JYOoNo6RRfoOtzeCPC2yynW+Z0 CqXko+GISmSpCyCl8hnYCzb8SlOxMzfghDruFdfW73uC3TXYaUhPbHrZ8N4klkKljg RFK4JaraQBUZYwZDhMyB2XTQqIhlEfCh6d5PlMF0j4nZa6x27gqPMoB3boVqZzb/8n gx+oSNvnhH73w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.13.33] ([79.251.13.33]) by web-mail.gmx.net (3c-app-gmx-bap49.server.lan [172.19.172.119]) (via HTTP); Sat, 17 Dec 2022 22:21:17 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: incorrect array bounds when bound intrinsic used in decl [PR108131] Content-Type: multipart/mixed; boundary=rehcsed-1f7c5189-0270-4121-924d-0555f11856d3 Date: Sat, 17 Dec 2022 22:21:17 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1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YwlA+vfYXFlrK+TQlvVc0AxG MgmBUPANkZPVLbZrQyw2umR46CVjFiQ6/dHW6iYgMTUpIsNNfT0i0WY2c/j5CnZe2YAK3gDPW mhnqgp7OvUxyVzsx/AOVdb/g== X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --rehcsed-1f7c5189-0270-4121-924d-0555f11856d3 Content-Type: text/plain; charset=UTF-8 Dear all, the previous fix for pr103505 introduced a regression that could lead to wrong array bounds when LBOUND/UBOUND were used in the array spec of a declaration. The reason was that we tried to simplify too early the array element spec, which appears to have interfered with the subtle semantics of the bound intrinsics. The solution is to undo the fix for pr103505. It turns out that there are other code changes in place that were put in place to fix related ICEs, and which handle that one, too, and only lead to a change of the emitted error diagnostics. Regtested on x86_64-pc-linux-gnu. OK for mainline? As this is a 10/11/12/13 regression, I would like to backport as seems fit. Thanks, Harald --rehcsed-1f7c5189-0270-4121-924d-0555f11856d3 Content-Type: text/x-patch Content-Disposition: attachment; filename=pr108131.diff Content-Transfer-Encoding: quoted-printable =46rom 531be0753352ec30c4b1e24591ec3e0c33cd4409 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sat, 17 Dec 2022 22:04:32 +0100 Subject: [PATCH] Fortran: incorrect array bounds when bound intrinsic used= in decl [PR108131] gcc/fortran/ChangeLog: PR fortran/108131 * array.cc (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. =2D-- gcc/fortran/array.cc | 4 ---- gcc/testsuite/gfortran.dg/pr103505.f90 | 8 +++++--- gcc/testsuite/gfortran.dg/pr108131.f90 | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr108131.f90 diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index 10d9e0c5354..7457c03e6cd 100644 =2D-- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -512,8 +512,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 =3D=3D EXPR_CONSTANT && (*upper)->ts.type !=3D BT_INTEGER) || ((*upper)->expr_type =3D=3D EXPR_FUNCTION @@ -546,8 +544,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 =3D=3D EXPR_CONSTANT && (*upper)->ts.type !=3D BT_INTEGER) || ((*upper)->expr_type =3D=3D EXPR_FUNCTION diff --git a/gcc/testsuite/gfortran.dg/pr103505.f90 b/gcc/testsuite/gfortr= an.dg/pr103505.f90 index 522e53efcb2..01308019b2c 100644 =2D-- 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.)) =3D [4,8] ! { dg-error "scalar INTEGER"= } - integer, parameter :: z(1:(2.)) =3D [4,8] ! { dg-error "scalar INTEGER"= } - print *, a(1:1) ! { dg-error "Syntax error" } + integer, parameter :: a((2.)) =3D [4,8] ! { dg-error "INTEGER type" } + integer, parameter :: z(1:(2.)) =3D [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/gfortr= an.dg/pr108131.f90 new file mode 100644 index 00000000000..4a3c467f73a =2D-- /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) =3D 0 + integer, parameter :: u =3D ubound(mg, dim=3D1) + integer, parameter :: cx(-1:ubound(mg, dim=3D1)) =3D 1 + integer, parameter :: dx(lbound(mg, dim=3D1):ubound(mg, dim=3D1)) =3D 2 + + write(*,*) ubound(mg, dim=3D1) + write(*,*) ubound(cx, dim=3D1) + if (u /=3D 10) stop 1 + if (ubound(mg, dim=3D1) /=3D 10) stop 2 + if (ubound(cx, dim=3D1) /=3D 10) stop 3 + if (ubound(dx, dim=3D1) /=3D 10) stop 4 + if (lbound(mg, dim=3D1) /=3D 7) stop 5 + if (lbound(cx, dim=3D1) /=3D -1) stop 6 + if (lbound(dx, dim=3D1) /=3D 7) stop 7 +end program test + +! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "original" } } =2D- 2.35.3 --rehcsed-1f7c5189-0270-4121-924d-0555f11856d3--