diff mbox series

[gfortran] PR 61450: ICE in gfc_global_used()

Message ID 3DFB4E8F-3B15-4A07-B090-C184C89965C5@lps.ens.fr
State New
Headers show
Series [gfortran] PR 61450: ICE in gfc_global_used() | expand

Commit Message

Dominique d'Humières Sept. 24, 2017, 2:13 p.m. UTC
Rebased FX’s patch.

Tested on x86_64-apple-darwin16.Is it OK with the proper log entries added?

TIA

Dominique

Comments

Dominique d'Humières Sept. 30, 2017, 12:21 p.m. UTC | #1
As noticed by Thomas on IRC, the FX's patch may not be translator friendly. I have now tested the following

--- ../_clean/gcc/fortran/parse.c	2017-09-01 19:00:10.000000000 +0200
+++ gcc/fortran/parse.c	2017-09-28 17:55:14.000000000 +0200
@@ -5742,16 +5742,28 @@ gfc_global_used (gfc_gsymbol *sym, locus
       name = "MODULE";
       break;
     default:
-      gfc_internal_error ("gfc_global_used(): Bad type");
       name = NULL;
     }
 
-  if (sym->binding_label)
-    gfc_error ("Global binding name %qs at %L is already being used as a %s "
-	       "at %L", sym->binding_label, where, name, &sym->where);
+  if (name)
+    {
+      if (sym->binding_label)
+	gfc_error ("Global binding name %qs at %L is already being used "
+		   "as a %s at %L", sym->binding_label, where, name,
+		   &sym->where);
+      else
+	gfc_error ("Global name %qs at %L is already being used as "
+		   "a %s at %L", sym->name, where, name, &sym->where);
+    }
   else
-    gfc_error ("Global name %qs at %L is already being used as a %s at %L",
-	       sym->name, where, name, &sym->where);
+    {
+      if (sym->binding_label)
+	gfc_error ("Global binding name %qs at %L is already being used "
+		   "at %L", sym->binding_label, where, &sym->where);
+      else
+	gfc_error ("Global name %qs at %L is already being used at %L",
+		   sym->name, where, &sym->where);
+    }
 }
 
 I have also tried to avoid the nested IFs following the Thomas’ suggestion to use

label = sym->binding_label ? sym->binding_label : sym->name;

but this does not handle "Global binding name "/"Global name ».

Dominique

> Le 24 sept. 2017 à 16:13, Dominique d'Humières <dominiq@lps.ens.fr> a écrit :
> 
> Rebased FX’s patch.
> 
> Tested on x86_64-apple-darwin16.Is it OK with the proper log entries added?
> 
> TIA
> 
> Dominique
Thomas Koenig Oct. 1, 2017, 8:37 a.m. UTC | #2
Hi Dominique,

The patch is OK for trunk.

Thanks!

	Thomas
Dominique d'Humières Oct. 1, 2017, 10:03 a.m. UTC | #3
Committed as revision r253328 with the change logs

2017-10-01  Dominique d'Humieres  <dominiq@lps.ens.fr>

	PR fortran/61450
	* parse.c (gfc_global_used): Replace the gfc_internal_error
	with an error.

2017-10-01  Dominique d'Humieres  <dominiq@lps.ens.fr>

	PR fortran/61450
	* gfortran.dg/binding_label_tests_28.f90: New test.

Thanks for the review,

Dominique

> Le 1 oct. 2017 à 10:37, Thomas Koenig <tkoenig@netcologne.de> a écrit :
> 
> Hi Dominique,
> 
> The patch is OK for trunk.
> 
> Thanks!
> 
> 	Thomas
diff mbox series

Patch

diff -up ../_clean/gcc/fortran/parse.c gcc/fortran/parse.c
--- ../_clean/gcc/fortran/parse.c	2017-01-22 20:50:56.000000000 +0100
+++ gcc/fortran/parse.c	2017-01-24 10:01:32.000000000 +0100
@@ -5724,34 +5724,33 @@  gfc_global_used (gfc_gsymbol *sym, locus
   switch(sym->type)
     {
     case GSYM_PROGRAM:
-      name = "PROGRAM";
+      name = "as a PROGRAM ";
       break;
     case GSYM_FUNCTION:
-      name = "FUNCTION";
+      name = "as a FUNCTION ";
       break;
     case GSYM_SUBROUTINE:
-      name = "SUBROUTINE";
+      name = "as a SUBROUTINE ";
       break;
     case GSYM_COMMON:
-      name = "COMMON";
+      name = "as a COMMON ";
       break;
     case GSYM_BLOCK_DATA:
-      name = "BLOCK DATA";
+      name = "as a BLOCK DATA ";
       break;
     case GSYM_MODULE:
-      name = "MODULE";
+      name = "as a MODULE ";
       break;
     default:
-      gfc_internal_error ("gfc_global_used(): Bad type");
-      name = NULL;
+      name = "";
     }
 
   if (sym->binding_label)
-    gfc_error ("Global binding name %qs at %L is already being used as a %s "
+    gfc_error ("Global binding name %qs at %L is already being used %s"
 	       "at %L", sym->binding_label, where, name, &sym->where);
   else
-    gfc_error ("Global name %qs at %L is already being used as a %s at %L",
-	       sym->name, where, name, &sym->where);
+    gfc_error ("Global name %qs at %L is already being used %s"
+	       "at %L", sym->name, where, name, &sym->where);
 }
 
 
--- ../_clean/gcc/testsuite/gfortran.dg/binding_label_tests_28.f90	1970-01-01 01:00:00.000000000 +0100
+++ gcc/testsuite/gfortran.dg/binding_label_tests_28.f90	2017-01-13 17:32:01.000000000 +0100
@@ -0,0 +1,12 @@ 
+! { dg-do compile }
+!
+! PR fortran/61450
+! Contributed by Francois-Xavier Coudert  <fxcoudert@gmail.com>
+!
+module p
+  integer i1 ! { dg-error "Global binding name 'foo' at .1. is already being used at .2." }
+  bind(c,name="foo") :: i1
+end module
+
+subroutine truc() bind(c,name="foo") ! { dg-error "Global binding name 'foo' at .1. is already being used at .2." }
+end