[PATCH] Fix -traditional-cpp preprocessing (PR preprocessor/39213)

Jakub Jelinek jakub@redhat.com
Fri Dec 17 20:12:00 GMT 2010


Hi!

When doing normal preprocessing, the _cpp_process_line_notes call
in _cpp_lex_direct is guarded by !pfile->overlaid_buffer, which I guess
is to avoid comparing unrelated pointers - the .pos field is from the
normal buffer, while cur if pfile->overlaid_buffer is from the overlay,
thus depending on whether that overlay buffer has been allocated above or
below the normal buffer in the address space it will either work or can
crash.

This patch adds the same test to traditional preprocessing.  I've
bootstrapped/regtested it on x86_64-linux and i686-linux and tries to
preprocess a couple of large files with -traditional-cpp without any
difference, but I can't reproduce the original problem.  CCing
Eric who has managed to reproduce it on Solaris.

Ok for trunk?

2010-12-17  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/39213
	* traditional.c (_cpp_scan_out_logical_line): Don't call
	_cpp_process_line_notes if pfile->overlaid_buffer.

--- libcpp/traditional.c.jj	2009-04-14 16:35:21.000000000 +0200
+++ libcpp/traditional.c	2010-12-17 11:34:18.000000000 +0100
@@ -1,5 +1,5 @@
 /* CPP Library - traditional lexical analysis and macro expansion.
-   Copyright (C) 2002, 2004, 2005, 2007, 2008, 2009
+   Copyright (C) 2002, 2004, 2005, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
    Contributed by Neil Booth, May 2002
 
@@ -378,7 +378,8 @@ _cpp_scan_out_logical_line (cpp_reader *
   for (;;)
     {
       if (!context->prev
-	  && cur >= pfile->buffer->notes[pfile->buffer->cur_note].pos)
+	  && cur >= pfile->buffer->notes[pfile->buffer->cur_note].pos
+	  && !pfile->overlaid_buffer)
 	{
 	  pfile->buffer->cur = cur;
 	  _cpp_process_line_notes (pfile, false);

	Jakub



More information about the Gcc-patches mailing list