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]

[PATCH] Fix Fortran #line handling


Hi!

If #line or # <num> directive contains filename, ffelex_hash_ can eat the
whole next line unless junk is present at the end of the # line.
E.g.
# 3 "20010321-1.f" 2 3
causes
LOGICAL ANTI
line not to be seen by the lexer, while if junk is added:
# 3 "20010321-1.f" 2 3 "junk"
it is not eaten.
The reason is that at skipline time, c is already '\n', but skipline then
does:
  /* skip the rest of this line.  */
skipline:
  if ((token != NULL) && !ffelex_kludge_flag_)
    ffelex_token_kill (token);
  while ((c = getc (finput)) != EOF && c != '\n')
    ;
  return c;

ie. does not care if c is already '\n' or EOF.
Fixed by patch below (plus testcase).
Ok to commit? For branch as well (it is not actually a regression - it has
been broken for years, on the other side it seems very broken and does not
do any harm)?

2001-03-21  Jakub Jelinek  <jakub@redhat.com>

	* lex.c (ffelex_hash_): Avoid eating one whole line after
	#line.

	* g77.f-torture/compile/20010321-1.f: New test.

--- gcc/f/lex.c.jj	Wed Mar 21 14:19:51 2001
+++ gcc/f/lex.c	Wed Mar 21 14:31:33 2001
@@ -1412,6 +1412,12 @@ ffelex_hash_ (FILE *finput)
 	  input_filename = old_input_filename;
 	  error ("Use `#line ...' instead of `# ...' in first line");
 	}
+      if (c == '\n' || c == EOF)
+	{
+	  if (token != NULL && !ffelex_kludge_flag_)
+	    ffelex_token_kill (token);
+	  return c;
+	}
     }
   else
     error ("invalid #-line");
--- gcc/testsuite/g77.f-torture/compile/20010321-1.f.jj	Wed Mar 21 14:34:40 2001
+++ gcc/testsuite/g77.f-torture/compile/20010321-1.f	Wed Mar 21 14:35:18 2001
@@ -0,0 +1,8 @@
+# 1 "20010321-1.f"
+      SUBROUTINE TWOEXP
+# 1 "include/implicit.h" 1 3
+      IMPLICIT DOUBLE PRECISION (A-H)
+# 3 "20010321-1.f" 2 3
+      LOGICAL ANTI
+      ANTI = .FALSE.
+      END

	Jakub


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