From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by sourceware.org (Postfix) with ESMTPS id DF0673858D28; Tue, 24 Jan 2023 21:48:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF0673858D28 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=1674596893; bh=vWw2Ojd9+qxaIMvM1bk0p4/03FSxs7LEi4xfD2f7zqY=; h=X-UI-Sender-Class:From:To:Subject:Date; b=G8dY8li3zKueVT93LnHiM4xq3weISYt7od4dkrRCpHssZOmN5QBx/vmHd96HBV51R w+vWi75t1Q/bvxx2J8eiHfGpagPOVF4Eilv15ncTSceoPzF+NKS/r345L0DjYArB/i OQkFWnG8cuwiwr0i3kEO7l5ZVgZOXVF0FqPc6xfyrLIU4VA9bOip4arfhc7/RjzKBE mQHkSSbXRTKUNGc47+x4z333jjkIJwnqgDYseyCdD1+GePvCz2aHcfEbWS/Qzl+Cc3 hB2SrLclCnXDs9ryubz1YOqXfViF8J0fZwArUG2P0fvbZ5WAkkMMEi+5pBrd4eJUND BzgdidrtQV5yg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.87.68] ([93.207.87.68]) by web-mail.gmx.net (3c-app-gmx-bs66.server.lan [172.19.170.210]) (via HTTP); Tue, 24 Jan 2023 22:48:13 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: fix ICE in compare_bound_int [PR108527] Content-Type: multipart/mixed; boundary=rehcsed-6ced7a92-340c-4f86-9f58-4d5d4100d047 Date: Tue, 24 Jan 2023 22:48:13 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:XkTcICx7Lp+D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6zHyv+BY4mjUnBLEKif tJJ5waZmChU4XWAe6FMYJGy97GXS30wM//KBIxG2GLsilc1a26PEmAAgQXrmv9FC2n7oMhvFM ur/9tmrguImJGIH70A/evU3Q== X-Spam-Status: No, score=-13.1 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-6ced7a92-340c-4f86-9f58-4d5d4100d047 Content-Type: text/plain; charset=UTF-8 Dear all, when checking expressions for array sections, we need to ensure that these use only type INTEGER. However, it does not make sense to generate an internal error when encountering wrong types, but rather take the ordinary route of error recovery. The initial fix was provided by Steve. While working on the same PR, I found that the comments related to the logic needed a minor adjustment, and the logic could be cleaned up to actually match the intended comment. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald --rehcsed-6ced7a92-340c-4f86-9f58-4d5d4100d047 Content-Type: text/x-patch Content-Disposition: attachment; filename=pr108527.diff Content-Transfer-Encoding: quoted-printable =46rom bd9afd0835bfe956400978503041323aea894ef5 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 24 Jan 2023 22:36:25 +0100 Subject: [PATCH] Fortran: fix ICE in compare_bound_int [PR108527] gcc/fortran/ChangeLog: PR fortran/108527 * resolve.cc (compare_bound_int): Expression to compare must be of type INTEGER. (compare_bound_mpz_t): Likewise. (check_dimension): Fix comment on checks applied to array section and clean up associated logic. gcc/testsuite/ChangeLog: PR fortran/108527 * gfortran.dg/pr108527.f90: New test. Co-authored-by: Steven G. Kargl =2D-- gcc/fortran/resolve.cc | 29 +++++++++++++------------- gcc/testsuite/gfortran.dg/pr108527.f90 | 10 +++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr108527.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 94213cd3cd4..0538029da26 100644 =2D-- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -4575,12 +4575,11 @@ compare_bound_int (gfc_expr *a, int b) { int i; - if (a =3D=3D NULL || a->expr_type !=3D EXPR_CONSTANT) + if (a =3D=3D NULL + || a->expr_type !=3D EXPR_CONSTANT + || a->ts.type !=3D BT_INTEGER) return CMP_UNKNOWN; - if (a->ts.type !=3D BT_INTEGER) - gfc_internal_error ("compare_bound_int(): Bad expression"); - i =3D mpz_cmp_si (a->value.integer, b); if (i < 0) @@ -4598,12 +4597,11 @@ compare_bound_mpz_t (gfc_expr *a, mpz_t b) { int i; - if (a =3D=3D NULL || a->expr_type !=3D EXPR_CONSTANT) + if (a =3D=3D NULL + || a->expr_type !=3D EXPR_CONSTANT + || a->ts.type !=3D BT_INTEGER) return CMP_UNKNOWN; - if (a->ts.type !=3D BT_INTEGER) - gfc_internal_error ("compare_bound_int(): Bad expression"); - i =3D mpz_cmp (a->value.integer, b); if (i < 0) @@ -4733,23 +4731,24 @@ check_dimension (int i, gfc_array_ref *ar, gfc_arr= ay_spec *as) #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i]) compare_result comp_start_end =3D compare_bound (AR_START, AR_END); + compare_result comp_stride_zero =3D compare_bound_int (ar->stride[i], 0)= ; /* Check for zero stride, which is not allowed. */ - if (compare_bound_int (ar->stride[i], 0) =3D=3D CMP_EQ) + if (comp_stride_zero =3D=3D CMP_EQ) { gfc_error ("Illegal stride of zero at %L", &ar->c_where[i]); return false; } - /* if start =3D=3D len || (stride > 0 && start < len) - || (stride < 0 && start > len), + /* if start =3D=3D end || (stride > 0 && start < end) + || (stride < 0 && start > end), then the array section contains at least one element. In this case, there is an out-of-bounds access if (start < lower || start > upper). */ - if (compare_bound (AR_START, AR_END) =3D=3D CMP_EQ - || ((compare_bound_int (ar->stride[i], 0) =3D=3D CMP_GT - || ar->stride[i] =3D=3D NULL) && comp_start_end =3D=3D CMP_LT) - || (compare_bound_int (ar->stride[i], 0) =3D=3D CMP_LT + if (comp_start_end =3D=3D CMP_EQ + || ((comp_stride_zero =3D=3D CMP_GT || ar->stride[i] =3D=3D NULL) + && comp_start_end =3D=3D CMP_LT) + || (comp_stride_zero =3D=3D CMP_LT && comp_start_end =3D=3D CMP_GT)) { if (compare_bound (AR_START, as->lower[i]) =3D=3D CMP_LT) diff --git a/gcc/testsuite/gfortran.dg/pr108527.f90 b/gcc/testsuite/gfortr= an.dg/pr108527.f90 new file mode 100644 index 00000000000..c97ba3111cb =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr108527.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! PR fortran/108527 - ICE in compare_bound_int +! Contributed by G.Steinmetz + +program p + integer, parameter :: a((2.)) =3D [4,8] ! { dg-error "must be of INTEGE= R type" } + integer(a(1:1)) :: b ! { dg-error "out of bounds" } +end + +! { dg-prune-output "Parameter array" } =2D- 2.35.3 --rehcsed-6ced7a92-340c-4f86-9f58-4d5d4100d047--