From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by sourceware.org (Postfix) with ESMTPS id 2D0063858C50 for ; Tue, 5 Apr 2022 17:33:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2D0063858C50 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220405173311euoutp025529bb74378cada789bcf4e15195c4aa~jEHbpER_d0368103681euoutp02O for ; Tue, 5 Apr 2022 17:33:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220405173311euoutp025529bb74378cada789bcf4e15195c4aa~jEHbpER_d0368103681euoutp02O Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220405173311eucas1p27e44258f48eb641e8a5e33fcc649b217~jEHbShPXH0394203942eucas1p2O; Tue, 5 Apr 2022 17:33:11 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 40.8A.09887.65D7C426; Tue, 5 Apr 2022 18:33:10 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220405173310eucas1p176fa6fe5052d6579805a1a85f0d727e7~jEHaZZiz90943909439eucas1p1t; Tue, 5 Apr 2022 17:33:10 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220405173310eusmtrp271076e0f4c93ca7d580902aba0c16f71~jEHaYwwQB0255302553eusmtrp2e; Tue, 5 Apr 2022 17:33:10 +0000 (GMT) X-AuditID: cbfec7f4-471ff7000000269f-8e-624c7d565e13 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 33.FD.09404.55D7C426; Tue, 5 Apr 2022 18:33:09 +0100 (BST) Received: from Kashkarov (unknown [106.109.129.148]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220405173309eusmtip1ebe40d49b2b86b5484b0f8e63508a7ef~jEHaB2Zbt0434604346eusmtip1c; Tue, 5 Apr 2022 17:33:09 +0000 (GMT) From: Mike Kashkarov To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/104812: generate error for constuct-name clash with symbols Date: Tue, 05 Apr 2022 20:33:09 +0300 Message-ID: <874k37xwoa.fsf@samsung.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPIsWRmVeSWpSXmKPExsWy7djP87phtT5JBms+WVi0zv7BYvHpf7oD k8fR+xuZAhijuGxSUnMyy1KL9O0SuDKadp9hLPilX/H4w0nWBsZW1S5GDg4JAROJm1OFuhi5 OIQEVjBKdE1tY4VwvjBKXOpdxQThfGaUmP19CxNMx50WLYj4ckaJyfenskA4LxklXtz5CuRw crAJ6Ek8fPaeFcQWETCQ2PDlNCOILSwQKdHybCUziM0ioCpx9uI2sBpeAQ2JnpYuRghbUOLk zCdgc5gF9CVmT+8GO0lCoJFD4ubFD2AJCQEXiavrvzNB2MISr45vYYewZST+75wPFc+XuHLk F1R9icTWyZ+h4vYS63cfZoWwHSW2PV7GCPEZn8SNt4IQe/kkJm2bzgwR5pXoaBOCqFaVmLfv KDOELS3RfeMzI4TtIXHrDCR8hARiJRrP+k9glJ2F5JlZSJ6BsCUkDr54wQxhS0nM+HMEys6U 2L/hGDuELSvR+XcD0wJGtlWM4qmlxbnpqcVGeanlesWJucWleel6yfm5mxiB6eD0v+NfdjAu f/VR7xAjEwfjIUYVoOZHG1ZfYJRiycvPS1US4a3K9UkS4k1JrKxKLcqPLyrNSS0+xCjNwaIk zpucuSFRSCA9sSQ1OzW1ILUIJsvEwSnVwOT+LWaWl02hg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l3L27ucm+eYR47ET7v+PTc6NaKeO7Y/immd OC9p5scpcue3C/av/ec/ffHRRfIKO32KDX8IPX0S0n4nbNLB19v3rl//nWOS/rLndpGJfTcz HmxxYot8mqj04nsye20X8/Fjf/PEPqw/L6uflrn2VeZ/4/Nnvi9UFG9WnZXa8EGm7Kn4hPUT wjjrZuk9lpMNklo0Y8VGvrWMG7dd02C2Ew87m7T745xF26aF/t5sd1q774DGqj2PKvjPXZmk xFKckWioxVxUnAgAXcdpEu8CAAA= X-CMS-MailID: 20220405173310eucas1p176fa6fe5052d6579805a1a85f0d727e7 X-Msg-Generator: CA X-RootMTR: 20220405173310eucas1p176fa6fe5052d6579805a1a85f0d727e7 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220405173310eucas1p176fa6fe5052d6579805a1a85f0d727e7 References: X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Apr 2022 17:33:17 -0000 --=-=-= Content-Type: text/plain Greetings, Propose patch for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104812 to reject non-conforming code when construct-name clashes with already defined symbol names, e.g: subroutine s1 logical :: x x: if (x) then ! Currently gfortran accepts 'x' as constuct-name end if x end Steve Kargl poited that (Fortran 2018, 19.4, p 498): Identifiers of entities, other than statement or construct entities (19.4), in the classes (1) named variables, ..., named constructs, ..., Within its scope, a local identifier of one class shall not be the same as another local identifier of the same class, Regtested on x86_64-pc-linux-gnu, OK for mainline? Thanks. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename="0001-Fortran-add-error-for-constuct-name-conflicts-with-s.patch" Content-Description: pr104812 >From 7c2749e3963733bf862fc58d3a068b0468a68c7f Mon Sep 17 00:00:00 2001 From: Mike Kashkarov Date: Mon, 14 Mar 2022 12:31:23 +0900 Subject: [PATCH] PR fortran/104812: generate error for constuct-name clash with symbols gcc/fortran/ChangeLog: PR fortran/104812 * match.cc (gfc_match_label): Add new error message if constuct-name conflicts with other symbols in scope. gcc/testsuite/ChangeLog: PR fortran/102332 * gcc/testsuite/gfortran.dg/pr104812.f90: New test. * gcc/testsuite/gfortran.dg/pr65045.f90: Update. --- gcc/fortran/match.cc | 17 +++++++++++++ gcc/testsuite/gfortran.dg/pr104812.f90 | 35 ++++++++++++++++++++++++++ gcc/testsuite/gfortran.dg/pr65045.f90 | 17 ++++++------- 3 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr104812.f90 diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc index 8edfe4a3a2d..8226fd4322b 100644 --- a/gcc/fortran/match.cc +++ b/gcc/fortran/match.cc @@ -576,6 +576,7 @@ cleanup: static match gfc_match_label (void) { + gfc_symtree *st; char name[GFC_MAX_SYMBOL_LEN + 1]; match m; @@ -585,6 +586,15 @@ gfc_match_label (void) if (m != MATCH_YES) return m; + // Check if we have symbol with matched name in scope. + // From 19.3.1: + // Identifiers of entities, other than statement or construct entities (19.4), + // in the classes + // (1) named variables, ..., named constructs, ..., + // Within its scope, a local identifier of one class shall not be the + // same as another local identifier of the same class, ... + st = gfc_find_symtree (gfc_current_ns->sym_root, name); + if (gfc_get_symbol (name, NULL, &gfc_new_block)) { gfc_error ("Label name %qs at %C is ambiguous", name); @@ -597,6 +607,13 @@ gfc_match_label (void) return MATCH_ERROR; } + if (st != 0) + { + gfc_error ("Construct label %qs at %C already defined here %L", name, + &st->n.sym->declared_at); + return MATCH_ERROR; + } + if (!gfc_add_flavor (&gfc_new_block->attr, FL_LABEL, gfc_new_block->name, NULL)) return MATCH_ERROR; diff --git a/gcc/testsuite/gfortran.dg/pr104812.f90 b/gcc/testsuite/gfortran.dg/pr104812.f90 new file mode 100644 index 00000000000..d103e93a184 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr104812.f90 @@ -0,0 +1,35 @@ +! { dg-do compile } + +subroutine s0 + logical :: x ! { dg-error "Construct label .x. at .1. already defined here .2." } + x: block ! { dg-error "Construct label .x. at .1. already defined here .2." } + end block x ! { dg-error "Expecting END SUBROUTINE" } +end + +subroutine s1 + logical :: x ! { dg-error "Construct label .x. at .1. already defined here .2." } + x: if (.true.) ! { dg-error "Construct label .x. at .1. already defined here .2." } + endif x ! { dg-error "Expecting END SUBROUTINE" } +end + +subroutine s2 + logical :: x ! { dg-error "Construct label .x. at .1. already defined here .2." } + real :: y ! { dg-error "Construct label .y. at .1. already defined here .2." } + + x: block ! { dg-error "Construct label .x. at .1. already defined here .2." } + end block x ! { dg-error "Expecting END SUBROUTINE" } + + y: block ! { dg-error "Construct label .y. at .1. already defined here .2." } + end block y ! { dg-error "Expecting END SUBROUTINE" } +end + +subroutine s3 + logical :: x ! { dg-error "Construct label .x. at .1. already defined here .2." } + real :: y ! { dg-error "Construct label .y. at .1. already defined here .2." } + + x: if (.true.) ! { dg-error "Construct label .x. at .1. already defined here .2." } + endif x ! { dg-error "Expecting END SUBROUTINE" } + + y: if (.true.) ! { dg-error "Construct label .y. at .1. already defined here .2." } + endif y ! { dg-error "Expecting END SUBROUTINE" } +end diff --git a/gcc/testsuite/gfortran.dg/pr65045.f90 b/gcc/testsuite/gfortran.dg/pr65045.f90 index c49652993d7..eba4f5d2882 100644 --- a/gcc/testsuite/gfortran.dg/pr65045.f90 +++ b/gcc/testsuite/gfortran.dg/pr65045.f90 @@ -2,14 +2,13 @@ ! ! Contributed by Walt Brainerd ! -real :: i = 9.9 -i:block - if (i>7.7) then ! { dg-error "is not appropriate for an expression" } - exit i - else ! { dg-error "Unexpected ELSE statement" } - i = 2.2 ! { dg-error "is not a variable" } - end if ! { dg-error "Expecting END BLOCK statement" } +real :: i = 9.9 ! { dg-error "Construct label .i. at .1. already defined here .2." } +i:block ! { dg-error "Construct label .i. at .1. already defined here .2." } + if (i>7.7) then + exit i ! { dg-error "Name .i. in EXIT statement at .1. is not a construct name" } + else + i = 2.2 + end if end block i ! { dg-error "Expecting END PROGRAM statement" } -print*,i ! { dg-error "not appropriate for an expression" } +print*,i end -! { dg-error "Unexpected end of file" "" { target "*-*-*" } 0 } -- 2.35.1 --=-=-=--