From patchwork Mon Apr 3 19:45:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 78702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2543975vqo; Mon, 3 Apr 2023 12:46:45 -0700 (PDT) X-Google-Smtp-Source: AKy350YSQPHEBf5PwMbSjgdAUwkfTGVj0uGhEf3pGUVJuU48rO16Xa9kS9mXKkg7S+6fpFxs+Ue0 X-Received: by 2002:a17:907:7d89:b0:947:c8d5:bfab with SMTP id oz9-20020a1709077d8900b00947c8d5bfabmr11997977ejc.35.1680551204884; Mon, 03 Apr 2023 12:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680551204; cv=none; d=google.com; s=arc-20160816; b=V+9n9cuKyZ+yA82TnGhzCWVGmgU1yQM6oNcrEzSCqprBqxEB9j+lJT+fcjSsv+odi7 Uucx2ElZxyMhOy4bsBPzOCy6qRR1dmcM2JVjGVmbGqVmo41mqPaRbCYzRmE9apcPV02/ obdpPA0/KgydMpRZRevuyly4E7hgBIFO7YjlKd/kGnR9EqrrN5kFvFwRFyFOjy1OwU5v m6/Xsanmc8sYPRG/+DwFsY+F6NL4mUodgS6V4v4U9oFRc44942hldP7WFLK/OWU8fC37 710zFxNnrCtr3L0IxfFUQ9ceCAIEc2ajrV2/7Ay4siwKgxwDG2unvtJwGcJNEr4TU7CM WNRA== 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=hxdLNA5lHWwP4MaByGHbtWhbrY0cmgOuLJEc/kWwims=; b=GpHuTtYWUSYr8Zd1l6PMZ80dlfNgdroNKi5rAKgqEmbiNiObwIvltFJXbv1V5PZTBn CCwjwadmIANPppUt7loiZeilp7DLI70tyzEaz6vr6sBuPPkT8Duv8pafS6RNb/Ub8flY hupr1fX3bEKzE6+ZIjMalr/FBdi3FjFgcBvevSvT1oRuNa+Nqs/svpo5Q0AqgVyVPUHl mvPkyRrq3dj6unOJ154VCAtpJXoQGvimC6KqiBpT6O4sN3qRTa+wydnggiPRenRCr0o+ 3rNna7zDoSSgoy6Krv5P5W34EKpZSTtOvQEwa6d4j0rl/jV2KTNKAv2uK7ygLob/RGKm tzgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="MJiQo/5j"; 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 g12-20020a170906348c00b00933b668c967si8443339ejb.477.2023.04.03.12.46.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 12:46:44 -0700 (PDT) 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="MJiQo/5j"; 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 AC072385B51F for ; Mon, 3 Apr 2023 19:46:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AC072385B51F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680551194; bh=hxdLNA5lHWwP4MaByGHbtWhbrY0cmgOuLJEc/kWwims=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MJiQo/5jsheXzfmDh8nzGU/ngnBH+86E6moIAx6bk2O/oMJ/gS0aO2H5XFCsT/JK4 U949sQgc7BC+5G4tvG9BtNVQokbNLiKei8JTevSt60Y7QUaNBwy3oh6f5LwG/pxwYt FMW0EvwiE1zRCPPHgoYO4KIWq0ugd+evUQNqld1w= 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.18]) by sourceware.org (Postfix) with ESMTPS id 3FD123858D39; Mon, 3 Apr 2023 19:45:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FD123858D39 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.89.165] ([93.207.89.165]) by web-mail.gmx.net (3c-app-gmx-bs28.server.lan [172.19.170.80]) (via HTTP); Mon, 3 Apr 2023 21:45:48 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: reject module variable as character length in PARAMETER [PR104349] Date: Mon, 3 Apr 2023 21:45:48 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:O8GQMh6IeioKIwxa4l5UU7H2y4lNNFe5QHRz2CNIGxMkutHCXnNnz/HRH+k3iL202HBRM ipMgYNt9wnANcH5860GB+XNBkejz5zOlBZju0mA4agIHNmghGWofnw7di6yn5R2COLNK18zBdDgx 2l6lHDdyXn/l3mZ536fsIFhFHKaD5ojwSzeIM45jXZKAoS0wi5xkAlLX/Gh+0gsyR8BVtgwQOW6u cfEkXSjTA8OblZwTBG4y2NBCN5S/1wANFTT1b9Mtq5u8q1WVs3SPgJombsEW4g6/PJeS9ZoyChmn UY= UI-OutboundReport: notjunk:1;M01:P0:gpz1kfiNRzs=;xfIKU0RF8s20s2pM5ACUE1q8Vvh M4UuHqp1953StqBW5XZ5FQ11q1DEdQlOqqyjkJszy8q52ZfaJcL03AuEoPq0h2GPJ4d2eRRwi u/XLS5M0pvh3x6NJkVG0cAL7HiUb/H78NzPVXbA9IZPQPOP0dqhX6b3ruYFddHplVOJnUS+5A /F98Fk0SqZzTo/udDJdGMWrLhuNFjHYyimEPkPnpNUjPpRhMihhVRRIkc03Jj03SoVuV/TTSB YZLirM681/1I71aY+BAfWzkLE1rijpMwwmOT9Fni7u1Dijcxq9/9na1RCW1VCI2EkbZrM6wyO 6AErmUfQCvCp4GPzagjZqXBkIQT5KogOXsmVSQaG0/waMrCMpriQ6owEEkIjPe5q1yVD8OS/W IX87MGi1HiFxJWAOblS4wcuo0tsc99eAuMTMKGzlV4RSiorNC1XNIWa3w7+HHGkiG+8OJX8Qe DJE0vrMnhQRETCzSyybJQMvQGMSMkzo7FWYp0zQRXwNLGxBb/3Xuvea4FtnhB90us/UrCQf9F wJ6OknJ4G5OyY+Ztb40uU6ge5GJ1wqEIo45dDv7LiP4QbKwo1YMa13ILTXj25iC/3r5KUbERI apdLCHxxShEzTdUyes5/6XVCrzfOQy7De9Eklso79CPNLePpiBaad94ud4+SlS25dAWgZ7CMn hcSkUaw3SLUYArjY1Q71ZZsYrxj6FE4KviAnjI0JSJKtGsCNUxrO7DwShOk8HEl/cPEsgKnOP BUq31hxYalmnkeL+6CMwFwelHawj3/i2rRv4Ks6HXClfDC0AIeI/6Bfl0JXPQUqCXYYJuLLOR XW/KahA+wwuKdyKoLtxiSOQg== X-Spam-Status: No, score=-12.9 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?1762185660444469966?= X-GMAIL-MSGID: =?utf-8?q?1762185660444469966?= Dear all, the attached patch fixes an ICE-on-invalid for a PARAMETER expression where the character length was a MODULE variable. The ICE seemed strange, as we were catching related erroneous code for declarations in programs or subroutines. Removing a seemingly bogus check of restricted expressions is the simplest way to fix this. (We could also catch this differently in decl.cc). Besides, this also fixes an accepts-invalid, see testcase. :-) Regtested on x86_64-pc-linux-gnu. OK for mainline (13) or rather wait? Thanks, Harald From 37136ce94b44149dd013b3d7fed7adba769241e6 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 3 Apr 2023 21:34:01 +0200 Subject: [PATCH] Fortran: reject module variable as character length in PARAMETER [PR104349] gcc/fortran/ChangeLog: PR fortran/104349 * expr.cc (check_restricted): Adjust check for valid variables in restricted expressions: make no exception for module variables. gcc/testsuite/ChangeLog: PR fortran/104349 * gfortran.dg/der_charlen_1.f90: Adjust dg-patterns. * gfortran.dg/pr104349.f90: New test. --- gcc/fortran/expr.cc | 2 -- gcc/testsuite/gfortran.dg/der_charlen_1.f90 | 2 ++ gcc/testsuite/gfortran.dg/pr104349.f90 | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr104349.f90 diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index 7fb33f81788..02028f993fd 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -3504,8 +3504,6 @@ check_restricted (gfc_expr *e) || sym->attr.implied_index || sym->attr.flavor == FL_PARAMETER || is_parent_of_current_ns (sym->ns) - || (sym->ns->proc_name != NULL - && sym->ns->proc_name->attr.flavor == FL_MODULE) || (gfc_is_formal_arg () && (sym->ns == gfc_current_ns))) { t = true; diff --git a/gcc/testsuite/gfortran.dg/der_charlen_1.f90 b/gcc/testsuite/gfortran.dg/der_charlen_1.f90 index 9f394c73f25..1246522d516 100644 --- a/gcc/testsuite/gfortran.dg/der_charlen_1.f90 +++ b/gcc/testsuite/gfortran.dg/der_charlen_1.f90 @@ -22,3 +22,5 @@ CONTAINS type(T), intent(in) :: X end subroutine end module another_core + +! { dg-prune-output "cannot appear in the expression" } diff --git a/gcc/testsuite/gfortran.dg/pr104349.f90 b/gcc/testsuite/gfortran.dg/pr104349.f90 new file mode 100644 index 00000000000..2bea4a37214 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr104349.f90 @@ -0,0 +1,8 @@ +! { dg-do compile } +! PR fortran/104349 - reject module variable as character length in PARAMETER +! Contributed by G.Steinmetz + +module m + character(n), parameter :: a(1) = 'b' ! { dg-error "cannot appear" } + character(n), parameter :: c = 'b' ! { dg-error "cannot appear" } +end -- 2.35.3