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: FYI: fix PR preprocessor/34602


I'm checking this in.

This fixes PR preprocessor/34602, an internal error on a simple test
case.  The bug is that we were trying to spell the EOF token.  The fix
is to emit a different error message in this case.

Test case included.  Bootstrapped and regtested on x86 F8.

I looked at all other callers of cpp_token_as_text and didn't see any
other situations where we could try to spell CPP_EOF.

Tom

libcpp/ChangeLog:
2008-01-03  Tom Tromey  <tromey@redhat.com>

	PR preprocessor/34602.
	* directives.c (do_line): Don't try to spell EOF token.
	(do_linemarker): Add comment.

gcc/testsuite/ChangeLog:
2008-01-03  Tom Tromey  <tromey@redhat.com>

	PR preprocessor/34602:
	* gcc.dg/cpp/pr34602.c: New file.

Index: libcpp/directives.c
===================================================================
--- libcpp/directives.c	(revision 131303)
+++ libcpp/directives.c	(working copy)
@@ -1,7 +1,7 @@
 /* CPP Library. (Directive handling.)
    Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
    1999, 2000, 2001, 2002, 2003, 2004, 2005,
-   2007 Free Software Foundation, Inc.
+   2007, 2008 Free Software Foundation, Inc.
    Contributed by Per Bothner, 1994-95.
    Based on CCCP program by Paul Rubin, June 1986
    Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -864,9 +864,12 @@
       || strtoul_for_line (token->val.str.text, token->val.str.len,
 			   &new_lineno))
     {
-      cpp_error (pfile, CPP_DL_ERROR,
-		 "\"%s\" after #line is not a positive integer",
-		 cpp_token_as_text (pfile, token));
+      if (token->type == CPP_EOF)
+	cpp_error (pfile, CPP_DL_ERROR, "unexpected end of file after #line");
+      else
+	cpp_error (pfile, CPP_DL_ERROR,
+		   "\"%s\" after #line is not a positive integer",
+		   cpp_token_as_text (pfile, token));
       return;
     }
 
@@ -920,6 +923,8 @@
       || strtoul_for_line (token->val.str.text, token->val.str.len,
 			   &new_lineno))
     {
+      /* Unlike #line, there does not seem to be a way to get an EOF
+	 here.  So, it should be safe to always spell the token.  */
       cpp_error (pfile, CPP_DL_ERROR,
 		 "\"%s\" after # is not a positive integer",
 		 cpp_token_as_text (pfile, token));
Index: gcc/testsuite/gcc.dg/cpp/pr34602.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr34602.c	(revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr34602.c	(revision 0)
@@ -0,0 +1,6 @@
+/* PR preprocessor/34602 - no internal error trying to spell EOF.  */
+/* { dg-do preprocess } */
+
+/* { dg-error "unexpected end" "" { target *-*-* } 6 } */
+
+#line


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