This is the mail archive of the gcc@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]

RFA: gcc.c retry hack


The following hack will retry a failing (ICE) compilation after stripping out
-O arguments (controlled by the ICE_RETRY environment variable).
At the moment it permits snapshots to build on alpha-dec-osf4.0e where
they were running out of swap. Is it worth cleaning up for inclusion, to allow
some testing when compiling with optimization fails for whatever reason?
Say a --retry command line argument, fix the indentation and a warning message.


--- gcc/gcc.c.orig	Tue Mar 27 19:00:47 2001
+++ gcc/gcc.c	Thu Mar 29 15:17:12 2001
@@ -270,6 +270,8 @@ static void set_input			PARAMS ((const c
 static void init_gcc_specs              PARAMS ((struct obstack *,
 						 const char *,
 						 const char *));
+static int retry_candidate		PARAMS ((const char **, int));
+static const char ** new_argv_nooptimize	PARAMS ((const char **));
 
 /* Specs are strings containing lines, each of which (if not blank)
 is made up of a program name, and arguments separated by spaces.
@@ -2551,6 +2553,39 @@ add_prefix (pprefix, prefix, component, 
   (*prev) = pl;
 }
 
+static int
+retry_candidate (argv, n_commands)
+     const char **argv;
+     int n_commands;
+{
+  if (!save_temps_flag && n_commands == 1 && argv != NULL
+    && getenv ("ICE_RETRY") != NULL)
+    {
+      int i;
+
+      for (i = 0; argv[i] != NULL; i++)
+	if (strncmp (argv[i], "-O", 2) == 0)
+	    return 1;
+    }
+  return 0;
+}
+
+static const char **
+new_argv_nooptimize(argv)
+     const char **argv;
+{
+  const char **n_argv;
+  int i, j;
+
+  n_argv = (const char **) xmalloc (argbuf_index * sizeof (char *));
+  for (i = j = 0; argv[i] != NULL; i++)
+    if (strncmp (argv[i], "-O", 2) != 0)
+      n_argv[j++] = argv[i];
+  
+  n_argv[j] = NULL;
+  return n_argv;
+}
+
 /* Execute the command specified by the arguments on the current line of spec.
    When using pipes, this includes several piped-together commands
    with `|' between them.
@@ -2562,6 +2597,7 @@ execute ()
 {
   int i;
   int n_commands;		/* # of command.  */
+  int in_retry = 0;		/* retrying failed command */
   char *string;
   struct command
   {
@@ -2610,7 +2646,8 @@ execute ()
 
   /* If -v, print what we are about to do, and maybe query.  */
 
-  if (verbose_flag)
+  do {
+  if (verbose_flag || in_retry)
     {
       /* For help listings, put a blank line between sub-processes.  */
       if (print_help_list)
@@ -2643,6 +2680,8 @@ execute ()
 #endif /* DEBUG */
     }
 
+    in_retry = 0;
+
   /* Run each piped subprocess.  */
 
   for (i = 0; i < n_commands; i++)
@@ -2664,8 +2703,7 @@ execute ()
       if (commands[i].pid == -1)
 	pfatal_pexecute (errmsg_fmt, errmsg_arg);
 
-      if (string != commands[i].prog)
-	free ((PTR) string);
+      /* Defer free-ing commands[i].argv[0] == string to allow retry. */
     }
 
   execution_count++;
@@ -2736,25 +2774,52 @@ Please submit a full bug report.\n\
 See %s for instructions.",
 			   strsignal (WTERMSIG (status)), commands[j].prog,
 			   GCCBUGURL);
+		    if (retry_candidate (commands[j].argv, n_commands))
+		      {
+			in_retry = 1;
+			commands[j].argv =
+			  new_argv_nooptimize (commands[j].argv);
+		      }
+		    else
+		      {
 		  signal_count++;
 		  ret_code = -1;
 		}
+		}
 	      else if (WIFEXITED (status)
 		       && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
 		{
+		  if (retry_candidate (commands[j].argv, n_commands))
+		    {
+		      in_retry = 1;
+		      commands[j].argv =
+			new_argv_nooptimize (commands[j].argv);
+		    }
+		  else
+		    {
 		  if (WEXITSTATUS (status) > greatest_status)
 		    greatest_status = WEXITSTATUS (status);
 		  ret_code = -1;
 		}
+		}
 #ifdef HAVE_GETRUSAGE
 	      if (report_times && ut + st != 0)
 		notice ("# %s %.2f %.2f\n", commands[j].prog, ut, st);
 #endif
+	      if (!in_retry && commands[j].argv[0] != commands[j].prog)
+		free ((PTR)commands[j].argv[0]);
 	      break;
 	    }
       }
+    if (!in_retry)
+      {
+	if (commands[0].argv != &argbuf[0])
+	  free ((PTR) commands[0].argv);
     return ret_code;
   }
+  }
+  } while (in_retry);
+  return 0;
 }
 
 /* Find all the switches given to us


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