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]

Re: this_input_filename patch introduced bug



On Sunday, July 27, 2003, at 01:46 PM, Neil Booth wrote:


Geoff,

Your this_input_filename patch introduced a bug when
preprocessing from stdin:

bash-2.05b$ ./cc1 -E -quiet
foo bar
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 ""				<--- file name lost here
foo bar

Can you fix this please? c-opts.c updates main_input_filename, and
you haven't caught that fact. You need to fix something around this line:


  /* NOTE: we use in_fname here, not the one supplied.  */
    *pfilename = cpp_read_main_file (parse_in, in_fnames[0]);

Hmmm. I don't see the relevance of that bit of code at all. The problem is that some parts of GCC represent stdin as an empty string, and other parts represent it as "<stdin>". I think we should standardise on the empty string except in line maps, like this:


Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.177
diff -u -p -u -p -r1.177 cppfiles.c
--- cppfiles.c  21 Jul 2003 20:57:00 -0000      1.177
+++ cppfiles.c  28 Jul 2003 21:18:59 -0000
@@ -411,8 +411,6 @@ stack_include_file (cpp_reader *pfile, s

   /* Generate the call back.  */
   filename = inc->name;
-  if (*filename == '\0')
-    filename = "<stdin>";
   _cpp_do_file_change (pfile, LC_ENTER, filename, 1, sysp);

   return true;
Index: line-map.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/line-map.c,v
retrieving revision 1.14
diff -u -p -u -p -r1.14 line-map.c
--- line-map.c  22 Jul 2003 23:11:34 -0000      1.14
+++ line-map.c  28 Jul 2003 21:18:59 -0000
@@ -61,11 +61,17 @@ linemap_free (struct line_maps *set)
 }

 /* Add a mapping of logical source line to physical source file and
-   line number.  The text pointed to by TO_FILE must have a lifetime
-   at least as long as the final call to lookup_line ().
+   line number.
+
+   The text pointed to by TO_FILE must have a lifetime
+   at least as long as the final call to lookup_line ().  An empty
+   TO_FILE means standard input.  If reason is LC_LEAVE, and
+   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
+   natural values considering the file we are returning to.

    FROM_LINE should be monotonic increasing across calls to this
-   function.  */
+   function.  A call to this function can relocate the previous set of
+   maps, so any stored line_map pointers should not be used.  */

 const struct line_map *
 linemap_add (struct line_maps *set, enum lc_reason reason,
@@ -84,6 +90,9 @@ linemap_add (struct line_maps *set, enum
     }

   map = &set->maps[set->used++];
+
+  if (*to_file == '\0')
+    to_file = "<stdin>";

   /* If we don't keep our line maps consistent, we can easily
      segfault.  Don't rely on the client to do it for us.  */
Index: line-map.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/line-map.h,v
retrieving revision 1.12
diff -u -p -u -p -r1.12 line-map.h
--- line-map.h  22 Jul 2003 16:24:53 -0000      1.12
+++ line-map.h  28 Jul 2003 21:18:59 -0000
@@ -74,8 +74,11 @@ extern void linemap_init (struct line_ma
 extern void linemap_free (struct line_maps *);

 /* Add a mapping of logical source line to physical source file and
-   line number.  The text pointed to by TO_FILE must have a lifetime
-   at least as long as the line maps.  If reason is LC_LEAVE, and
+   line number.
+
+   The text pointed to by TO_FILE must have a lifetime
+   at least as long as the final call to lookup_line ().  An empty
+   TO_FILE means standard input.  If reason is LC_LEAVE, and
    TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
    natural values considering the file we are returning to.


-- Geoff Keating <geoffk@apple.com>


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