From patchwork Thu Dec 22 21:13:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 35960 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp166001wrn; Thu, 22 Dec 2022 13:13:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXsIwxNudhW1gEumL5BeHOCKBN4ceRh2HBEeqD01fGypYS+CFXIC7GU/887fNy0A2L+hsT0N X-Received: by 2002:a17:907:6f09:b0:7f7:a985:1849 with SMTP id sy9-20020a1709076f0900b007f7a9851849mr5519169ejc.24.1671743637450; Thu, 22 Dec 2022 13:13:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671743637; cv=none; d=google.com; s=arc-20160816; b=pKwnyPCNWsdcFYlt4EQI3VEdgVkN36SpMiy5Qlg/LW5fuSO2TOfbFKYw+flkYUUId7 JOH1Ud7tNDLIB2sDKXo3M0deIFmUt+6KKtzNW+r5Sns0K00A9bHB7YyvosLfwwuf/HO2 kA1KldNqQe1PJldD+3ZGONS0ySNARXW3LoGszoYv8mjEX8bNaCdGUP82F/6AHpTj8AnZ mkGOIsqEDYWEEAzZ2+JSdtIDxnqVuew6Iid/eKrDNd0h/Bba00XAtbpQp/Q+CVdGDp9v y6btyWw6JeDTHRnZ68GoXrTGkooZ8mBrfkvEeZC7sN0DC3T2JT4+o9JTFmASTblg8HVf HQBw== 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=Gi6Qvz64eMVQLwoiylX5EkAcX/eJl+5OqWq26KwHAy4=; b=FqZ9FRQ60dPojdNmDYpCIILb3qPyyfBSgmb+w9oDbCbnEwQuas3cwnRA5+QLtkjqYH Y0sMFd+rNq/7d9CDMwTji967viSch7I1QESY4ZAhg+Gc8BI4SF+WxJjQ/ceIdeTjcWxH ZvYcZUaLvbKKV9xf3DNpxPiRyw8gZQR80zpLo/epej+uy55c43FH+0fYZbzkdVV93Cnu gp6xdEiwRiAOr2IuhC+JhMvHJ43s6/N4qirvvFUplLC5u0jcEgAA4GNsVoBIhEkwc921 ZZuOEwnhG20XeA7wYAiZaqUkaEvaQR26zLJ7Qex1mJ6JaczzS4FMwISAQRmpL5FeT/3M eVqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Oyda/MYg"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gs6-20020a1709072d0600b007cebad0e757si1358674ejc.194.2022.12.22.13.13.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 13:13:57 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Oyda/MYg"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 9ABA9385483F for ; Thu, 22 Dec 2022 21:13:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9ABA9385483F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671743628; bh=Gi6Qvz64eMVQLwoiylX5EkAcX/eJl+5OqWq26KwHAy4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Oyda/MYgVNTuwfZ2qL9uWI4EOCEPcOL2CWmlzZ2SC4JlMpPvCMk0rVTQhI0Ke0W62 Y9kUZU9o1SPwHBvrR247poCpc8R0KqHYQuueULzoujx4IpRvQgaNUD3tliZPZ1Mly1 BXicCOYYDULYRpqVIQweS7K5h6CXc30pFpuVgZXU= 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.21]) by sourceware.org (Postfix) with ESMTPS id 08ECD3858D1E; Thu, 22 Dec 2022 21:13:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 08ECD3858D1E X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.82.36] ([93.207.82.36]) by web-mail.gmx.net (3c-app-gmx-bap55.server.lan [172.19.172.125]) (via HTTP); Thu, 22 Dec 2022 22:13:04 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: check for invalid uses of statement functions arguments [PR69604] Date: Thu, 22 Dec 2022 22:13:04 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:T2zrMgZInQ2DDbJNfOR7YxKcfdEszGU6T6WBgFhDb4vwDg8M2QNkUF4jbDC3REemv1su2 cKFCbBdo1M2rWX2BH3I4UFnuZBzujImMr3kqWZXifloO+x/1CmBFDLmzjNmAn0lfqxCMOZaRAQ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: 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 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?1752950256107923371?= X-GMAIL-MSGID: =?utf-8?q?1752950256107923371?= Dear all, the attached patch adds a check for statement function bodies for invalid uses of dummy arguments. This fixes an ICE-on invalid. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 794af0d00b7086c9f0493f3a1aaac644e1fd50f6 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 22 Dec 2022 22:03:31 +0100 Subject: [PATCH] Fortran: check for invalid uses of statement functions arguments [PR69604] gcc/fortran/ChangeLog: PR fortran/69604 * match.cc (chk_stmt_fcn_body): New function. Check for invalid uses of statement functions arguments. (gfc_match_st_function): Use above. gcc/testsuite/ChangeLog: PR fortran/69604 * gfortran.dg/statement_function_4.f90: New test. --- gcc/fortran/match.cc | 27 +++++++++++++++++++ .../gfortran.dg/statement_function_4.f90 | 10 +++++++ 2 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/statement_function_4.f90 diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc index 89fb115c0f6..3d346788416 100644 --- a/gcc/fortran/match.cc +++ b/gcc/fortran/match.cc @@ -5915,6 +5915,30 @@ recursive_stmt_fcn (gfc_expr *e, gfc_symbol *sym) } +/* Check for invalid uses of statement function dummy arguments in body. */ + +static bool +chk_stmt_fcn_body (gfc_expr *e, gfc_symbol *sym, int *f ATTRIBUTE_UNUSED) +{ + gfc_formal_arglist *formal; + + if (e == NULL || e->symtree == NULL || e->expr_type != EXPR_FUNCTION) + return false; + + for (formal = sym->formal; formal; formal = formal->next) + { + if (formal->sym == e->symtree->n.sym) + { + gfc_error ("Invalid use of statement function argument at %L", + &e->where); + return true; + } + } + + return false; +} + + /* Match a statement function declaration. It is so easy to match non-statement function statements with a MATCH_ERROR as opposed to MATCH_NO that we suppress error message in most cases. */ @@ -5983,6 +6007,9 @@ gfc_match_st_function (void) return MATCH_ERROR; } + if (gfc_traverse_expr (expr, sym, chk_stmt_fcn_body, 0)) + return MATCH_ERROR; + sym->value = expr; if ((gfc_current_state () == COMP_FUNCTION diff --git a/gcc/testsuite/gfortran.dg/statement_function_4.f90 b/gcc/testsuite/gfortran.dg/statement_function_4.f90 new file mode 100644 index 00000000000..6ce5951b53a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/statement_function_4.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! PR fortran/69604 +! Contributed by G.Steinmetz + +program p + x(n) = 1 + n(2.0) ! { dg-error "Invalid use of statement function argument" } + y(k) = k() ! { dg-error "Invalid use of statement function argument" } + z(m) = m ! { dg-warning "Statement function" } + print *, x(n) +end -- 2.35.3