[PATCH] cpp fix for -include #line breakage

Jakub Jelinek jakub@redhat.com
Tue Jul 18 06:11:00 GMT 2000


On Mon, Jul 17, 2000 at 01:23:52PM -0700, Zack Weinberg wrote:
> On Mon, Jul 17, 2000 at 10:22:07PM +0200, Jakub Jelinek wrote:
> > Hi!
> > 
> > Would a solution for the cpptest.tar.bz2 problem I posted recently be
> > acceptable? With this the # commands are output properly in the cpp test
> > (even if I put two -include options with 2 different headers).
> > I'll bootstrap now with this and then will try to see if it cures the glibc
> > .stabs problem.
> 
> I never got a chance to reproduce the problem, but this looks at least
> plausible as a fix.  Please let me know how it goes.

Bootstrapped fine on i386-redhat-linux, build a working glibc which can be
debugged (without this patch, gdb is always segfaulting when it sees glibc).
No regressions.
Ok to commit?

> 
> It would make my life much easier if you could come up with a test
> case that could be added to gcc.dg/cpp.

Well, I'm afraid I'm not a tcl/testsuite wizard, at least I cannot find any
testcases which would do similar things. Below the cpplex patch is an
attempt to do so, but I have no idea how to find out the full patch to the
include headers needed for -include command line.
Any ideas? Basically, if I run
cpp -include 20000718-1.h -include 20000718-2.h 20000718.c
in the cpp directory, then without the cpplex patch the output is like:
# 1 "20000718-1.c"
# 1 "20000718-2.h" 1
# 1 "20000718-1.h" 1

# 2 "20000718-2.h" 2
(ie. #line commands are not paired up properly), with my patch:
# 1 "20000718-1.c"
# 1 "20000718-2.h" 1
# 1 "20000718-1.h" 1

# 1 "20000718-2.h" 2

# 1 "20000718-1.c" 2
(so if the path location to the include files is worked out, it should just
grep for 20000718-1.c.*2$

2000-07-17  Jakub Jelinek  <jakub@redhat.com>

	* cpplex.c (cpp_scan_buffer): Output line command even at the stop
	buffer, provided it is not NULL.

--- gcc/cpplex.c.jj	Sat Jul 15 12:50:29 2000
+++ gcc/cpplex.c	Mon Jul 17 22:10:51 2000
@@ -452,10 +452,13 @@ cpp_scan_buffer (pfile, print)
       if (token->type == CPP_EOF)
 	{
 	  cpp_pop_buffer (pfile);
+
+	  if (CPP_BUFFER (pfile))
+	    cpp_output_tokens (pfile, print, CPP_BUF_LINE (CPP_BUFFER (pfile)));
+
 	  if (CPP_BUFFER (pfile) == stop)
 	    return;
 
-	  cpp_output_tokens (pfile, print, CPP_BUF_LINE (CPP_BUFFER (pfile)));
 	  prev = 0;
 	  continue;
 	}


--- gcc/testsuite/gcc.dg/cpp/20000718-1.c.jj	Tue Jul 18 14:56:54 2000
+++ gcc/testsuite/gcc.dg/cpp/20000718-1.c	Tue Jul 18 14:56:50 2000
@@ -0,0 +1,10 @@
+/* This test checks whether some #line notes are not thrown away accidentally
+   in the presence of -include command line options.
+
+  { dg-options "-include @@@/20000718-1.h -include @@@/20000718-2.h" }
+  { dg-final { if \{ [grep 20000718-1.i 20000718-1.c.*2$ ] != "" \} \{ } }
+  { dg-final {   pass "20000718-1.i: #line directive optimization" } }
+  { dg-final { \} else \{ } }
+  { dg-final {   fail "20000718-1.i: #line directive optimization" } }
+  { dg-final { \} } }
+*/
--- gcc/testsuite/gcc.dg/cpp/20000718-1.h.jj	Tue Jul 18 14:57:05 2000
+++ gcc/testsuite/gcc.dg/cpp/20000718-1.h	Tue Jul 18 14:12:34 2000
@@ -0,0 +1 @@
+#include "20000718-3.h"
--- gcc/testsuite/gcc.dg/cpp/20000718-2.h.jj	Tue Jul 18 14:57:05 2000
+++ gcc/testsuite/gcc.dg/cpp/20000718-2.h	Tue Jul 18 14:12:34 2000
@@ -0,0 +1 @@
+#include "20000718-3.h"
--- gcc/testsuite/gcc.dg/cpp/20000718-3.h.jj	Tue Jul 18 14:57:05 2000
+++ gcc/testsuite/gcc.dg/cpp/20000718-3.h	Tue Jul 18 14:13:09 2000
@@ -0,0 +1 @@
+/* This is an empty header.  */

	Jakub


More information about the Gcc-patches mailing list