From patchwork Tue Jan 24 21:48:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 47908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2388324wrn; Tue, 24 Jan 2023 13:49:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXvdEPrNRkQ9Ch6UJsAgu3GC7+ohC9/AEUa1bnI5XD1gmEQEmxM/4OUA2vSl8wK++9VXSIuX X-Received: by 2002:a17:906:af8f:b0:7c1:5098:9074 with SMTP id mj15-20020a170906af8f00b007c150989074mr27554318ejb.0.1674596951997; Tue, 24 Jan 2023 13:49:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674596951; cv=none; d=google.com; s=arc-20160816; b=caAyJfQEMQbwJZnc9n66/oTMlkX4sw+2N4mrW29+zQZN/lDsiAP1MOtHv1SjN2pej7 ay1T5sS3XuGcW4j9bI/32f0gGxlmRM8Q9xeIOjN/63a2fQMg5lVifRAV4eRhY9VzBr26 btetNt20yUCSRY7OyT/gkyQ6b4r+PipGjS44+gnVC0643cl5njsvwjZNoNg70gHh/Tj3 MLSNb0MDTuFuRxnOluIW9PPSeVTx+JyeIZv08H00KpqZWAoiLHS7CHfic6i3cLQRCh2D yucJyfSh8R5OrkiQyPiQjfx1F5ijBQqxBlgFF8VsGADGSHNwGiPbU5UKgu4pxq7mIaKo D2Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=N8ebWc4sCd1Fdq4CHBSGf1PNX93dJ+EqxiV15xwTEkA=; b=Crt/vmbH3Nht9H4ZfKu+EDYAMO2mNyeESdzxo6CrzYK9+s4ApYewI1rBycB+pa1gK2 JA22z52MlRg+8+6XcXoOflRWOPB2dyNOS5O4qbwuWZeIoadhg7NsV3ynYMPmlYbPprr1 UXzO5R8pgcUbZn2Vob3uCI4qtnqgkLKjOi9qTAAsonqH6jJ4+NI+JBR8nulqcR2cCezD /VEOAKIrWydktCAe5vWepafN/fmDMRN91s+PK3V96vXxS0VMT40KYF2kk5/xa/FTIZ+t nXA0AgbKHsuo16uNVpZj4wINP3xj6BuWw4up2Vun8WVn/+2uuGb9bQBmovR7lXxuVGT/ ZUrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jpDf2dDm; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fl4-20020a1709072a8400b007c173f77500si3497302ejc.427.2023.01.24.13.49.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 13:49:11 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jpDf2dDm; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5055638582AC for ; Tue, 24 Jan 2023 21:48:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5055638582AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674596939; bh=N8ebWc4sCd1Fdq4CHBSGf1PNX93dJ+EqxiV15xwTEkA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jpDf2dDmQzDzYBFZB7KsoKla4H7xysLoTWq0JynBOMQi/mf8/+gEaX0/Kt6uEJJzR GpZqnHUXxo3ztRzJJQy/HG6/RT2JsaWbjHWm2vqUKPONYcyMWcXMXqA4Eow+v33wCZ xyRqxv/jCoH8dwRkK9QmOuEyeQVzON2hO4t1I7ow= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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: To: fortran , gcc-patches Subject: [PATCH] Fortran: fix ICE in compare_bound_int [PR108527] Date: Tue, 24 Jan 2023 22:48:13 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:XkTcICx7Lp+DHFs5oRdsFIx4b0WdbTphIM4LadrNy3N6oITgTX66xDVNjpKVWD1/VzEzv Y0sFNhByB1VzW4Ckxjg5XUMWb7GXdeAc8dyIp2OcxkkVw464VFkERd0iYMrjo1t5ilSQ5x34+nRW lBsqfAO+Zl17GOe8VKYGGL9PdhrXD+htLK5tgvvaXYgfIjCQ1Sl4te6DQbVrrrzHX8nRpLbj3jcz xHd25AjgwkTVV1s33q8tF9DLntg/36hdrckFrObK1xmU0jHrBfwuRg2A0GtWFuBbxm6fe5/E7Pxv JU= UI-OutboundReport: notjunk:1;M01:P0:qXgQ4quuyYQ=;nRsmEVgYNAsdkHYffZ96ojFiHbk MJGchj3f7NvXTtniFZfmQ482RVsor1efSyo2YSW6iaX2yM4Q+LKWsLYTvTEp5pnw4UAtdT+V8 4PoE+DO/6iuHauB+Pp+ap8s0Rncu4DXUkYrH9ZhF99bsCST6Y8ROwPg+wg5XI+Ljdo4J40Ur4 Moh7M5buR5Yr6y26wz60aa22fWbIu/rVeeUs8EVahZejp+qazlVtQeztQfuvuEyUMA4a/qomR VSp0laYpGye5Czx/Qu8tqEYI7Ok+22BMXTGPUkSZDGDr7bWJAnJ80FgNluZs4kZi5KML7WwAo 0aBT3RE6pqTXRcA0c5ctz+QY9ATXh6FeNZ/3N1xqv2q4DKGkfRyic9iGfebDvimBS7CcZBcdi v0UHmBJKbjCFzrmqkQWaxXZYnUhX5s7ytOU28z3hzKeyRFF+2Ao44S28K+P7c4gMXslUeJfm7 P1hcBXVXDQjUmxPS9MEuwOMnO3oVqzEyNy2yO+ZAosmATUkABpCfkHhdFLUnC3NFF4kiQjTnn ERWfko4aNGz2Y+iMxCg5lmSVGh0GhPwilc6QbxTN7wv80I15lV+E6ipEu240Fn5Rm6QabU5ja 940R3gsbrjhe/nq51UWvMLh6wu4daJyeXlUUxLZWzDJUBMTwqY/uPeeqpJsKFRS9KrmIZ/Gz3 hpjKCiV4oYKEFrerGkM6+03jwCliZYM2tqyPYGv2zol7LocZZbad3H6zHyv+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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755942173264062375?= X-GMAIL-MSGID: =?utf-8?q?1755942173264062375?= 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 From 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 --- 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 --- 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 == NULL || a->expr_type != EXPR_CONSTANT) + if (a == NULL + || a->expr_type != EXPR_CONSTANT + || a->ts.type != BT_INTEGER) return CMP_UNKNOWN; - if (a->ts.type != BT_INTEGER) - gfc_internal_error ("compare_bound_int(): Bad expression"); - i = 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 == NULL || a->expr_type != EXPR_CONSTANT) + if (a == NULL + || a->expr_type != EXPR_CONSTANT + || a->ts.type != BT_INTEGER) return CMP_UNKNOWN; - if (a->ts.type != BT_INTEGER) - gfc_internal_error ("compare_bound_int(): Bad expression"); - i = mpz_cmp (a->value.integer, b); if (i < 0) @@ -4733,23 +4731,24 @@ check_dimension (int i, gfc_array_ref *ar, gfc_array_spec *as) #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i]) compare_result comp_start_end = compare_bound (AR_START, AR_END); + compare_result comp_stride_zero = compare_bound_int (ar->stride[i], 0); /* Check for zero stride, which is not allowed. */ - if (compare_bound_int (ar->stride[i], 0) == CMP_EQ) + if (comp_stride_zero == CMP_EQ) { gfc_error ("Illegal stride of zero at %L", &ar->c_where[i]); return false; } - /* if start == len || (stride > 0 && start < len) - || (stride < 0 && start > len), + /* if start == 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) == CMP_EQ - || ((compare_bound_int (ar->stride[i], 0) == CMP_GT - || ar->stride[i] == NULL) && comp_start_end == CMP_LT) - || (compare_bound_int (ar->stride[i], 0) == CMP_LT + if (comp_start_end == CMP_EQ + || ((comp_stride_zero == CMP_GT || ar->stride[i] == NULL) + && comp_start_end == CMP_LT) + || (comp_stride_zero == CMP_LT && comp_start_end == CMP_GT)) { if (compare_bound (AR_START, as->lower[i]) == CMP_LT) diff --git a/gcc/testsuite/gfortran.dg/pr108527.f90 b/gcc/testsuite/gfortran.dg/pr108527.f90 new file mode 100644 index 00000000000..c97ba3111cb --- /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.)) = [4,8] ! { dg-error "must be of INTEGER type" } + integer(a(1:1)) :: b ! { dg-error "out of bounds" } +end + +! { dg-prune-output "Parameter array" } -- 2.35.3