Fix preprocessor/7150

Neil Booth neil@daikokuya.co.uk
Sat Jun 29 07:51:00 GMT 2002


This is another bug introduced by the integrated traditional
preprocessor.  cpp_scan_nooutput() had not been updated to
handle the traditional case.

Jason, this should fix the segfault that occurred for you
in cpp_paste_tokens().  It tends to happen if you use
-imacros or -dM or something that scans code without
outputting it.

I'm doing a make check on this; I'll apply it once it suceeds.

Neil.

	PR preprocessor/7150
	* cppmain.c (scan_translation_unit_trad): Simplify.
	* cpplib.c (cpp_scan_nooutput): Handle traditional case.

Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.100
diff -u -p -r1.100 cppmain.c
--- cppmain.c	19 Jun 2002 05:40:08 -0000	1.100
+++ cppmain.c	29 Jun 2002 13:51:47 -0000
@@ -228,13 +228,9 @@ static void
 scan_translation_unit_trad (pfile)
      cpp_reader *pfile;
 {
-  for (;;)
+  while (_cpp_read_logical_line_trad (pfile))
     {
-      size_t len;
-
-      if (!_cpp_read_logical_line_trad (pfile))
-	break;
-      len = pfile->out.cur - pfile->out.base;
+      size_t len = pfile->out.cur - pfile->out.base;
       maybe_print_line (print.map, pfile->out.first_line);
       fwrite (pfile->out.base, 1, len, print.outf);
       print.printed = 1;
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.115
diff -u -p -r1.115 cppmacro.c
--- cppmacro.c	19 Jun 2002 05:40:06 -0000	1.115
+++ cppmacro.c	29 Jun 2002 13:51:48 -0000
@@ -1136,8 +1136,12 @@ cpp_scan_nooutput (pfile)
      transparently continuing with the including file.  */
   pfile->buffer->return_at_eof = true;
 
-  while (cpp_get_token (pfile)->type != CPP_EOF)
-    ;
+  if (CPP_OPTION (pfile, traditional))
+    while (_cpp_read_logical_line_trad (pfile))
+      ;
+  else
+    while (cpp_get_token (pfile)->type != CPP_EOF)
+      ;
 }
 
 /* Step back one (or more) tokens.  Can only step mack more than 1 if



More information about the Gcc-patches mailing list