Fix the fix for PR fortran/90988
diff mbox series

Message ID 20191031221602.GA13698@troutmask.apl.washington.edu
State New
Headers show
Series
  • Fix the fix for PR fortran/90988
Related show

Commit Message

Steve Kargl Oct. 31, 2019, 10:16 p.m. UTC
Jeff Law sent me an email that showed my patch for
PR fortran/90988 caused a regression for fixed-form
source code.  The attached patch address that regression.

Briefly, the original patch fixed free-form souce code
parsing for 'PUBLICX' where the required whitespace was
missing (i.e., 'PUBLIC X').  Unfortunately, the regression
is that the original fix did not preserve fixed-form source
code.

OK to commit?

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

	PR fortran/90988
	* decl.c (gfc_match_private, gfc_match_public): Fixed-form source code
	does not require whitespace between PRIVATE (or PUBLIC) and an entity.

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

	PR fortran/90988
	* gfortran.dg/pr90988_4.f: New test.

Comments

Tobias Burnus Nov. 1, 2019, 7:49 a.m. UTC | #1
On 10/31/19 11:16 PM, Steve Kargl wrote:

> Jeff Law sent me an email … caused a regression for fixed-form
> source code.

Interesting, what kind of code is used in the real world!

> OK to commit?

OK. Thanks for the patch!

Tobias

> 2019-10-31  Steven G. Kargl  <kargl@gcc.gnu.org>
>
> 	PR fortran/90988
> 	* decl.c (gfc_match_private, gfc_match_public): Fixed-form source code
> 	does not require whitespace between PRIVATE (or PUBLIC) and an entity.
>
> 2019-10-31  Steven G. Kargl  <kargl@gcc.gnu.org>
>
> 	PR fortran/90988
> 	* gfortran.dg/pr90988_4.f: New test.
Jeff Law Nov. 1, 2019, 12:49 p.m. UTC | #2
On 11/1/19 1:49 AM, Tobias Burnus wrote:
> On 10/31/19 11:16 PM, Steve Kargl wrote:
> 
>> Jeff Law sent me an email … caused a regression for fixed-form
>> source code.
> 
> Interesting, what kind of code is used in the real world!
It's from the dl_poly package in Fedora IIRC.  It was the only instance
of this problem across the Fedora builds.
jeff
Steve Kargl Nov. 1, 2019, 3:53 p.m. UTC | #3
On Fri, Nov 01, 2019 at 08:49:58AM +0100, Tobias Burnus wrote:
> On 10/31/19 11:16 PM, Steve Kargl wrote:
> 
> > Jeff Law sent me an email … caused a regression for fixed-form
> > source code.
> 
> Interesting, what kind of code is used in the real world!
> 

Jeff sent me the file from dl_poly that ran into thre regression.
The dl_ploy developers use modern Fortran, but at least one file
restrict themselves to fixed-form source code.  This seems to be
an odd choice to me, but it is legal Fortran.

> > OK to commit?
> 
> OK. Thanks for the patch!
> 

Thanks.  And, sorry about the regression.

Patch
diff mbox series

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 277696)
+++ gcc/fortran/decl.c	(working copy)
@@ -9059,7 +9079,6 @@  match
 gfc_match_private (gfc_statement *st)
 {
   gfc_state_data *prev;
-  char c;
 
   if (gfc_match ("private") != MATCH_YES)
     return MATCH_NO;
@@ -9083,10 +9102,14 @@  gfc_match_private (gfc_statement *st)
       return MATCH_YES;
     }
 
-  /* At this point, PRIVATE must be followed by whitespace or ::.  */
-  c = gfc_peek_ascii_char ();
-  if (!gfc_is_whitespace (c) && c != ':')
-    return MATCH_NO;
+  /* At this point in free-form source code, PRIVATE must be followed
+     by whitespace or ::.  */
+  if (gfc_current_form == FORM_FREE)
+    {
+      char c = gfc_peek_ascii_char ();
+      if (!gfc_is_whitespace (c) && c != ':')
+	return MATCH_NO;
+    }
 
   prev = gfc_state_stack->previous;
   if (gfc_current_state () != COMP_MODULE
@@ -9108,8 +9131,6 @@  gfc_match_private (gfc_statement *st)
 match
 gfc_match_public (gfc_statement *st)
 {
-  char c;
-
   if (gfc_match ("public") != MATCH_YES)
     return MATCH_NO;
 
@@ -9127,10 +9148,14 @@  gfc_match_public (gfc_statement *st)
       return MATCH_YES;
     }
 
-  /* At this point, PUBLIC must be followed by whitespace or ::.  */
-  c = gfc_peek_ascii_char ();
-  if (!gfc_is_whitespace (c) && c != ':')
-    return MATCH_NO;
+  /* At this point in free-form source code, PUBLIC must be followed
+     by whitespace or ::.  */
+  if (gfc_current_form == FORM_FREE)
+    {
+      char c = gfc_peek_ascii_char ();
+      if (!gfc_is_whitespace (c) && c != ':')
+	return MATCH_NO;
+    }
 
   if (gfc_current_state () != COMP_MODULE)
     {
Index: gcc/testsuite/gfortran.dg/pr90988_4.f
===================================================================
--- gcc/testsuite/gfortran.dg/pr90988_4.f	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr90988_4.f	(working copy)
@@ -0,0 +1,10 @@ 
+c { dg-do compile }
+       module foo
+          implicit none
+          real a,b,c
+          integer i,j,k
+          public a,b
+          publicc
+          private i,j
+          privatek
+       end module foo