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: -save-temps still produces different .s and .o


Alex, can you try this patch (against mainline)?
I'd like to check this into mainline asap, and then
shortly a variant of this patch into mainline.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/

2004-01-24  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.
	* 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.
	* c-opts.c (c_common_post_options):  Maybe set dir_change callback.
	(finish_options):  Don't call cpp_find_main_file here.	Hence remove
	unneeded parameter and result. Do LC_RENAME for <built-in>.
	(c_common_post_options):  Call cpp_read_main_file here instead.
	(c_common_init):  Update accordingly.
	(push_command_line_include):  Don't cpp_push_main_file.
	Do LC_RENAME rather than LC_LEASE to get back to main file.
	Compared to pre-10-01 version, inline cpp_rename_to_main_file .
	(c_common_parse_file):  Call cpp_read_main_file for subsequent main
	files, but call finish_options for all files.
	* fix-header.c (read_scan_file):  Call cpp_read_main_file instead of
	cpp_find_main_file + cpp_push_main_file.
	* c-lex.c (fe_file_change):  Don't set main_input_filename here.
	* opts.c (handle_options):  Only set main_input_filename first time.

Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.217
diff -u -p -r1.217 c-common.h
--- c-common.h	21 Jan 2004 20:39:51 -0000	1.217
+++ c-common.h	24 Jan 2004 16:59:11 -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-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.215
diff -u -p -r1.215 c-lex.c
--- c-lex.c	2 Oct 2003 07:03:41 -0000	1.215
+++ c-lex.c	24 Jan 2004 16:59:11 -0000
@@ -222,9 +222,7 @@ fe_file_change (const struct line_map *n
     {
       /* Don't stack the main buffer on the input stack;
 	 we already did in compile_file.  */
-      if (map == NULL)
-	main_input_filename = new_map->to_file;
-      else
+      if (map != NULL)
 	{
           int included_at = SOURCE_LINE (new_map - 1, new_map->from_line - 1);
 
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.98
diff -u -p -r1.98 c-opts.c
--- c-opts.c	21 Jan 2004 20:39:51 -0000	1.98
+++ c-opts.c	24 Jan 2004 16:59:12 -0000
@@ -108,7 +108,7 @@ static void sanitize_cpp_opts (void);
 static void add_prefixed_path (const char *, size_t);
 static void push_command_line_include (void);
 static void cb_file_change (cpp_reader *, const struct line_map *);
-static bool finish_options (const char *);
+static void finish_options (void);
 
 #ifndef STDC_0_IN_SYSTEM_HEADERS
 #define STDC_0_IN_SYSTEM_HEADERS 0
@@ -1049,7 +1049,7 @@ c_common_handle_option (size_t scode, co
 
 /* Post-switch processing.  */
 bool
-c_common_post_options (const char **pfilename ATTRIBUTE_UNUSED)
+c_common_post_options (const char **pfilename)
 {
   /* Canonicalize the input and output filenames.  */
   if (in_fnames == NULL)
@@ -1129,6 +1129,9 @@ c_common_post_options (const char **pfil
 	       progname);
 
       init_pp_output (out_stream);
+
+      if (! cpp_opts->preprocessed)
+	cpp_get_callbacks (parse_in)->dir_change = pp_dir_change;
     }
   else
     {
@@ -1148,6 +1151,11 @@ c_common_post_options (const char **pfil
      immediately.  */
   errorcount += cpp_errors (parse_in);
 
+  *pfilename = this_input_filename
+    = cpp_read_main_file (parse_in, in_fnames[0]);
+  if (this_input_filename == NULL)
+    return true;
+
   return flag_preprocess_only;
 }
 
@@ -1172,8 +1180,8 @@ c_common_init (void)
 
   if (flag_preprocess_only)
     {
-      if (finish_options (in_fnames[0]))
-	preprocess_file (parse_in);
+      finish_options ();
+      preprocess_file (parse_in);
       return false;
     }
 
@@ -1207,10 +1215,12 @@ c_common_parse_file (int set_yydebug ATT
 
 	  /* Reset cpplib's macros and start a new file.  */
 	  cpp_undef_all (parse_in);
+	  main_input_filename = this_input_filename
+	    = cpp_read_main_file (parse_in, in_fnames[file_index]);
+	  if (this_input_filename == NULL)
+	    break;
 	}
-
-      if (! finish_options(in_fnames[file_index]))
-	break;
+      finish_options ();
       if (file_index == 0)
 	pch_init();
       c_parse_file ();
@@ -1375,21 +1385,15 @@ add_prefixed_path (const char *suffix, s
   add_path (path, chain, 0);
 }
 
-/* Handle -D, -U, -A, -imacros, and the first -include.  
-   TIF is the input file to which we will return after processing all
-   the includes.  Returns true on success.  */
-static bool
-finish_options (const char *tif)
+/* Handle -D, -U, -A, -imacros, and the first -include.  */
+static void
+finish_options (void)
 {
-  this_input_filename = tif;
-  if (! cpp_find_main_file (parse_in, this_input_filename))
-    return false;
-
   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);
 
@@ -1439,7 +1443,6 @@ finish_options (const char *tif)
 
   include_cursor = 0;
   push_command_line_include ();
-  return true;
 }
 
 /* Give CPP the next file given by -include, if any.  */
@@ -1458,12 +1461,15 @@ 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.  */
+      line_table.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	24 Jan 2004 16:59:12 -0000
@@ -334,6 +334,22 @@ cb_include (cpp_reader *pfile ATTRIBUTE_
   print.line++;
 }
 
+/* Callback called when -fworking-director and -E to emit 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.300
diff -u -p -r1.300 cppinit.c
--- cppinit.c	21 Jan 2004 20:39:52 -0000	1.300
+++ cppinit.c	24 Jan 2004 16:59:12 -0000
@@ -453,9 +453,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)
     {
@@ -471,37 +472,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_table->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.273
diff -u -p -r1.273 cpplib.h
--- cpplib.h	21 Jan 2004 20:39:53 -0000	1.273
+++ cpplib.h	24 Jan 2004 16:59:12 -0000
@@ -536,14 +536,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.106
diff -u -p -r1.106 fix-header.c
--- fix-header.c	21 Jan 2004 20:39:54 -0000	1.106
+++ fix-header.c	24 Jan 2004 16:59:13 -0000
@@ -606,9 +606,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: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.51
diff -u -p -r1.51 opts.c
--- opts.c	1 Jan 2004 13:58:57 -0000	1.51
+++ opts.c	24 Jan 2004 16:59:13 -0000
@@ -448,7 +448,8 @@ handle_options (unsigned int argc, const
       /* Interpret "-" or a non-switch as a file name.  */
       if (opt[0] != '-' || opt[1] == '\0')
 	{
-	  main_input_filename = opt;
+	  if (main_input_filename == NULL)
+	    main_input_filename = opt;
 	  add_input_filename (opt);
 	  n = 1;
 	  continue;

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