public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fortran : ICE in build_field PR95614
@ 2020-09-04  7:35 Mark Eggleston
  2020-09-14  7:23 ` Mark Eggleston
  2020-09-14  8:03 ` Andre Vehreschild
  0 siblings, 2 replies; 5+ messages in thread
From: Mark Eggleston @ 2020-09-04  7:35 UTC (permalink / raw)
  To: gcc-patches, fortran

[-- Attachment #1: Type: text/plain, Size: 2105 bytes --]

Please find attached a fix for PR95614.  The original patch was by Steve 
Kargl.

The original patch resulted in name clashes between global identifiers 
naming common blocks and local identifiers.  According to the 2018 
standard 19.3.1 Classes of local identifiers, item 2, a local identifier 
shall not be the same as a global identifier, however, there is an 
exception where the global identifier is a common block name.

The change to the patch is:

if (gsym && gsym->type != GSYM_UNKNOWN && gsym->type != GSYM_COMMON)

instead of:

if (gsym && gsym->type != GSYM_UNKNOWN)

Tested on x86_64 using make -j 8 check-fortran.

OK to commit?

[PATCH] Fortran  :  ICE in build_field PR95614

Local identifiers can not be the same as a module name. Original
patch by Steve Kargl resulted in name clashes between common block
names and local identifiers.  A local identifier can be the same as
a global identier if that identifier represents a common.  The patch
was modified to allow global identifiers that represent a common
block.

2020-09-04  Steven G. Kargl  <kargl@gcc.gnu.org>
         Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/fortran/

     PR fortran/95614
     * decl.c (gfc_get_common): Use gfc_match_common_name instead
     of match_common_name.
     * decl.c (gfc_bind_idents): Use gfc_match_common_name instead
     of match_common_name.
     * match.c : Rename match_common_name to gfc_match_common_name.
     * match.c (gfc_match_common): Use gfc_match_common_name instead
     of match_common_name.
     * match.h : Rename match_common_name to gfc_match_common_name.
     * resolve.c (resolve_common_vars): Check each symbol in a
     common block has a global symbol.  If there is a global symbol
     issue an error if the symbol type is known as is not a common
     block name.

2020-09-04  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/testsuite/

     PR fortran/95614
     * gfortran.dg/pr95614_1.f90: New test.
     * gfortran.dg/pr95614_2.f90: New test.


-- 
https://www.codethink.co.uk/privacy.html


[-- Attachment #2: 0001-Fortran-ICE-in-build_field-PR95614.patch --]
[-- Type: text/x-patch, Size: 5457 bytes --]

From 658f5bfa1013b92e99d8ffbf994098971f8444f4 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggleston@gcc.gnu.org>
Date: Thu, 11 Jun 2020 14:33:51 +0100
Subject: [PATCH] Fortran  :  ICE in build_field PR95614

Local identifiers can not be the same as a module name.  Original
patch by Steve Kargl resulted in name clashes between common block
names and local identifiers.  A local identifier can be the same as
a global identier if that identifier represents a common.  The patch
was modified to allow global identifiers that represent a common
block.

2020-09-04  Steven G. Kargl  <kargl@gcc.gnu.org>
	    Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/fortran/

	PR fortran/95614
	* decl.c (gfc_get_common): Use gfc_match_common_name instead
	of match_common_name.
	* decl.c (gfc_bind_idents): Use gfc_match_common_name instead
	of match_common_name.
	* match.c : Rename match_common_name to gfc_match_common_name.
	* match.c (gfc_match_common): Use gfc_match_common_name instead
	of match_common_name.
	* match.h : Rename match_common_name to gfc_match_common_name.
	* resolve.c (resolve_common_vars): Check each symbol in a
	common block has a global symbol.  If there is a global symbol
	issue an error if the symbol type is known as is not a common
	block name.

2020-09-04  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/testsuite/

	PR fortran/95614
	* gfortran.dg/pr95614_1.f90: New test.
	* gfortran.dg/pr95614_2.f90: New test.
---
 gcc/fortran/decl.c                      | 4 ++--
 gcc/fortran/match.c                     | 5 +++--
 gcc/fortran/match.h                     | 6 ++----
 gcc/fortran/resolve.c                   | 7 +++++++
 gcc/testsuite/gfortran.dg/pr95614_1.f90 | 6 ++++++
 gcc/testsuite/gfortran.dg/pr95614_2.f90 | 6 ++++++
 6 files changed, 26 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr95614_1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/pr95614_2.f90

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index d854b2a0307..16f40566d33 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -6004,7 +6004,7 @@ get_bind_c_idents (void)
       found_id = MATCH_YES;
       gfc_get_ha_symbol (name, &tmp_sym);
     }
-  else if (match_common_name (name) == MATCH_YES)
+  else if (gfc_match_common_name (name) == MATCH_YES)
     {
       found_id = MATCH_YES;
       com_block = gfc_get_common (name, 0);
@@ -6049,7 +6049,7 @@ get_bind_c_idents (void)
 	      found_id = MATCH_YES;
 	      gfc_get_ha_symbol (name, &tmp_sym);
 	    }
-	  else if (match_common_name (name) == MATCH_YES)
+	  else if (gfc_match_common_name (name) == MATCH_YES)
 	    {
 	      found_id = MATCH_YES;
 	      com_block = gfc_get_common (name, 0);
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index cb09c5f8ec5..bee73e7b008 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -5166,7 +5166,8 @@ gfc_get_common (const char *name, int from_module)
 
 /* Match a common block name.  */
 
-match match_common_name (char *name)
+match
+gfc_match_common_name (char *name)
 {
   match m;
 
@@ -5218,7 +5219,7 @@ gfc_match_common (void)
 
   for (;;)
     {
-      m = match_common_name (name);
+      m = gfc_match_common_name (name);
       if (m == MATCH_ERROR)
 	goto cleanup;
 
diff --git a/gcc/fortran/match.h b/gcc/fortran/match.h
index 7bf70d77016..4ccb5961d2b 100644
--- a/gcc/fortran/match.h
+++ b/gcc/fortran/match.h
@@ -103,11 +103,9 @@ match gfc_match_call (void);
 
 /* We want to use this function to check for a common-block-name
    that can exist in a bind statement, so removed the "static"
-   declaration of the function in match.c.
+   declaration of the function in match.c. */
  
-   TODO: should probably rename this now that it'll be globally seen to
-   gfc_match_common_name.  */
-match match_common_name (char *name);
+match gfc_match_common_name (char *name);
 
 match gfc_match_common (void);
 match gfc_match_block_data (void);
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 6caddcf4ef0..6a36ae96801 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -936,9 +936,16 @@ static void
 resolve_common_vars (gfc_common_head *common_block, bool named_common)
 {
   gfc_symbol *csym = common_block->head;
+  gfc_gsymbol *gsym;
 
   for (; csym; csym = csym->common_next)
     {
+      gsym = gfc_find_gsymbol (gfc_gsym_root, csym->name);
+      if (gsym && gsym->type != GSYM_UNKNOWN && gsym->type != GSYM_COMMON)
+	gfc_error_now ("Global entity %qs at %L cannot appear in a "
+			"COMMON block at %L", gsym->name,
+			&gsym->where, &csym->common_block->where);
+
       /* gfc_add_in_common may have been called before, but the reported errors
 	 have been ignored to continue parsing.
 	 We do the checks again here.  */
diff --git a/gcc/testsuite/gfortran.dg/pr95614_1.f90 b/gcc/testsuite/gfortran.dg/pr95614_1.f90
new file mode 100644
index 00000000000..f835143365a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95614_1.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+
+module m   ! { dg-error ".1." }
+  common m ! { dg-error "cannot appear in a COMMON" }
+end
+
diff --git a/gcc/testsuite/gfortran.dg/pr95614_2.f90 b/gcc/testsuite/gfortran.dg/pr95614_2.f90
new file mode 100644
index 00000000000..9d69a506384
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95614_2.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+
+module m        ! { dg-error ".1." }
+  common /xc/ m ! { dg-error "cannot appear in a COMMON" }
+end
+
-- 
2.11.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fortran : ICE in build_field PR95614
  2020-09-04  7:35 [PATCH] Fortran : ICE in build_field PR95614 Mark Eggleston
@ 2020-09-14  7:23 ` Mark Eggleston
  2020-09-14  8:03 ` Andre Vehreschild
  1 sibling, 0 replies; 5+ messages in thread
From: Mark Eggleston @ 2020-09-14  7:23 UTC (permalink / raw)
  To: gcc-patches, fortran

**ping**

On 04/09/2020 08:35, Mark Eggleston wrote:
> Please find attached a fix for PR95614.  The original patch was by 
> Steve Kargl.
>
> The original patch resulted in name clashes between global identifiers 
> naming common blocks and local identifiers.  According to the 2018 
> standard 19.3.1 Classes of local identifiers, item 2, a local 
> identifier shall not be the same as a global identifier, however, 
> there is an exception where the global identifier is a common block name.
>
> The change to the patch is:
>
> if (gsym && gsym->type != GSYM_UNKNOWN && gsym->type != GSYM_COMMON)
>
> instead of:
>
> if (gsym && gsym->type != GSYM_UNKNOWN)
>
> Tested on x86_64 using make -j 8 check-fortran.
>
> OK to commit?
>
> [PATCH] Fortran  :  ICE in build_field PR95614
>
> Local identifiers can not be the same as a module name. Original
> patch by Steve Kargl resulted in name clashes between common block
> names and local identifiers.  A local identifier can be the same as
> a global identier if that identifier represents a common.  The patch
> was modified to allow global identifiers that represent a common
> block.
>
> 2020-09-04  Steven G. Kargl  <kargl@gcc.gnu.org>
>         Mark Eggleston  <markeggleston@gcc.gnu.org>
>
> gcc/fortran/
>
>     PR fortran/95614
>     * decl.c (gfc_get_common): Use gfc_match_common_name instead
>     of match_common_name.
>     * decl.c (gfc_bind_idents): Use gfc_match_common_name instead
>     of match_common_name.
>     * match.c : Rename match_common_name to gfc_match_common_name.
>     * match.c (gfc_match_common): Use gfc_match_common_name instead
>     of match_common_name.
>     * match.h : Rename match_common_name to gfc_match_common_name.
>     * resolve.c (resolve_common_vars): Check each symbol in a
>     common block has a global symbol.  If there is a global symbol
>     issue an error if the symbol type is known as is not a common
>     block name.
>
> 2020-09-04  Mark Eggleston  <markeggleston@gcc.gnu.org>
>
> gcc/testsuite/
>
>     PR fortran/95614
>     * gfortran.dg/pr95614_1.f90: New test.
>     * gfortran.dg/pr95614_2.f90: New test.
>
>
-- 
https://www.codethink.co.uk/privacy.html


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fortran : ICE in build_field PR95614
  2020-09-04  7:35 [PATCH] Fortran : ICE in build_field PR95614 Mark Eggleston
  2020-09-14  7:23 ` Mark Eggleston
@ 2020-09-14  8:03 ` Andre Vehreschild
  2020-09-24  8:04   ` *PING* " Mark Eggleston
  1 sibling, 1 reply; 5+ messages in thread
From: Andre Vehreschild @ 2020-09-14  8:03 UTC (permalink / raw)
  To: Mark Eggleston; +Cc: gcc-patches, fortran

Hi Marc,

the patch looks reasonable and ok to me. Ok for trunk.

Thanks for the patch.

Regards,
	Andre

On Fri, 4 Sep 2020 08:35:59 +0100
Mark Eggleston <mark.eggleston@codethink.co.uk> wrote:

> Please find attached a fix for PR95614.  The original patch was by Steve 
> Kargl.
> 
> The original patch resulted in name clashes between global identifiers 
> naming common blocks and local identifiers.  According to the 2018 
> standard 19.3.1 Classes of local identifiers, item 2, a local identifier 
> shall not be the same as a global identifier, however, there is an 
> exception where the global identifier is a common block name.
> 
> The change to the patch is:
> 
> if (gsym && gsym->type != GSYM_UNKNOWN && gsym->type != GSYM_COMMON)
> 
> instead of:
> 
> if (gsym && gsym->type != GSYM_UNKNOWN)
> 
> Tested on x86_64 using make -j 8 check-fortran.
> 
> OK to commit?
> 
> [PATCH] Fortran  :  ICE in build_field PR95614
> 
> Local identifiers can not be the same as a module name. Original
> patch by Steve Kargl resulted in name clashes between common block
> names and local identifiers.  A local identifier can be the same as
> a global identier if that identifier represents a common.  The patch
> was modified to allow global identifiers that represent a common
> block.
> 
> 2020-09-04  Steven G. Kargl  <kargl@gcc.gnu.org>
>          Mark Eggleston  <markeggleston@gcc.gnu.org>
> 
> gcc/fortran/
> 
>      PR fortran/95614
>      * decl.c (gfc_get_common): Use gfc_match_common_name instead
>      of match_common_name.
>      * decl.c (gfc_bind_idents): Use gfc_match_common_name instead
>      of match_common_name.
>      * match.c : Rename match_common_name to gfc_match_common_name.
>      * match.c (gfc_match_common): Use gfc_match_common_name instead
>      of match_common_name.
>      * match.h : Rename match_common_name to gfc_match_common_name.
>      * resolve.c (resolve_common_vars): Check each symbol in a
>      common block has a global symbol.  If there is a global symbol
>      issue an error if the symbol type is known as is not a common
>      block name.
> 
> 2020-09-04  Mark Eggleston  <markeggleston@gcc.gnu.org>
> 
> gcc/testsuite/
> 
>      PR fortran/95614
>      * gfortran.dg/pr95614_1.f90: New test.
>      * gfortran.dg/pr95614_2.f90: New test.
> 
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* *PING* Re: [PATCH] Fortran : ICE in build_field PR95614
  2020-09-14  8:03 ` Andre Vehreschild
@ 2020-09-24  8:04   ` Mark Eggleston
  2020-09-24 17:59     ` Thomas König
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Eggleston @ 2020-09-24  8:04 UTC (permalink / raw)
  Cc: gcc-patches, fortran

I haven't yet committed this.

I am unfamiliar with Andre, I've checked MAINTAINERS and I find Andre in 
the "Write after approval" section.

Is Andre's approval sufficient? If so MAINTAINERS needs to be updated.

If not: OK to commit and backport?

regards,

Mark

On 14/09/2020 09:03, Andre Vehreschild wrote:
> Hi Marc,
>
> the patch looks reasonable and ok to me. Ok for trunk.
>
> Thanks for the patch.
>
> Regards,
> 	Andre
>
> On Fri, 4 Sep 2020 08:35:59 +0100
> Mark Eggleston <mark.eggleston@codethink.co.uk> wrote:
>
>> Please find attached a fix for PR95614.  The original patch was by Steve
>> Kargl.
>>
>> The original patch resulted in name clashes between global identifiers
>> naming common blocks and local identifiers.  According to the 2018
>> standard 19.3.1 Classes of local identifiers, item 2, a local identifier
>> shall not be the same as a global identifier, however, there is an
>> exception where the global identifier is a common block name.
>>
>> The change to the patch is:
>>
>> if (gsym && gsym->type != GSYM_UNKNOWN && gsym->type != GSYM_COMMON)
>>
>> instead of:
>>
>> if (gsym && gsym->type != GSYM_UNKNOWN)
>>
>> Tested on x86_64 using make -j 8 check-fortran.
>>
>> OK to commit?
>>
>> [PATCH] Fortran  :  ICE in build_field PR95614
>>
>> Local identifiers can not be the same as a module name. Original
>> patch by Steve Kargl resulted in name clashes between common block
>> names and local identifiers.  A local identifier can be the same as
>> a global identier if that identifier represents a common.  The patch
>> was modified to allow global identifiers that represent a common
>> block.
>>
>> 2020-09-04  Steven G. Kargl  <kargl@gcc.gnu.org>
>>           Mark Eggleston  <markeggleston@gcc.gnu.org>
>>
>> gcc/fortran/
>>
>>       PR fortran/95614
>>       * decl.c (gfc_get_common): Use gfc_match_common_name instead
>>       of match_common_name.
>>       * decl.c (gfc_bind_idents): Use gfc_match_common_name instead
>>       of match_common_name.
>>       * match.c : Rename match_common_name to gfc_match_common_name.
>>       * match.c (gfc_match_common): Use gfc_match_common_name instead
>>       of match_common_name.
>>       * match.h : Rename match_common_name to gfc_match_common_name.
>>       * resolve.c (resolve_common_vars): Check each symbol in a
>>       common block has a global symbol.  If there is a global symbol
>>       issue an error if the symbol type is known as is not a common
>>       block name.
>>
>> 2020-09-04  Mark Eggleston  <markeggleston@gcc.gnu.org>
>>
>> gcc/testsuite/
>>
>>       PR fortran/95614
>>       * gfortran.dg/pr95614_1.f90: New test.
>>       * gfortran.dg/pr95614_2.f90: New test.
>>
>>
>
-- 
https://www.codethink.co.uk/privacy.html


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: *PING* Re: [PATCH] Fortran : ICE in build_field PR95614
  2020-09-24  8:04   ` *PING* " Mark Eggleston
@ 2020-09-24 17:59     ` Thomas König
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas König @ 2020-09-24 17:59 UTC (permalink / raw)
  To: Mark Eggleston; +Cc: gcc-patches, fortran, Toon Moene

Hi Mark,

> I haven't yet committed this.

> I am unfamiliar with Andre, I've checked MAINTAINERS and I find Andre in 
> the "Write after approval" section.
> 
> Is Andre's approval sufficient? If so MAINTAINERS needs to be updated.

The official list of people who can review is at

https://gcc.gnu.org/fortran/

but that is clearly not sufficient.  We need to update it to reflect
current realities, there are people who have approved patches (with
nobody objecting) for a long time, and many people who are on that list
are no longer active.

I'm not 100% sure what is needed to update that file, if we need OK
from the steering committee or not.  I had already taken a straw
poll I think I will simply do tomorrow moring.  If anybody
strenuously objects, we can always revert the patch :-)

> If not: OK to commit and backport?

OK from my side, and thanks for the patch.

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-24 17:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-04  7:35 [PATCH] Fortran : ICE in build_field PR95614 Mark Eggleston
2020-09-14  7:23 ` Mark Eggleston
2020-09-14  8:03 ` Andre Vehreschild
2020-09-24  8:04   ` *PING* " Mark Eggleston
2020-09-24 17:59     ` Thomas König

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).