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 committed mainline, proposed for 3.3] Fix cpp -traditional bug


Fixes a bug which was bugging XWindows.  Patch approved by Neil Booth
in private mail, test case considered obvious.

Built & regtested on i686-pc-linux-gnu.

Committed on mainline.

Approval requested to backport this to gcc 3.3.  It's currently one of two
bugs causing Debian's XWindows to depend on cpp 3.2.

	* cpptrad.c (_cpp_scan_out_logical_line): Improve test for
	whether directive begins at the beginning of a line.

	(testsuite)
	* gcc.dg/cpp/trad/xwin1.c: New test case.

Index: gcc.dg/cpp/trad/xwin1.c
===================================================================
RCS file: gcc.dg/cpp/trad/xwin1.c
diff -N gcc.dg/cpp/trad/xwin1.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc.dg/cpp/trad/xwin1.c	19 Nov 2003 00:38:01 -0000
@@ -0,0 +1,13 @@
+/* XWindows (as of 4.3) does some pretty strange things with cpp.
+   This tests one of them; the leading comments are supposed to be
+   eaten by the preprocessor; but the 'directives' after them are
+   supposed to be retained as text, not processed, so that imake's cpp
+   can be run on the output!
+   { dg-do preprocess }
+*/
+
+/**/#if 0
+passed
+/**/#endif
+
+/* { dg-final { scan-file xwin1.i "(^|\n)#if 0" } } */
Index: cpptrad.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpptrad.c,v
retrieving revision 1.38
diff -u -r1.38 cpptrad.c
--- cpptrad.c	1 Nov 2003 22:56:54 -0000	1.38
+++ cpptrad.c	19 Nov 2003 18:45:18 -0000
@@ -350,6 +350,7 @@
   unsigned int c, paren_depth = 0, quote;
   enum ls lex_state = ls_none;
   bool header_ok;
+  const uchar *start_of_input_line;
 
   fmacro.buff = NULL;
 
@@ -359,6 +360,9 @@
   RLIMIT (pfile->context) = pfile->buffer->rlimit;
   pfile->out.cur = pfile->out.base;
   pfile->out.first_line = pfile->line;
+  /* start_of_input_line is needed to make sure that directives really,
+     really start at the first character of the line. */
+  start_of_input_line = pfile->buffer->cur;
  new_context:
   context = pfile->context;
   cur = CUR (context);
@@ -581,7 +585,7 @@
 	  break;
 
 	case '#':
-	  if (out - 1 == pfile->out.base
+	  if (cur - 1 == start_of_input_line
 	      /* A '#' from a macro doesn't start a directive.  */
 	      && !pfile->context->prev
 	      && !pfile->state.in_directive)

-- 
Nathanael Nerode  <neroden at gcc.gnu.org>
http://home.twcny.rr.com/nerode/neroden/fdl.html


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