This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, fortran] PR31473 - no error on duplicate EXTERNAL or INTRINSIC declarations


Attached patch emits an errors for duplicate external and intrinsic 
declarations as in the following code:

$> cat pr31473.f90
EXTERNAL foo
EXTERNAL foo
INTRINSIC abs
INTRINSIC abs
END

Due to this comment from the end of symbol.c (gfc_copy_attr) ...

  /* The subroutines that set these bits also cause flavors to be set,
     and that has already happened in the original, so don't let it
     happen again.  */

... I present two fixes to choose from. The first version (pr31473.patch) 
assumes this comment to be still valid, the second and more elegant 
(pr31473-2.patch) assumes that it is not.

I believe the latter to be true as I was not able to determine where this 
flavour-setting is supposed to happen: the function gfc_add_external() calls 
check_used(), check_conflict() and duplicate_attr() to report an error if 
any. Neither of the check_* functions seems to have the side-effect as stated 
by the comment. Both patches were regression tested on i686-pc-linux-gnu 
without issues.


:ADDPATCH fortran:
2007-06-16  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/31473
	* symbol.c (gfc_copy_attr): Emit errors for duplicate 
	EXTERNAL/INTRINSIC statements.


OK to apply either patch to trunk?

Regards
	Daniel
Index: symbol.c
===================================================================
--- symbol.c	(revision 125720)
+++ symbol.c	(working copy)
@@ -1436,15 +1436,12 @@
     goto fail;
   if (src->cray_pointee && gfc_add_cray_pointee (dest, where) == FAILURE)
     goto fail;    
-  
-  /* The subroutines that set these bits also cause flavors to be set,
-     and that has already happened in the original, so don't let it
-     happen again.  */
-  if (src->external)
-    dest->external = 1;
-  if (src->intrinsic)
-    dest->intrinsic = 1;
 
+  if (src->external && gfc_add_external (dest, where) == FAILURE)
+    goto fail;
+  if (src->intrinsic && gfc_add_intrinsic (dest, where) == FAILURE)
+    goto fail;
+
   return SUCCESS;
 
 fail:
Index: symbol.c
===================================================================
--- symbol.c	(revision 125720)
+++ symbol.c	(working copy)
@@ -1441,10 +1441,26 @@
      and that has already happened in the original, so don't let it
      happen again.  */
   if (src->external)
-    dest->external = 1;
+    {
+      if (dest->external)
+        {
+          duplicate_attr ("EXTERNAL", where);
+          goto fail;
+        }
+
+      dest->external = 1;
+    }
   if (src->intrinsic)
-    dest->intrinsic = 1;
+    {
+      if (dest->intrinsic)
+        {
+          duplicate_attr ("INTRINSIC", where);
+          goto fail;
+        }
 
+      dest->intrinsic = 1;
+    }
+
   return SUCCESS;
 
 fail:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]