* [PATCH] PR fortran/104812: generate error for constuct-name clash with symbols
[not found] <CGME20220405173310eucas1p176fa6fe5052d6579805a1a85f0d727e7@eucas1p1.samsung.com>
@ 2022-04-05 17:33 ` Mike Kashkarov
[not found] ` <CGME20220405173310eucas1p176fa6fe5052d6579805a1a85f0d727e7@eucms1p3>
0 siblings, 1 reply; 2+ messages in thread
From: Mike Kashkarov @ 2022-04-05 17:33 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 720 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr104812 --]
[-- Type: text/x-patch, Size: 5024 bytes --]
From 7c2749e3963733bf862fc58d3a068b0468a68c7f Mon Sep 17 00:00:00 2001
From: Mike Kashkarov <m.kashkarov@samsung.com>
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 <walt.brainerd@gmail.com>
!
-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
^ permalink raw reply [flat|nested] 2+ messages in thread
* FW: [PATCH] PR fortran/104812: generate error for constuct-name clash with symbols
[not found] ` <CGME20220405173310eucas1p176fa6fe5052d6579805a1a85f0d727e7@eucms1p3>
@ 2022-04-19 10:06 ` Mikhail Kashkarov
0 siblings, 0 replies; 2+ messages in thread
From: Mikhail Kashkarov @ 2022-04-19 10:06 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: image/gif, Size: 13168 bytes --]
[-- Attachment #2: 0001-Fortran-add-error-for-constuct-name-conflicts-with-s.patch --]
[-- Type: application/octet-stream, Size: 5160 bytes --]
From 7c2749e3963733bf862fc58d3a068b0468a68c7f Mon Sep 17 00:00:00 2001
From: Mike Kashkarov <m.kashkarov@samsung.com>
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 <walt.brainerd@gmail.com>
!
-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
[-- Attachment #3: rcptInfo.txt --]
[-- Type: application/octet-stream, Size: 983 bytes --]
=================================================================================================================================
Subject : [PATCH] PR fortran/104812: generate error for constuct-name clash with symbols
From : Mikhail Kashkarov /HPC SW Lab /SRR/Samsung Electronics
Sent Date : 2022-04-05 20:33 GMT+3
=================================================================================================================================
Name Type Job Title Dept. Company
=================================================================================================================================
fortran@gcc.gnu.org TO
gcc-patches@gcc.gnu.org TO
=================================================================================================================================
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-19 10:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20220405173310eucas1p176fa6fe5052d6579805a1a85f0d727e7@eucas1p1.samsung.com>
2022-04-05 17:33 ` [PATCH] PR fortran/104812: generate error for constuct-name clash with symbols Mike Kashkarov
[not found] ` <CGME20220405173310eucas1p176fa6fe5052d6579805a1a85f0d727e7@eucms1p3>
2022-04-19 10:06 ` FW: " Mikhail Kashkarov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).