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]

Re: [CPP patch]: -M default name


Zack Weinberg wrote:-

> If we get an -o switch with -MM, then we should use its path.  And -MM
> -o foo.o should not create an empty foo.o (see the bug report).

OK, I think this fixes the empty file problem.  Nathan, are you OK
with the basename stuff?

The semantics of -o as regards to interaction between gcc / cpp and
cpp0 are not entirely clear to me.  At present,

gcc -M foo.c -o foo.o

works (apart from truncation of foo.o).  However,

cpp -M foo.c -o foo.o

complains about multiple output files.  I'm not entirely sure how to
fix this (I've not looked to find what's causing it either).

Anyway, for "gcc" invocations, does this look OK to you, Zack?  Note
the specs change - the specs currently instruct the driver to delete
the output file in case of an error, which is just as bad as
truncating it, so I'm removing that.

Thoughts?

Neil.

	* cppinit.c (cpp_start_read): Don't fix out_fname here, ...
	(cpp_post_options): ... but here.
	(init_dependency_output): Send any output to stdout if
	we're generating dependencies.
	* cpplib.h: Update comment.
	* cppmain.c (printer_init): Remove redundant check.

	* gcc.c (cpp_options): Don't delete output file on error
	with -M and -MM.

Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.204
diff -u -p -r1.204 gcc.c
--- gcc.c	2001/02/07 18:58:05	1.204
+++ gcc.c	2001/02/08 19:26:46
@@ -606,7 +606,7 @@ static const char *cpp_options =
  %{fleading-underscore} %{fno-leading-underscore}\
  %{fno-operator-names} %{ftabstop=*} %{remap}\
  %{g3:-dD} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*&U*&A*} %{i*} %Z %i\
- %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}";
+ %{E:%W{o*}}";
 
 /* NB: This is shared amongst all front-ends.  */
 static const char *cc1_options =
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.147
diff -u -p -r1.147 cppinit.c
--- cppinit.c	2001/02/07 18:32:41	1.147
+++ cppinit.c	2001/02/08 19:27:05
@@ -422,7 +422,6 @@ set_lang (pfile, lang)
 
       /* Objective C.  */
     case CLK_OBJCXX:
-      new_pending_directive (pend, "__cplusplus", cpp_define);
       CPP_OPTION (pfile, cplusplus) = 1;
     case CLK_OBJC:
       CPP_OPTION (pfile, trigraphs) = 0;
@@ -443,7 +442,6 @@ set_lang (pfile, lang)
       CPP_OPTION (pfile, cplusplus_comments) = 1;
       CPP_OPTION (pfile, digraphs) = 1;
       CPP_OPTION (pfile, c99) = 0;
-      new_pending_directive (pend, "__cplusplus", cpp_define);
       break;
 
       /* Assembler.  */
@@ -757,6 +755,10 @@ init_builtins (pfile)
 	  _cpp_define_builtin (pfile, str);
 	}
     }
+
+  /* This is the right place to do the option-dependent builtins, too.  */
+  if (CPP_OPTION (pfile, cplusplus))
+    _cpp_define_builtin (pfile, "__cplusplus 199711L");
 }
 #undef BUILTIN
 #undef OPERATOR
@@ -915,8 +917,6 @@ cpp_start_read (pfile, fname)
       if (CPP_OPTION (pfile, in_fname) == NULL)
 	CPP_OPTION (pfile, in_fname) = "";
     }
-  if (CPP_OPTION (pfile, out_fname) == NULL)
-    CPP_OPTION (pfile, out_fname) = "";
 
   if (CPP_OPTION (pfile, print_deps))
     /* Set the default target (if there is none already).  */
@@ -1697,6 +1697,10 @@ cpp_post_options (pfile)
   if (CPP_OPTION (pfile, user_label_prefix) == NULL)
     CPP_OPTION (pfile, user_label_prefix) = USER_LABEL_PREFIX;
 
+  /* Guarantee out_fname is non-null, before init_dependency_output.  */
+  if (CPP_OPTION (pfile, out_fname) == NULL)
+    CPP_OPTION (pfile, out_fname) = "";
+
   /* We need to do this after option processing and before
      cpp_start_read, as cppmain.c relies on the options->no_output to
      set its callbacks correctly before calling cpp_start_read.  */
@@ -1755,6 +1759,10 @@ init_dependency_output (pfile)
 	CPP_OPTION (pfile, deps_file) = output_file;
       CPP_OPTION (pfile, print_deps_append) = 1;
     }
+
+  /* We might be invoked as "gcc -M foo.c -o foo.o".  With "foo.o" in
+     out_fname, cppmain.c will truncate it unless we catch it here.  */
+  CPP_OPTION (pfile, out_fname) = "";
 
   /* If dependencies go to standard output, or -MG is used, we should
      suppress output.  The user may be requesting other stuff to
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.163
diff -u -p -r1.163 cpplib.h
--- cpplib.h	2001/02/04 08:29:46	1.163
+++ cpplib.h	2001/02/08 19:27:14
@@ -514,7 +514,8 @@ extern void cpp_set_callbacks PARAMS ((c
    understand the next switch.  When there are no switches left, you
    must call cpp_post_options before calling cpp_start_read.  Only
    after cpp_post_options are the contents of the cpp_options
-   structure reliable.  */
+   structure reliable.  cpp_post_options guarantees that out_fname is
+   non-null on returning; an empty string means stdout.  */
 extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
 extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
 extern void cpp_post_options PARAMS ((cpp_reader *));
Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.61
diff -u -p -r1.61 cppmain.c
--- cppmain.c	2001/02/01 19:13:53	1.61
+++ cppmain.c	2001/02/08 19:27:14
@@ -271,9 +271,6 @@ printer_init (pfile)
   print.lineno = 0;
   print.printed = 0;
 
-  if (options->out_fname == NULL)
-    options->out_fname = "";
-  
   if (options->out_fname[0] == '\0')
     print.outf = stdout;
   else

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