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] Fix --enable-checking=valgrind libcpp issue on cpp/line5.c


Hi!

On cpp/line5.c cc1 fails under valgrind (even without
--enable-checking=valgrind).  The problem is that _cpp_handle_directive
called by read_original_filename refuses to handle it as a directive,
because # isn't at the beginning of the line, thus pushes the line number
back into lookaheads.  But then read_original_directory (which isn't
desirable in that case) uses _cpp_lex_token_direct (ignores the pushed back
token) and pushes it back, which leads to uninitialized token data.
When the first line doesn't contain a valid filename directive, we shouldn't
be looking at the original directory on the next line.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
for trunk and 4.4?

2010-02-11  Jakub Jelinek  <jakub@redhat.com>

	* init.c (read_original_filename): Don't call read_original_directory
	if _cpp_handle_directive returns 0.

--- libcpp/init.c.jj	2009-11-12 14:14:03.000000000 +0100
+++ libcpp/init.c	2010-02-11 17:31:23.000000000 +0100
@@ -1,7 +1,7 @@
 /* CPP Library.
    Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
-   2009 Free Software Foundation, Inc.
+   2009, 2010 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
@@ -595,9 +595,9 @@ read_original_filename (cpp_reader *pfil
       pfile->state.in_directive = 0;
 
       /* If it's a #line directive, handle it.  */
-      if (token1->type == CPP_NUMBER)
+      if (token1->type == CPP_NUMBER
+	  && _cpp_handle_directive (pfile, token->flags & PREV_WHITE))
 	{
-	  _cpp_handle_directive (pfile, token->flags & PREV_WHITE);
 	  read_original_directory (pfile);
 	  return;
 	}

	Jakub


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