Patchwork -E/-save-temps locus fix (PR preprocessor/48248)

login
register
mail settings
Submitter Jakub Jelinek
Date March 29, 2011, 3:59 p.m.
Message ID <20110329155958.GM18914@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/88805/
State New
Headers show

Comments

Jakub Jelinek - March 29, 2011, 3:59 p.m.
Hi!

My PR41445 fix apparently sometimes results in wrong locus.
The problem is if we switch temporarily to a locus of some token
from a header file (PR41445 was fixing a problem where -save-temps
behaved differently then normal compilation as locuses were different)
and the line in the header file is within 8 lines of the line in the
current source file, maybe_print_line optimizes and will emit
newlines instead of emitting # X "file"... line.
The optimization should be done only if it is the same file though.

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

2011-03-29  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/48248
	* c-ppoutput.c (print): Add src_file field.
	(init_pp_output): Initialize it.
	(maybe_print_line): Don't optimize by adding up to 8 newlines
	if map->to_file and print.src_file are different file.
	(print_line): Update print.src_file.


	Jakub
Joseph S. Myers - March 29, 2011, 4:55 p.m.
On Tue, 29 Mar 2011, Jakub Jelinek wrote:

> Hi!
> 
> My PR41445 fix apparently sometimes results in wrong locus.
> The problem is if we switch temporarily to a locus of some token
> from a header file (PR41445 was fixing a problem where -save-temps
> behaved differently then normal compilation as locuses were different)
> and the line in the header file is within 8 lines of the line in the
> current source file, maybe_print_line optimizes and will emit
> newlines instead of emitting # X "file"... line.
> The optimization should be done only if it is the same file though.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
> ok for trunk/4.6?

OK.

Patch

--- gcc/c-family/c-ppoutput.c.jj	2011-01-06 10:21:28.000000000 +0100
+++ gcc/c-family/c-ppoutput.c	2011-03-28 20:36:29.000000000 +0200
@@ -36,6 +36,7 @@  static struct
   int src_line;			/* Line number currently being written.  */
   unsigned char printed;	/* Nonzero if something output at line.  */
   bool first_time;		/* pp_file_change hasn't been called yet.  */
+  const char *src_file;		/* Current source file.  */
 } print;
 
 /* Defined and undefined macros being queued for output with -dU at
@@ -153,6 +154,7 @@  init_pp_output (FILE *out_stream)
   print.prev = 0;
   print.outf = out_stream;
   print.first_time = 1;
+  print.src_file = "";
 }
 
 /* Writes out the preprocessed file, handling spacing and paste
@@ -312,7 +314,9 @@  maybe_print_line (source_location src_lo
       print.printed = 0;
     }
 
-  if (src_line >= print.src_line && src_line < print.src_line + 8)
+  if (src_line >= print.src_line
+      && src_line < print.src_line + 8
+      && strcmp (map->to_file, print.src_file) == 0)
     {
       while (src_line > print.src_line)
 	{
@@ -344,6 +348,7 @@  print_line (source_location src_loc, con
       unsigned char *p;
 
       print.src_line = SOURCE_LINE (map, src_loc);
+      print.src_file = map->to_file;
 
       /* cpp_quote_string does not nul-terminate, so we have to do it
 	 ourselves.  */