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]

[3.4 patch?] -save-temps still produces different .s and .o


Here is a slightly revised patch.  I've tested it on the 3.4
branch on Fedora (bootstrap and testsuite); no regressions.
It "fixes" the cpp output to be more-or-less the historical,
adding support for Alex's -fworking-directory mechanism.
I did some simplification of the latter; specifically no
line_map entry is created for the working directory.
That now seems to work.

This is mostly a reversion of my October 1 patch, but with
various improvements and simplifications.  I first worked
on the patch in the compile server branch to convince
myself I could create a variant of the patch for both the
compile-server branch and 3.4/mainline.

I think this should go into the 3.4 branch as well as mainline.
However, I'd appreciate it if people did some more testing on it.
For example I haven't checked if it breaks --enable-intermodule,
though that seems unlikely.  (I'll be incommunicado and unable
to do more testing Tuesday morning until Wednesday evening.)
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/

2004-01-19  Per Bothner  <per@bothner.com>

	Partially revert/redo 2003-10-01 change; fix -fworking-directory.
	* c-ppoutput.c (pp_dir_change):  New function.
	* c-common.h (pp_dir_change):  New declaration.
	* c-opts.c (c_common_post_options):  Maybe set dir_change callback.
	(finish_options):  Set main_input_filename.
	Do LC_RENAME for <built-in>.
	(push_command_line_include):  Don't cpp_push_main_file.
	Do LC_RENAME rathe than LC_LEASE to get back to main file.
	Compared to pre-10-01 version, inline cpp_rename_to_main_file .
	* cppinit.c (cpp_find_main_file, cpp_push_main_file):  Merge back to
	(cpp_read_main_file):  as before 10-01.  Call _cpp_stack_file.
	To handle -fworking_directory, just call dir_change callback,
	which calls pp_dir_change if flag_preprocess_only.
	* cpplib.h.h:  Update declarations to match.
	* fix-header.c (read_scan_file):  Call cpp_read_main_file instead of
	cpp_find_main_file + cpp_push_main_file.

Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.216
diff -u -p -r1.216 c-common.h
--- c-common.h	16 Jan 2004 01:44:05 -0000	1.216
+++ c-common.h	20 Jan 2004 04:25:35 -0000
@@ -1340,5 +1340,6 @@ extern void objc_mark_locals_volatile (v
 extern void init_pp_output (FILE *);
 extern void preprocess_file (cpp_reader *);
 extern void pp_file_change (const struct line_map *);
+extern void pp_dir_change (cpp_reader *, const char *);
 
 #endif /* ! GCC_C_COMMON_H */
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.96
diff -u -p -r1.96 c-opts.c
--- c-opts.c	22 Dec 2003 23:57:03 -0000	1.96
+++ c-opts.c	20 Jan 2004 04:25:36 -0000
@@ -1129,6 +1129,8 @@ c_common_post_options (const char **pfil
 	       progname);
 
       init_pp_output (out_stream);
+
+      cpp_get_callbacks (parse_in)->dir_change = pp_dir_change;
     }
   else
     {
@@ -1382,14 +1384,17 @@ static bool
 finish_options (const char *tif)
 {
   this_input_filename = tif;
-  if (! cpp_find_main_file (parse_in, this_input_filename))
+
+  if (! (tif = cpp_read_main_file (parse_in, this_input_filename)))
     return false;
 
+  main_input_filename = tif;
+
   if (!cpp_opts->preprocessed)
     {
       size_t i;
 
-      cpp_change_file (parse_in, LC_ENTER, _("<built-in>"));
+      cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
       cpp_init_builtins (parse_in, flag_hosted);
       c_cpp_builtins (parse_in);
 
@@ -1458,12 +1463,16 @@ push_command_line_include (void)
   if (include_cursor == deferred_count)
     {
       include_cursor++;
-      /* Restore the line map from <command line>.  */
-      if (! cpp_opts->preprocessed)
-	cpp_change_file (parse_in, LC_LEAVE, NULL);
       /* -Wunused-macros should only warn about macros defined hereafter.  */
       cpp_opts->warn_unused_macros = warn_unused_macros;
-      cpp_push_main_file (parse_in);
+      /* Restore the line map from <command line>.  */
+      if (! cpp_opts->preprocessed)
+	cpp_change_file (parse_in, LC_RENAME, main_input_filename);
+
+      /* Set this here so the client can change the option if it wishes,
+	 and after stacking the main file so we don't trace the main file.  */
+      cpp_get_line_maps (parse_in)->trace_includes
+	= cpp_opts->print_include_names;
     }
 }
 
Index: c-ppoutput.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-ppoutput.c,v
retrieving revision 1.11
diff -u -p -r1.11 c-ppoutput.c
--- c-ppoutput.c	2 Oct 2003 07:03:41 -0000	1.11
+++ c-ppoutput.c	20 Jan 2004 04:25:36 -0000
@@ -334,6 +334,22 @@ cb_include (cpp_reader *pfile ATTRIBUTE_
   print.line++;
 }
 
+/* Callback called when -fworking-director and -E to emot working
+   diretory in cpp output file. */
+
+void
+pp_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
+{
+  size_t to_file_len = strlen (dir);
+  unsigned char *to_file_quoted = alloca (to_file_len * 4 + 1);
+  unsigned char *p;
+
+  /* cpp_quote_string does not nul-terminate, so we have to do it ourselves. */
+  p = cpp_quote_string (to_file_quoted, (unsigned char *) dir, to_file_len);
+  *p = '\0';
+  fprintf (print.outf, "# 1 \"%s//\"\n", to_file_quoted);
+}
+
 /* The file name, line number or system header flags have changed, as
    described in MAP.  From this point on, the old print.map might be
    pointing to freed memory, and so must not be dereferenced.  */
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.297
diff -u -p -r1.297 cppinit.c
--- cppinit.c	1 Nov 2003 22:56:51 -0000	1.297
+++ cppinit.c	20 Jan 2004 04:25:36 -0000
@@ -450,9 +450,10 @@ cpp_post_options (cpp_reader *pfile)
 }
 
 /* Setup for processing input from the file named FNAME, or stdin if
-   it is the empty string.  Returns true if the file was found.  */
-bool
-cpp_find_main_file (cpp_reader *pfile, const char *fname)
+   it is the empty string.  Return the original filename
+   on success (e.g. foo.i->foo.c), or NULL on failure.  */
+const char *
+cpp_read_main_file (cpp_reader *pfile, const char *fname)
 {
   if (CPP_OPTION (pfile, deps.style) != DEPS_NONE)
     {
@@ -468,37 +469,23 @@ cpp_find_main_file (cpp_reader *pfile, c
   if (_cpp_find_failed (pfile->main_file))
     return false;
 
-  if (CPP_OPTION (pfile, working_directory))
-    {
-      const char *dir = getpwd ();
-      char *dir_with_slashes = alloca (strlen (dir) + 3);
-
-      memcpy (dir_with_slashes, dir, strlen (dir));
-      memcpy (dir_with_slashes + strlen (dir), "//", 3);
-
-      if (pfile->cb.dir_change)
-	pfile->cb.dir_change (pfile, dir);
-    }
-  return true;
-}
-
-/* This function reads the file, but does not start preprocessing.
-   This will generate at least one file change callback, and possibly
-   a line change callback.  */
-void
-cpp_push_main_file (cpp_reader *pfile)
-{
   _cpp_stack_file (pfile, pfile->main_file, false);
+  pfile->line++;
 
   /* For foo.i, read the original filename foo.c now, for the benefit
      of the front ends.  */
   if (CPP_OPTION (pfile, preprocessed))
-    read_original_filename (pfile);
+    {
+      read_original_filename (pfile);
+      fname = pfile->map->to_file;
+    }
 
-  /* Set this here so the client can change the option if it wishes,
-     and after stacking the main file so we don't trace the main
-     file.  */
-  pfile->line_maps.trace_includes = CPP_OPTION (pfile, print_include_names);
+  if (CPP_OPTION (pfile, working_directory))
+    {
+      if (pfile->cb.dir_change)
+	pfile->cb.dir_change (pfile, getpwd ());
+    }
+  return fname;
 }
 
 /* For preprocessed files, if the first tokens are of the form # NUM.
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.270
diff -u -p -r1.270 cpplib.h
--- cpplib.h	21 Dec 2003 14:08:32 -0000	1.270
+++ cpplib.h	20 Jan 2004 04:25:37 -0000
@@ -532,14 +532,12 @@ extern const struct line_maps *cpp_get_l
 extern cpp_callbacks *cpp_get_callbacks (cpp_reader *);
 extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *);
 
-/* This function finds the main file, but does not start reading it.
-   Returns true iff the file was found.  */
-extern bool cpp_find_main_file (cpp_reader *, const char *);
-
-/* This function reads the file, but does not start preprocessing.
-   This will generate at least one file change callback, and possibly
-   a line change callback.  */
-extern void cpp_push_main_file (cpp_reader *);
+/* This function reads the file, but does not start preprocessing.  It
+   returns the name of the original file; this is the same as the
+   input file, except for preprocessed input.  This will generate at
+   least one file change callback, and possibly a line change callback
+   too.  If there was an error opening the file, it returns NULL. */
+extern const char *cpp_read_main_file (cpp_reader *, const char *);
 
 /* Set up built-ins like __FILE__.  */
 extern void cpp_init_builtins (cpp_reader *, int);
Index: fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.104
diff -u -p -r1.104 fix-header.c
--- fix-header.c	1 Nov 2003 22:56:54 -0000	1.104
+++ fix-header.c	20 Jan 2004 04:25:37 -0000
@@ -604,9 +604,8 @@ read_scan_file (char *in_fname, int argc
   options->inhibit_errors = 1;
   cpp_post_options (scan_in);
 
-  if (!cpp_find_main_file (scan_in, in_fname))
+  if (!cpp_read_main_file (scan_in, in_fname))
     exit (FATAL_EXIT_CODE);
-  cpp_push_main_file (scan_in);
 
   cpp_change_file (scan_in, LC_RENAME, "<built-in>");
   cpp_init_builtins (scan_in, true);

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