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]

[PATCH] Fix #line generation in cpp


Hi!

If a header includes itself and is not fully protected against multiple
inclusion, cpp ommits one of the needed #line commands, which has the result
that gcc ends with error:
[jakub@tucnak /tmp]$ gcc -c k.c
k.c:0: #-lines for entering and leaving files don't match

Example (should I make a testcase from it):
[jakub@tucnak /tmp]$ cat k.c
#include "k.h"
[jakub@tucnak /tmp]$ cat k.h
/* Self including unprotected header */
#include "l.h"
#ifndef K_H
#define K_H 1
#include "k.h"
#include "l.h"
#endif
[jakub@tucnak /tmp]$ cat l.h
asm ("");

Ok to commit?

2000-06-28  Jakub Jelinek  <jakub@redhat.com>

	* cpplex.c (output_line_command): Output correct #line if a header
	is including itself and is not protected against multiple inclusion.

--- gcc/cpplex.c.jj	Thu Jun 22 13:47:17 2000
+++ gcc/cpplex.c	Wed Jun 28 15:51:09 2000
@@ -289,25 +289,26 @@ output_line_command (pfile, print, line)
   if (CPP_OPTION (pfile, no_line_commands))
     return;
 
-  /* Determine whether the current filename has changed, and if so,
-     how.  'nominal_fname' values are unique, so they can be compared
-     by comparing pointers.  */
-  if (ip->nominal_fname == print->last_fname)
-    change = same;
-  else
+  if (pfile->buffer_stack_depth == print->last_bsd)
     {
-      if (pfile->buffer_stack_depth == print->last_bsd)
+      /* Determine whether the current filename has changed, and if so,
+	 how.  'nominal_fname' values are unique, so they can be compared
+	 by comparing pointers.  */
+      if (ip->nominal_fname == print->last_fname)
+	change = same;
+      else
 	change = rname;
+    }
+  else
+    {
+      if (pfile->buffer_stack_depth > print->last_bsd)
+	change = enter;
       else
-	{
-	  if (pfile->buffer_stack_depth > print->last_bsd)
-	    change = enter;
-	  else
-	    change = leave;
-	  print->last_bsd = pfile->buffer_stack_depth;
-	}
-      print->last_fname = ip->nominal_fname;
+	change = leave;
+      print->last_bsd = pfile->buffer_stack_depth;
     }
+  print->last_fname = ip->nominal_fname;
+
   /* If the current file has not changed, we can output a few newlines
      instead if we want to increase the line number by a small amount.
      We cannot do this if print->lineno is zero, because that means we

	Jakub

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