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]

[gfortran] Fix RETURN matcher was: Re: bug fc110


The return statement is special in that it is the only case where a keyword is
immediately followed by an expression.  This means that in most cases a blank
is required after the RETURN keyword, but not always, according to 3.3.1 "A
blank shall be used to separate names, constants, or labels from adjacent
keywords, names, constants, or labels."

I.e. the following is valid:
 return(1)
the following is invalid
 return1
and the following is indeterminate:
 return+1
because it is invalid if +1 is a constant, but valid if +1 is an expression.
The latter seems to be more consistent, but I think it's really ugly.  ifc
accept it, though, so I chose to support this as well.  (g77 also accepts
this, but that is due to the wonders of fixed-form).

While I was touching gfc_match_return I moved the warning about a RETURN found
in the main program to a place where we're actually sure that we're dealing
with a return statement, and not something like "return1 = 5".  I also fixed
the parse tree dumper from segfaulting when it encounters an alternate return
in an arglist (did noone notice this before??)

Bubblestrapped and regtested, ok?

- Tobi

2005-04-11  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>

	* match.c (gfc_match_return): Only require space after keyword when
	it is obligatory.  Only give stdwarn to after matching is successful.
	* dump-parse-tree.c (gfc_show_symbol): Deal with alternate returns.

Index: match.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/match.c,v
retrieving revision 1.35
diff -u -p -r1.35 match.c
--- match.c     9 Apr 2005 09:13:53 -0000       1.35
+++ match.c     11 Apr 2005 12:06:01 -0000
@@ -1974,12 +1974,7 @@ gfc_match_return (void)
   gfc_expr *e;
   match m;
   gfc_compile_state s;
-
-  gfc_enclosing_unit (&s);
-  if (s == COMP_PROGRAM
-      && gfc_notify_std (GFC_STD_GNU, "Extension: RETURN statement in "
-                        "main program at %C") == FAILURE)
-      return MATCH_ERROR;
+  int c;

   e = NULL;
   if (gfc_match_eos () == MATCH_YES)
@@ -1992,7 +1987,18 @@ gfc_match_return (void)
       goto cleanup;
     }

-  m = gfc_match ("% %e%t", &e);
+  if (gfc_current_form == FORM_FREE)
+    {
+      /* The following are valid, so we can't require a blank after the
+        RETURN keyword:
+          return+1
+          return(1)  */
+      c = gfc_peek_char ();
+      if (ISALPHA (c) || ISDIGIT (c))
+       return MATCH_NO;
+    }
+
+  m = gfc_match (" %e%t", &e);
   if (m == MATCH_YES)
     goto done;
   if (m == MATCH_ERROR)
@@ -2005,6 +2011,12 @@ cleanup:
   return MATCH_ERROR;

 done:
+  gfc_enclosing_unit (&s);
+  if (s == COMP_PROGRAM
+      && gfc_notify_std (GFC_STD_GNU, "Extension: RETURN statement in "
+                        "main program at %C") == FAILURE)
+      return MATCH_ERROR;
+
   new_st.op = EXEC_RETURN;
   new_st.expr = e;

Index: dump-parse-tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/dump-parse-tree.c,v
retrieving revision 1.15
diff -u -p -r1.15 dump-parse-tree.c
--- dump-parse-tree.c   19 Mar 2005 19:45:33 -0000      1.15
+++ dump-parse-tree.c   11 Apr 2005 12:06:01 -0000
@@ -665,7 +665,12 @@ gfc_show_symbol (gfc_symbol * sym)
       gfc_status ("Formal arglist:");

       for (formal = sym->formal; formal; formal = formal->next)
-       gfc_status (" %s", formal->sym->name);
+       {
+         if (formal->sym != NULL)
+           gfc_status (" %s", formal->sym->name);
+         else
+           gfc_status (" [Alt Return]");
+       }
     }

   if (sym->formal_ns)


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