Blame SOURCES/gcc32-ice-hack.patch

4ac4fd
--- gcc/system.h.jj	2003-04-08 15:55:41.000000000 +0200
4ac4fd
+++ gcc/system.h	2003-10-03 19:01:24.000000000 +0200
4ac4fd
@@ -153,6 +153,10 @@ extern int errno;
4ac4fd
 # endif
4ac4fd
 #endif
4ac4fd
 
4ac4fd
+#ifndef ICE_EXIT_CODE
4ac4fd
+# define ICE_EXIT_CODE 27
4ac4fd
+#endif
4ac4fd
+
4ac4fd
 #ifdef HAVE_UNISTD_H
4ac4fd
 # include <unistd.h>
4ac4fd
 #endif
4ac4fd
--- gcc/gcc.c.jj	2003-06-11 15:08:12.000000000 +0200
4ac4fd
+++ gcc/gcc.c	2003-10-06 10:10:42.000000000 +0200
4ac4fd
@@ -112,6 +112,10 @@ extern int getrusage PARAMS ((int, struc
4ac4fd
 #define TARGET_OBJECT_SUFFIX ".o"
4ac4fd
 #endif
4ac4fd
 
4ac4fd
+#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS))
4ac4fd
+static void retry_ice PARAMS ((const char *, const char **));
4ac4fd
+#endif
4ac4fd
+
4ac4fd
 #ifndef VMS
4ac4fd
 /* FIXME: the location independence code for VMS is hairier than this,
4ac4fd
    and hasn't been written.  */
4ac4fd
@@ -2857,7 +2861,7 @@ execute ()
4ac4fd
       if (commands[i].pid == -1)
4ac4fd
 	pfatal_pexecute (errmsg_fmt, errmsg_arg);
4ac4fd
 
4ac4fd
-      if (string != commands[i].prog)
4ac4fd
+      if (i && string != commands[i].prog)
4ac4fd
 	free ((PTR) string);
4ac4fd
     }
4ac4fd
 
4ac4fd
@@ -2935,6 +2939,17 @@ See %s for instructions.",
4ac4fd
 	      else if (WIFEXITED (status)
4ac4fd
 		       && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
4ac4fd
 		{
4ac4fd
+#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS))
4ac4fd
+		  /* For ICEs in cc1, cc1obj, cc1plus see if it is
4ac4fd
+		     reproducible or not.  */
4ac4fd
+		  char *p;
4ac4fd
+		  if (WEXITSTATUS (status) == ICE_EXIT_CODE
4ac4fd
+		      && j == 0
4ac4fd
+		      && (p = strrchr (commands[j].argv[0], DIR_SEPARATOR))
4ac4fd
+		      && ! strncmp (p + 1, "cc1", 3))
4ac4fd
+		    retry_ice (commands[j].prog, commands[j].argv);
4ac4fd
+#endif
4ac4fd
+
4ac4fd
 		  if (WEXITSTATUS (status) > greatest_status)
4ac4fd
 		    greatest_status = WEXITSTATUS (status);
4ac4fd
 		  ret_code = -1;
4ac4fd
@@ -2946,6 +2961,10 @@ See %s for instructions.",
4ac4fd
 	      break;
4ac4fd
 	    }
4ac4fd
       }
4ac4fd
+
4ac4fd
+    if (commands[0].argv[0] != commands[0].prog)
4ac4fd
+      free ((PTR) commands[0].argv[0]);
4ac4fd
+
4ac4fd
     return ret_code;
4ac4fd
   }
4ac4fd
 }
4ac4fd
@@ -5667,6 +5686,231 @@ give_switch (switchnum, omit_first_word,
4ac4fd
   switches[switchnum].validated = 1;
4ac4fd
 }
4ac4fd
 
4ac4fd
+#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS))
4ac4fd
+#define RETRY_ICE_ATTEMPTS 2
4ac4fd
+
4ac4fd
+static void
4ac4fd
+retry_ice (prog, argv)
4ac4fd
+     const char *prog;
4ac4fd
+     const char **argv;
4ac4fd
+{
4ac4fd
+  int nargs, out_arg = -1, quiet = 0, attempt;
4ac4fd
+  int pid, retries, sleep_interval;
4ac4fd
+  const char **new_argv;
4ac4fd
+  char *temp_filenames[RETRY_ICE_ATTEMPTS * 2 + 2];
4ac4fd
+
4ac4fd
+  if (input_filename == NULL || ! strcmp (input_filename, "-"))
4ac4fd
+    return;
4ac4fd
+
4ac4fd
+  for (nargs = 0; argv[nargs] != NULL; ++nargs)
4ac4fd
+    /* Only retry compiler ICEs, not preprocessor ones.  */
4ac4fd
+    if (! strcmp (argv[nargs], "-E"))
4ac4fd
+      return;
4ac4fd
+    else if (argv[nargs][0] == '-' && argv[nargs][1] == 'o')
4ac4fd
+      {
4ac4fd
+	if (out_arg == -1)
4ac4fd
+	  out_arg = nargs;
4ac4fd
+	else
4ac4fd
+	  return;
4ac4fd
+      }
4ac4fd
+    /* If the compiler is going to output any time information,
4ac4fd
+       it might varry between invocations.  */
4ac4fd
+    else if (! strcmp (argv[nargs], "-quiet"))
4ac4fd
+      quiet = 1;
4ac4fd
+    else if (! strcmp (argv[nargs], "-ftime-report"))
4ac4fd
+      return;
4ac4fd
+
4ac4fd
+  if (out_arg == -1 || !quiet)
4ac4fd
+    return;
4ac4fd
+
4ac4fd
+  memset (temp_filenames, '\0', sizeof (temp_filenames));
4ac4fd
+  new_argv = alloca ((nargs + 2) * sizeof (const char *));
4ac4fd
+  memcpy (new_argv, argv, (nargs + 1) * sizeof (const char *));
4ac4fd
+  if (new_argv[out_arg][2] == '\0')
4ac4fd
+    new_argv[out_arg + 1] = "-";
4ac4fd
+  else
4ac4fd
+    new_argv[out_arg] = "-o-";
4ac4fd
+
4ac4fd
+  for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS + 1; ++attempt)
4ac4fd
+    {
4ac4fd
+      int fd;
4ac4fd
+      int status;
4ac4fd
+
4ac4fd
+      temp_filenames[attempt * 2] = make_temp_file (".out");
4ac4fd
+      temp_filenames[attempt * 2 + 1] = make_temp_file (".err");
4ac4fd
+
4ac4fd
+      if (attempt == RETRY_ICE_ATTEMPTS)
4ac4fd
+        {
4ac4fd
+	  int i;
4ac4fd
+	  int fd1, fd2;
4ac4fd
+	  struct stat st1, st2;
4ac4fd
+	  size_t n, len;
4ac4fd
+	  char *buf;
4ac4fd
+	  char *cpp0;
4ac4fd
+
4ac4fd
+	  buf = xmalloc (8192);
4ac4fd
+
4ac4fd
+	  for (i = 0; i < 2; ++i)
4ac4fd
+	    {
4ac4fd
+	      fd1 = open (temp_filenames[i], O_RDONLY);
4ac4fd
+	      fd2 = open (temp_filenames[2 + i], O_RDONLY);
4ac4fd
+
4ac4fd
+	      if (fd1 < 0 || fd2 < 0)
4ac4fd
+		{
4ac4fd
+		  i = -1;
4ac4fd
+		  close (fd1);
4ac4fd
+		  close (fd2);
4ac4fd
+		  break;
4ac4fd
+		}
4ac4fd
+
4ac4fd
+	      if (fstat (fd1, &st1) < 0 || fstat (fd2, &st2) < 0)
4ac4fd
+		{
4ac4fd
+		  i = -1;
4ac4fd
+		  close (fd1);
4ac4fd
+		  close (fd2);
4ac4fd
+		  break;
4ac4fd
+		}
4ac4fd
+
4ac4fd
+	      if (st1.st_size != st2.st_size)
4ac4fd
+		{
4ac4fd
+		  close (fd1);
4ac4fd
+		  close (fd2);
4ac4fd
+		  break;
4ac4fd
+		}
4ac4fd
+
4ac4fd
+	      len = 0;
4ac4fd
+	      for (n = st1.st_size; n; n -= len)
4ac4fd
+		{
4ac4fd
+		  len = n;
4ac4fd
+		  if (len > 4096)
4ac4fd
+		    len = 4096;
4ac4fd
+
4ac4fd
+		  if (read (fd1, buf, len) != (int) len
4ac4fd
+		      || read (fd2, buf + 4096, len) != (int) len)
4ac4fd
+		    {
4ac4fd
+		      i = -1;
4ac4fd
+		      break;
4ac4fd
+		    }
4ac4fd
+
4ac4fd
+		  if (memcmp (buf, buf + 4096, len) != 0)
4ac4fd
+		    break;
4ac4fd
+		}
4ac4fd
+
4ac4fd
+	      close (fd1);
4ac4fd
+	      close (fd2);
4ac4fd
+
4ac4fd
+	      if (n)
4ac4fd
+		break;
4ac4fd
+	    }
4ac4fd
+
4ac4fd
+	  free (buf);
4ac4fd
+	  if (i == -1)
4ac4fd
+	    break;
4ac4fd
+
4ac4fd
+	  if (i != 2)
4ac4fd
+	    {
4ac4fd
+	      notice ("The bug is not reproducible, so it is likely a hardware or OS problem.\n");
4ac4fd
+	      break;
4ac4fd
+	    }
4ac4fd
+
4ac4fd
+          fd = open (temp_filenames[attempt * 2], O_RDWR);
4ac4fd
+	  if (fd < 0)
4ac4fd
+	    break;
4ac4fd
+	  write (fd, "//", 2);
4ac4fd
+	  for (i = 0; i < nargs; i++)
4ac4fd
+	    {
4ac4fd
+	      write (fd, " ", 1);
4ac4fd
+	      write (fd, new_argv[i], strlen (new_argv[i]));
4ac4fd
+	    }
4ac4fd
+	  write (fd, "\n", 1);
4ac4fd
+	  cpp0 = alloca (strlen (new_argv[0]) + sizeof "cpp0");
4ac4fd
+	  strcpy (cpp0, new_argv[0]);
4ac4fd
+	  new_argv[0] = cpp0;
4ac4fd
+	  cpp0 = strrchr (new_argv[0], DIR_SEPARATOR);
4ac4fd
+	  if (cpp0 != NULL)
4ac4fd
+	    strcpy (cpp0 + 1, "cpp0");
4ac4fd
+	  new_argv[nargs] = "--ice-hack";
4ac4fd
+	  new_argv[nargs + 1] = NULL;
4ac4fd
+        }
4ac4fd
+
4ac4fd
+      /* Fork a subprocess; wait and retry if it fails.  */
4ac4fd
+      sleep_interval = 1;
4ac4fd
+      pid = -1;
4ac4fd
+      for (retries = 0; retries < 4; retries++)
4ac4fd
+	{
4ac4fd
+	  pid = fork ();
4ac4fd
+	  if (pid >= 0)
4ac4fd
+	    break;
4ac4fd
+	  sleep (sleep_interval);
4ac4fd
+	  sleep_interval *= 2;
4ac4fd
+	}
4ac4fd
+
4ac4fd
+      if (pid < 0)
4ac4fd
+	break;
4ac4fd
+      else if (pid == 0)
4ac4fd
+	{
4ac4fd
+	  if (attempt != RETRY_ICE_ATTEMPTS)
4ac4fd
+	    fd = open (temp_filenames[attempt * 2], O_RDWR);
4ac4fd
+	  if (fd < 0)
4ac4fd
+	    exit (-1);
4ac4fd
+	  if (fd != 1)
4ac4fd
+	    {
4ac4fd
+	      close (1);
4ac4fd
+	      dup (fd);
4ac4fd
+	      close (fd);
4ac4fd
+	    }
4ac4fd
+
4ac4fd
+	  fd = open (temp_filenames[attempt * 2 + 1], O_RDWR);
4ac4fd
+	  if (fd < 0)
4ac4fd
+	    exit (-1);
4ac4fd
+	  if (fd != 2)
4ac4fd
+	    {
4ac4fd
+	      close (2);
4ac4fd
+	      dup (fd);
4ac4fd
+	      close (fd);
4ac4fd
+	    }
4ac4fd
+
4ac4fd
+	  if (prog == new_argv[0])
4ac4fd
+	    execvp (prog, (char *const *) new_argv);
4ac4fd
+	  else
4ac4fd
+	    execv (new_argv[0], (char *const *) new_argv);
4ac4fd
+	  exit (-1);
4ac4fd
+	}
4ac4fd
+
4ac4fd
+      if (waitpid (pid, &status, 0) < 0)
4ac4fd
+	break;
4ac4fd
+
4ac4fd
+      if (attempt < RETRY_ICE_ATTEMPTS
4ac4fd
+	  && (! WIFEXITED (status) || WEXITSTATUS (status) != ICE_EXIT_CODE))
4ac4fd
+	{
4ac4fd
+	  notice ("The bug is not reproducible, so it is likely a hardware or OS problem.\n");
4ac4fd
+	  break;
4ac4fd
+	}
4ac4fd
+      else if (attempt == RETRY_ICE_ATTEMPTS)
4ac4fd
+	{
4ac4fd
+	  close (fd);
4ac4fd
+	  if (WIFEXITED (status)
4ac4fd
+	      && WEXITSTATUS (status) == SUCCESS_EXIT_CODE)
4ac4fd
+	    {
4ac4fd
+	      notice ("Preprocessed source stored into %s file, please attach this to your bugreport.\n",
4ac4fd
+		      temp_filenames[attempt * 2]);
4ac4fd
+	      /* Make sure it is not deleted.  */
4ac4fd
+	      free (temp_filenames[attempt * 2]);
4ac4fd
+	      temp_filenames[attempt * 2] = NULL;
4ac4fd
+	      break;
4ac4fd
+	    }
4ac4fd
+	}
4ac4fd
+    }
4ac4fd
+
4ac4fd
+  for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS * 2 + 2; attempt++)
4ac4fd
+    if (temp_filenames[attempt])
4ac4fd
+      {
4ac4fd
+	unlink (temp_filenames[attempt]);
4ac4fd
+	free (temp_filenames[attempt]);
4ac4fd
+      }
4ac4fd
+}
4ac4fd
+#endif
4ac4fd
+
4ac4fd
 /* Search for a file named NAME trying various prefixes including the
4ac4fd
    user's -B prefix and some standard ones.
4ac4fd
    Return the absolute file name found.  If nothing is found, return NAME.  */
4ac4fd
--- gcc/diagnostic.c.jj	2002-01-24 23:37:04.000000000 +0100
4ac4fd
+++ gcc/diagnostic.c	2003-10-03 19:01:24.000000000 +0200
4ac4fd
@@ -1242,7 +1242,7 @@ internal_error VPARAMS ((const char *msg
4ac4fd
 "Please submit a full bug report,\n\
4ac4fd
 with preprocessed source if appropriate.\n\
4ac4fd
 See %s for instructions.\n", GCCBUGURL);
4ac4fd
-  exit (FATAL_EXIT_CODE);
4ac4fd
+  exit (ICE_EXIT_CODE);
4ac4fd
 }
4ac4fd
 
4ac4fd
 void
4ac4fd
@@ -1392,7 +1392,7 @@ error_recursion ()
4ac4fd
 "Please submit a full bug report,\n\
4ac4fd
 with preprocessed source if appropriate.\n\
4ac4fd
 See %s for instructions.\n", GCCBUGURL);
4ac4fd
-  exit (FATAL_EXIT_CODE);
4ac4fd
+  exit (ICE_EXIT_CODE);
4ac4fd
 }
4ac4fd
 
4ac4fd
 /* Given a partial pathname as input, return another pathname that
4ac4fd
--- gcc/cppmain.c.jj	2002-05-03 20:19:22.000000000 +0200
4ac4fd
+++ gcc/cppmain.c	2003-10-06 10:35:15.000000000 +0200
4ac4fd
@@ -111,10 +111,33 @@ do_preprocessing (argc, argv)
4ac4fd
      char **argv;
4ac4fd
 {
4ac4fd
   int argi = 1;  /* Next argument to handle.  */
4ac4fd
+  int ice_hack = 0;
4ac4fd
 
4ac4fd
-  argi += cpp_handle_options (pfile, argc - argi , argv + argi);
4ac4fd
-  if (CPP_FATAL_ERRORS (pfile))
4ac4fd
-    return;
4ac4fd
+  if (argc >= 1 && strcmp (argv[argc - 1], "--ice-hack") == 0)
4ac4fd
+    {
4ac4fd
+      ice_hack = 1;
4ac4fd
+      for (argi = 1; argi + 1 < argc; argi++)
4ac4fd
+	if (strcmp (argv[argi], "-dumpbase") == 0)
4ac4fd
+	  {
4ac4fd
+	    argv[argi] = "-quiet";
4ac4fd
+	    argv[argi + 1] = "-quiet";
4ac4fd
+	    break;
4ac4fd
+	  }
4ac4fd
+      argi = 1;
4ac4fd
+    }
4ac4fd
+
4ac4fd
+  do
4ac4fd
+    {
4ac4fd
+      argi += cpp_handle_options (pfile, argc - argi, argv + argi);
4ac4fd
+      if (CPP_FATAL_ERRORS (pfile))
4ac4fd
+        return;
4ac4fd
+
4ac4fd
+      if (argi >= argc || !ice_hack)
4ac4fd
+	break;
4ac4fd
+
4ac4fd
+      argi++;
4ac4fd
+    }
4ac4fd
+  while (argi < argc);
4ac4fd
 
4ac4fd
   if (argi < argc)
4ac4fd
     {