From patchwork Sat Dec 10 21:14:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 32096 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1497034wrr; Sat, 10 Dec 2022 13:14:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf7b/U1VMfNA41lvbv+Xs6nDKtXbNC8+KqEwISrmgOUyfNhPpB1866ZYU1MHecnsrgqidcZU X-Received: by 2002:a17:907:3ac2:b0:7c1:765:9cfc with SMTP id fi2-20020a1709073ac200b007c107659cfcmr6695557ejc.34.1670706892751; Sat, 10 Dec 2022 13:14:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670706892; cv=none; d=google.com; s=arc-20160816; b=D5bJi/OALuw4pndAtnCUBIUFiQnB1bGjAPvN44DYsIfbwqHJCXvljdu8rB4LQJK+t3 TsKVCnhQHH/HSWDm4EWwh5q/oBi8BNVH6DNB5fJilkxTErjlmjoC5zFWjFfVP7yPLC7L HzQD3YtCMiY2ADN/jgytrMzxFVfoXpv2BAMHSTL0KRZR6reBT/0A8fbxnOrfKTCpds12 lkRgRRZqNc1WvEwXXfNOdIC8HbE0VKWdt44mR2UoQ5CNOvrgB6ZEoGVVOntRhHPYPrlT 9kV3+JngqrjcYaKwvnhjoPhDVmKDYcr5rtT/LIDDej+4AD0G3eu0qf5NgQ0YYeEQF+Vc w3cQ== 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=To409pZp943xi07BsGm8hsU00K1xDOg4DHMlcWSrn68=; b=PeyvjpWa/ybluz9lX6A3XZySezKnIg8W3iF1OoVF3QBAo5q1DErfZDnw7KHJcDpErx VwD46WVFNjEqNQhHRM7kKpEIQIidRvm5OtGOaNE/9TJYPwwRbS3Tx6idC49bZik8DXd7 4/sjb40ecZv+ClCltdK7WwsdeHoo8PPEWMquM+VdpgLe9yvrpmPX6k7/CTVGaDXEXUeC zYq6wxYNpiusqoEDLkrcuNNiC8BkAFoTpbshKfNytWw76Xpc7vDFWK+i22zFXiEb3fJK rU6+BukUE7FQ4VvurDDHK/JhUEUQZFaUvcAp8s0QrZGXXenC+AovCyvm5FrYv7oXc+qF hMyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ldZ5xX+k; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gb2-20020a170907960200b007c10a0c31a3si2866561ejc.425.2022.12.10.13.14.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Dec 2022 13:14:52 -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=ldZ5xX+k; 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 9C5D238417E9 for ; Sat, 10 Dec 2022 21:14:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C5D238417E9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670706891; bh=To409pZp943xi07BsGm8hsU00K1xDOg4DHMlcWSrn68=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ldZ5xX+kPbNyyC+RS9F/sIe3SwcVIotGOuo0mewb06YCAG4uvKtZ47uTaZmqczm7n qMGc5af9ru4p4u2hLCVEvGEuRfhrxS9NpmzDef6o2ePziYzS2Gzfd0zjYSdust8TJC hpu/6Zev6ie4udzpb40ozxiEeqOyPwFmXO0GbIMU= 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.17.20]) by sourceware.org (Postfix) with ESMTPS id 40EED38500BE; Sat, 10 Dec 2022 21:14:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 40EED38500BE X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.84.200] ([93.207.84.200]) by web-mail.gmx.net (3c-app-gmx-bap38.server.lan [172.19.172.108]) (via HTTP); Sat, 10 Dec 2022 22:14:06 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: reject bad SIZE argument while simplifying ISHFTC [PR106911] Date: Sat, 10 Dec 2022 22:14:06 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:ChWGdEReVim3doPtbrYhF3J6lyZ9DNEm4vdKiBTsLEcPmJDoO+agem3Tsxk4SHnJN+tVJ jfGiOYN57dbPnmQXCS1WY6e7KDg9gPGDDcCQQbX6As63Fj/oLHawZNMKlLPaxhZ/O1EexEGmjmzn QUCCKeRvCX3geiHjQPHjFENdTRN0LUtUTwp2MsXh7QY6JZfvu4LqXgIoc/BtyDhMOZf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F, 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?1751863150724815740?= X-GMAIL-MSGID: =?utf-8?q?1751863150724815740?= Dear all, we should not try to simplify ISHFTC if the SIZE argument is known to be outside the allowed range. It's better to generate an error by terminating the simplification. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From ae4438537fbc2ed04f3b0fb32d4e02b0ed6977a1 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sat, 10 Dec 2022 22:05:15 +0100 Subject: [PATCH] Fortran: reject bad SIZE argument while simplifying ISHFTC [PR106911] gcc/fortran/ChangeLog: PR fortran/106911 * simplify.cc (gfc_simplify_ishftc): If the SIZE argument is known to be outside the allowed range, terminate simplification. gcc/testsuite/ChangeLog: PR fortran/106911 * gfortran.dg/pr106911.f90: New test. --- gcc/fortran/simplify.cc | 3 +++ gcc/testsuite/gfortran.dg/pr106911.f90 | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr106911.f90 diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index aff9a1b8ced..3d3aaba84df 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -3955,6 +3955,9 @@ gfc_simplify_ishftc (gfc_expr *e, gfc_expr *s, gfc_expr *sz) return NULL; gfc_extract_int (sz, &ssize); + + if (ssize > isize || ssize <= 0) + return &gfc_bad_expr; } else ssize = isize; diff --git a/gcc/testsuite/gfortran.dg/pr106911.f90 b/gcc/testsuite/gfortran.dg/pr106911.f90 new file mode 100644 index 00000000000..f3fe7f6ad68 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr106911.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! PR fortran/106911 - ICE in gfc_convert_mpz_to_signed +! Contributed by G.Steinmetz + +program p + implicit none + integer, parameter :: a = 10 + integer, parameter :: b = 20 + integer, parameter :: c = ishftc(1_1, a, b) ! { dg-error "must be less than or equal" } + integer, parameter :: d = ishftc(1_1, a, 0) ! { dg-error "must be positive" } + interface + subroutine s + import :: a, b + integer, parameter :: e = ishftc(1_1, a, b) ! { dg-error "must be less than or equal" } + integer, parameter :: f = ishftc(1_1, a, 0) ! { dg-error "must be positive" } + end + end interface +end -- 2.35.3