PR fortran/91959 -- Re-arrange matching of %FILL
diff mbox series

Message ID 20191004181851.GA27050@troutmask.apl.washington.edu
State New
Headers show
Series
  • PR fortran/91959 -- Re-arrange matching of %FILL
Related show

Commit Message

Steve Kargl Oct. 4, 2019, 6:18 p.m. UTC
The attached patch has been tested on x86_64-*-freebsd.
OK to commit.

Apparently, DEC Fortran allows one to use %FILL as a variable name.
When the -fdec code was added to gfortran, variable_decl was updated
to match %FILL.  This was done by first ilooking for the % character,
and if found, it is burned and FILL is then match.  Unfortunately,
as the new testcase shows this allowed any variable starting with
% to match.  The patch re-arranges the code so that an error is
issues for variables starting with %, which are not %FILL.

2019-10-04  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran.91959
	* fortran/decl.c (variable_decl): Re-arrange code for matching %FILL.

2019-10-04  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran.91959
	* gfortran.dg/pr91959.f90: New test.

Comments

Thomas Koenig Oct. 4, 2019, 7:59 p.m. UTC | #1
Hi Steve,

> The attached patch has been tested on x86_64-*-freebsd.
> OK to commit.

OK.

Thanks a lot for the patch!

Since this seems to be a regression to before when %FILL was introduced,
also OK to backport as far as you care to do it.

Regards

	Thomas
Steve Kargl Oct. 4, 2019, 8:45 p.m. UTC | #2
On Fri, Oct 04, 2019 at 09:59:14PM +0200, Thomas Koenig wrote:
> Hi Steve,
> 
> > The attached patch has been tested on x86_64-*-freebsd.
> > OK to commit.
> 
> OK.
> 
> Thanks a lot for the patch!
> 
> Since this seems to be a regression to before when %FILL was introduced,
> also OK to backport as far as you care to do it.
> 

Thanks for quick review.

Patch
diff mbox series

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 276593)
+++ gcc/fortran/decl.c	(working copy)
@@ -2441,6 +2441,7 @@  variable_decl (int elem)
   match m;
   bool t;
   gfc_symbol *sym;
+  char c;
 
   initializer = NULL;
   as = NULL;
@@ -2454,40 +2455,45 @@  variable_decl (int elem)
      name to be '%FILL' which gives it an anonymous (inaccessible) name.  */
   m = MATCH_NO;
   gfc_gobble_whitespace ();
-  if (gfc_peek_ascii_char () == '%')
+  c = gfc_peek_ascii_char ();
+  if (c == '%')
     {
-      gfc_next_ascii_char ();
+      gfc_next_ascii_char ();	/* Burn % character.  */
       m = gfc_match ("fill");
-    }
-
-  if (m != MATCH_YES)
-    {
-      m = gfc_match_name (name);
-      if (m != MATCH_YES)
-	goto cleanup;
-    }
-
-  else
-    {
-      m = MATCH_ERROR;
-      if (gfc_current_state () != COMP_STRUCTURE)
+      if (m == MATCH_YES)
 	{
-	  if (flag_dec_structure)
-	    gfc_error ("%qs not allowed outside STRUCTURE at %C", "%FILL");
-	  else
-	    gfc_error ("%qs at %C is a DEC extension, enable with "
+	  if (gfc_current_state () != COMP_STRUCTURE)
+	    {
+	      if (flag_dec_structure)
+		gfc_error ("%qs not allowed outside STRUCTURE at %C", "%FILL");
+	      else
+		gfc_error ("%qs at %C is a DEC extension, enable with "
 		       "%<-fdec-structure%>", "%FILL");
-	  goto cleanup;
-	}
+	      m = MATCH_ERROR;
+	      goto cleanup;
+	    }
 
-      if (attr_seen)
+	  if (attr_seen)
+	    {
+	      gfc_error ("%qs entity cannot have attributes at %C", "%FILL");
+	      m = MATCH_ERROR;
+	      goto cleanup;
+	    }
+
+	  /* %FILL components are given invalid fortran names.  */
+	  snprintf (name, GFC_MAX_SYMBOL_LEN + 1, "%%FILL%u", fill_id++);
+	}
+      else
 	{
-	  gfc_error ("%qs entity cannot have attributes at %C", "%FILL");
-	  goto cleanup;
+	  gfc_error ("Invalid character %qc in variable name at %C", c);
+	  return MATCH_ERROR;
 	}
-
-      /* %FILL components are given invalid fortran names.  */
-      snprintf (name, GFC_MAX_SYMBOL_LEN + 1, "%%FILL%u", fill_id++);
+    }
+  else
+    {
+      m = gfc_match_name (name);
+      if (m != MATCH_YES)
+	goto cleanup;
     }
 
   var_locus = gfc_current_locus;
Index: gcc/testsuite/gfortran.dg/pr91959.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr91959.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr91959.f90	(working copy)
@@ -0,0 +1,9 @@ 
+! { dg-do compile }
+! PR fortran/91959
+! Code contributed by Gerhard Steinmetz
+program p
+   implicit none
+   integer :: %a  ! { dg-error "Invalid character" }
+   a = 1          ! { dg-error "has no IMPLICIT type" }
+   print *, a 
+end