From patchwork Mon Dec 20 21:07:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1571259 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Au8mgE7Z; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JHsd665J1z9s1l for ; Tue, 21 Dec 2021 08:08:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89AF9385803F for ; Mon, 20 Dec 2021 21:08:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89AF9385803F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1640034503; bh=Q5fvGztzP0TKko7EzbUhBqafwpjmY6mzbYKppWakHdk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Au8mgE7ZVTz58XOgvNKoPU8Eb45/sR4kYLOijqJc/yrFRvi54AK4161VT3vfsbMb0 uYEgp8d3KtpFdDK4JrsZD9+6wxGED/cS4keSG9XfTNCjH7bYipz3EuoErJnedo2DB6 mbWLVuEL02X81qamxvPuYMF6kWmE0N5CwmoWGQ4A= 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.15]) by sourceware.org (Postfix) with ESMTPS id D3EF53858428; Mon, 20 Dec 2021 21:07:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D3EF53858428 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.251.14.138] ([79.251.14.138]) by web-mail.gmx.net (3c-app-gmx-bs55.server.lan [172.19.170.139]) (via HTTP); Mon, 20 Dec 2021 22:07:45 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] PR fortran/103776 - ICE in gfc_compare_string, at fortran/arith.c:1118 Date: Mon, 20 Dec 2021 22:07:45 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:Ps6cESM5m+kcaAqp+743vdkcnEO4YFdqgDbRHbvvVzjvcSf4L+gNjSouxfkdsodOlMdyW +H0f9cAjDBprRfqQ8AAu0327DF1OVLAJMymSfz8o+CE+Nw7yUcKxfKoMyZ2etQCWnjsrwo48TQx+ b3Uok/dW1UvDZKIXeeZpMc/XEBt3GhsRescbnvoB7BKLSCSxHuYXs/COboABOk4G3IwxtcCHUeJM KNYSWDKmvBL2NFAsEwuLioQxTvHVNERtI52rXyMWKhEd/SIuzp5l9KG0ugH7zQPa13LZE7i5T904 WU= X-UI-Out-Filterresults: notjunk:1;V03:K0:ElAj76lhvBE=:8wTHpQuSbPpP/OHkAhAc9w FrHeccOP0qaLRdsfdwuoCmq4VlmhwDZmhATFVBY5rto8LN6bZFUl7ai85Kk6cxDR1RCDLSnLl yYcU5LP1eS8+/64MH+++vn6PiwZBXkE6m6EIqgFQAdfJHEtCSYN80yJ7p9vLPZJXc444fLf9k YW2pPZXoCBta/0K7RkJ3SSToR7EVrYnvQ+Jj/KiHhHYUUCR0AsQ4F/I7/mqzXhnBIQ2stNhMA xX3s2ksiO8UvNoT4/wuASG6d/dtvX/Nmwq0KVGoGdE6d4rfAqM7D2E/2WcpY8AAXp8ntPVXXY mTgxIogZNHiz2FHnATXnGIF5MLPtCQhe/3lHHyG5sWliTNFwNCMsAcvBe0KTUZHdDF87j2Dgh yc2TrS7/U9akecaNhfV/qWHp/L8eToDLjJtve59BtRJZO4HPHZ4qNlv2r8fJvbWkx6+TxV3PT 7FYQd35OrW9mtD2WnEO603ZlxfVmS+RyAMIzg+4AWEwd7Q7y871xtaz8eY3LE1dtpMcFyk1WP IljbabsTvNGJ/Ohd2XHRTIjNA0kkV0i2sBoXUBM8nS6xym5Cw+wxIN53TqGbeghvHeQY67Dtc f/Jso9U+L7IDXRcOB44POvotGgzeH9WV+wNbG0ace5EFguO4ndzODVtnTIdkqrRjvjFbm1058 f8oaj2QF42dMNcpxRF8ajr9oT+zbmVmnLIiS8YmrCclPTLblODdZCRoFOtqxGOMRTGg3cpx9x n+O8ZZG0ux/8Aambd21iJOyJnOzPzemTyivhDesceBgbdLv8WpwRQZJACInrfXphhrSmnTLrF rdnqUtW X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Dear all, we need to check that expressions in CASE selectors are scalar, and reject them early if they aren't. Testcase by Gerhard. The fix is obvious and sort of a follow-up to the fix for PR103591. Regtested on x86_64-pc-linux-gnu. Will commit as obvious within 48h unless there are objections or other comments. Thanks, Harald From 70385de214fe4de289c56e7f4e06a4b252414379 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 20 Dec 2021 22:01:05 +0100 Subject: [PATCH] Fortran: CASE selector expressions must be scalar gcc/fortran/ChangeLog: PR fortran/103776 * match.c (match_case_selector): Reject expressions in CASE selector which are not scalar. gcc/testsuite/ChangeLog: PR fortran/103776 * gfortran.dg/select_10.f90: New test. --- gcc/fortran/match.c | 13 +++++++++++++ gcc/testsuite/gfortran.dg/select_10.f90 | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/select_10.f90 diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 52bc5af7542..617fb35c9cd 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -6088,6 +6088,19 @@ match_case_selector (gfc_case **cp) } } + if (c->low && c->low->rank != 0) + { + gfc_error ("Expression in CASE selector at %L must be scalar", + &c->low->where); + goto cleanup; + } + if (c->high && c->high->rank != 0) + { + gfc_error ("Expression in CASE selector at %L must be scalar", + &c->high->where); + goto cleanup; + } + *cp = c; return MATCH_YES; diff --git a/gcc/testsuite/gfortran.dg/select_10.f90 b/gcc/testsuite/gfortran.dg/select_10.f90 new file mode 100644 index 00000000000..2d9b0170ce9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/select_10.f90 @@ -0,0 +1,25 @@ +! { dg-do compile } +! PR fortran/103776 - ICE in gfc_compare_string +! Contributed by G.Steinmetz + +program p + integer :: n + select case (n) + case ([1]) ! { dg-error "must be scalar" } + end select + select case (n) + case (:[2]) ! { dg-error "must be scalar" } + end select + select case (n) + case (['1']) ! { dg-error "must be scalar" } + end select + select case (n) + case (['1']:2) ! { dg-error "must be scalar" } + end select + select case (n) + case(['1']:['2']) ! { dg-error "must be scalar" } + end select + select case (n) + case(1:['2']) ! { dg-error "must be scalar" } + end select +end -- 2.26.2