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]

Finish fixing --help and --target-help regression


Playing further, I discovered that my patch yesterday only fixes 75%
of the problem - it cures the gcc / g++ / f77 etc. drivers.  [The
original breakage is a result of moving to an integrated cpp without
updating the driver fully].

But is does not fix the cpp driver.  This is because the above drivers
pick up and emit the --help and --target-help options from the
cc1_option spec; this is why adding a separate preprocessor switch is
unnecessary.  But the cpp driver does not process the cc1_options
spec, so it requires a preprocessor switch to be added.

The patch below fixes this.  At the same time, it also fixes the fact
that currently

   gcc --help a.c b.c c.c

will output the help no less that 4 times - it is done additionally
for each input file.

I have tested this by checking that cpp, gcc, and f77 do the right
thing for a variety of input combinations.  There is still one
breakage that is not a regression: --help and --target-help together
output the target help twice in toplev.c; I'll post a separate patch
for that.  It isn't a regression since --target-help was not in
2.95.x.

OK for mainline and branch?

Neil.

	* cppspec.c (lang_specific_driver): Set is_cpp_driver.
	* gcc.c (process_command): Ensure the cpp driver sees
	--help and --target-help, and that the help is printed
	exactly once.

Index: cppspec.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppspec.c,v
retrieving revision 1.15
diff -u -p -r1.15 cppspec.c
--- cppspec.c	2001/08/22 14:34:49	1.15
+++ cppspec.c	2001/12/04 20:40:14
@@ -103,6 +103,9 @@ lang_specific_driver (in_argc, in_argv, 
   int i, j, quote = 0;
   const char **new_argv;
   int new_argc;
+  extern int is_cpp_driver;
+
+  is_cpp_driver = 1;
 
   /* First pass.  If we see an -S or -c, barf.  If we see an input file,
      turn off read_stdin.  If we see a second input file, it is actually
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.273
diff -u -p -r1.273 gcc.c
--- gcc.c	2001/12/03 22:36:51	1.273
+++ gcc.c	2001/12/04 20:41:03
@@ -143,6 +143,9 @@ static const char dir_separator_str[] = 
 
 #define MIN_FATAL_STATUS 1
 
+/* Flag set by cppspec.c to 1.  */
+int is_cpp_driver;
+
 /* Flag saying to pass the greatest exit code returned by a sub-process
    to the calling program.  */
 static int pass_exit_codes;
@@ -3310,6 +3313,9 @@ process_command (argc, argv)
 	  n_infiles++;
 	  n_switches++;
 
+	  /* CPP driver cannot obtain switch from cc1_options.  */
+	  if (is_cpp_driver)
+	    add_preprocessor_option ("--help", 6);
 	  add_assembler_option ("--help", 6);
 	  add_linker_option ("--help", 6);
 	}
@@ -3322,6 +3328,9 @@ process_command (argc, argv)
           n_infiles++;
           n_switches++;
 
+	  /* CPP driver cannot obtain switch from cc1_options.  */
+	  if (is_cpp_driver)
+	    add_preprocessor_option ("--target-help", 13);
           add_assembler_option ("--target-help", 13);
           add_linker_option ("--target-help", 13);
         }
@@ -3792,41 +3801,10 @@ process_command (argc, argv)
 	;
       else if (! strcmp (argv[i], "-print-multi-directory"))
 	;
-      else if (strcmp (argv[i], "-ftarget-help") == 0)
-        {
-           /* Create a dummy input file, so that we can pass --target-help on to
-              the various sub-processes.  */
-           infiles[n_infiles].language = "c";
-           infiles[n_infiles++].name   = "target-dummy";
-
-           /* Preserve the --target-help switch so that it can be caught by
-              the cc1 spec string.  */
-           switches[n_switches].part1     = "--target-help";
-           switches[n_switches].args      = 0;
-           switches[n_switches].live_cond = SWITCH_OK;
-           switches[n_switches].validated = 0;
-
-           n_switches++;
-        }
-      else if (strcmp (argv[i], "-fhelp") == 0)
-	{
-	  if (verbose_flag)
-	    {
-	      /* Create a dummy input file, so that we can pass --help on to
-		 the various sub-processes.  */
-	      infiles[n_infiles].language = "c";
-	      infiles[n_infiles++].name   = "help-dummy";
-
-	      /* Preserve the --help switch so that it can be caught by the
-		 cc1 spec string.  */
-	      switches[n_switches].part1     = "--help";
-	      switches[n_switches].args      = 0;
-	      switches[n_switches].live_cond = SWITCH_OK;
-	      switches[n_switches].validated = 0;
-
-	      n_switches++;
-	    }
-	}
+      else if (! strcmp (argv[i], "-ftarget-help"))
+	;
+      else if (! strcmp (argv[i], "-fhelp"))
+	;
       else if (argv[i][0] == '+' && argv[i][1] == 'e')
 	{
 	  /* Compensate for the +e options to the C++ front-end;
@@ -3988,6 +3966,37 @@ process_command (argc, argv)
 
   if (n_infiles == last_language_n_infiles && spec_lang != 0)
     error ("warning: `-x %s' after last input file has no effect", spec_lang);
+
+  /* Ensure we only invoke each subprocess once.  */
+  if (target_help_flag || print_help_list)
+    {
+      n_infiles = 1;
+
+      /* Create a dummy input file, so that we can pass --target-help on to
+	 the various sub-processes.  */
+      infiles[0].language = "c";
+      infiles[0].name   = "help-dummy";
+
+      if (target_help_flag)
+	{
+	  switches[n_switches].part1     = "--target-help";
+	  switches[n_switches].args      = 0;
+	  switches[n_switches].live_cond = SWITCH_OK;
+	  switches[n_switches].validated = 0;
+
+	  n_switches++;
+	}
+
+      if (print_help_list)
+	{
+	  switches[n_switches].part1     = "--help";
+	  switches[n_switches].args      = 0;
+	  switches[n_switches].live_cond = SWITCH_OK;
+	  switches[n_switches].validated = 0;
+
+	  n_switches++;
+	}
+    }
 
   switches[n_switches].part1 = 0;
   infiles[n_infiles].name = 0;


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