OSDN Git Service

gcc/ChangeLog:
authoraoliva <aoliva@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 14 Mar 2007 01:47:33 +0000 (01:47 +0000)
committeraoliva <aoliva@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 14 Mar 2007 01:47:33 +0000 (01:47 +0000)
* flags.h (flag_random_seed): Remove declaration, in favor of...
* toplev.h (get_random_seed, set_random_seed): ... these.
* tree.c (get_file_function_name): Use the former.
* opts.c (common_handle_option): Use the latter.
* toplev.c
gcc/cp/ChangeLog:
* cp/repo.c (init_repo): Initialize random_seed saved options.
(finish_repo): Adjust.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122901 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/repo.c
gcc/flags.h
gcc/opts.c
gcc/toplev.c
gcc/toplev.h
gcc/tree.c

index 9d2fc89..45d009d 100644 (file)
@@ -1,3 +1,11 @@
+2007-03-13  Alexandre Oliva  <aoliva@redhat.com>
+
+       * flags.h (flag_random_seed): Remove declaration, in favor of...
+       * toplev.h (get_random_seed, set_random_seed): ... these.
+       * tree.c (get_file_function_name): Use the former.
+       * opts.c (common_handle_option): Use the latter.
+       * toplev.c
+
 2007-03-13  Steven Bosscher  <steven@gcc.gnu.org>
 
        PR middle-end/31127
index b18286d..a56322b 100644 (file)
@@ -1,3 +1,8 @@
+2007-03-13  Alexandre Oliva  <aoliva@redhat.com>
+
+       * cp/repo.c (init_repo): Initialize random_seed saved options.
+       (finish_repo): Adjust.
+
 2007-03-13  Mark Mitchell  <mark@codesourcery.com>
 
        PR bootstrap/30899
index 2bf0303..a9b0852 100644 (file)
@@ -1,6 +1,6 @@
 /* Code to maintain a C++ template repository.
-   Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005
-   Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005,
+   2006, 2007  Free Software Foundation, Inc.
    Contributed by Jason Merrill (jason@cygnus.com)
 
 This file is part of GCC.
@@ -203,6 +203,10 @@ init_repo (void)
       obstack_free (&temporary_obstack, buf);
     }
   fclose (repo_file);
+
+  if (old_args && !get_random_seed (true)
+      && (buf = strstr (old_args, "'-frandom-seed=")))
+    set_random_seed (extract_string (&buf) + strlen ("-frandom-seed="));
 }
 
 static FILE *
@@ -250,7 +254,7 @@ finish_repo (void)
         anonymous namespaces will get the same mangling when this
         file is recompiled.  */
       if (!strstr (args, "'-frandom-seed="))
-       fprintf (repo_file, " '-frandom-seed=%s'", flag_random_seed);
+       fprintf (repo_file, " '-frandom-seed=%s'", get_random_seed (false));
       fprintf (repo_file, "\n");
     }
 
index 2a5515f..0b594ee 100644 (file)
@@ -251,11 +251,6 @@ extern int flag_var_tracking;
    warning message in case flag was set by -fprofile-{generate,use}.  */
 extern bool flag_speculative_prefetching_set;
 
-/* A string that's used when a random name is required.  NULL means
-   to make it really random.  */
-
-extern const char *flag_random_seed;
-
 /* Returns TRUE if generated code should match ABI version N or
    greater is in use.  */
 
index ecbc9a3..f8eeb1a 100644 (file)
@@ -1268,11 +1268,11 @@ common_handle_option (size_t scode, const char *arg, int value,
       /* The real switch is -fno-random-seed.  */
       if (value)
        return 0;
-      flag_random_seed = NULL;
+      set_random_seed (NULL);
       break;
 
     case OPT_frandom_seed_:
-      flag_random_seed = arg;
+      set_random_seed (arg);
       break;
 
     case OPT_fsched_verbose_:
index 4ad6f1d..8a471d8 100644 (file)
@@ -1,6 +1,6 @@
 /* Top level of GCC compilers (cc1, cc1plus, etc.)
    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -239,7 +239,7 @@ int in_system_header = 0;
 int flag_detailed_statistics = 0;
 
 /* A random sequence of characters, unless overridden by user.  */
-const char *flag_random_seed;
+static const char *flag_random_seed;
 
 /* A local time stamp derived from the time of compilation. It will be
    zero if the system cannot provide a time.  It will be -1u, if the
@@ -451,23 +451,20 @@ announce_function (tree decl)
     }
 }
 
-/* Set up a default flag_random_seed and local_tick, unless the user
-   already specified one.  */
+/* Initialize local_tick with the time of day, or -1 if
+   flag_random_seed is set.  */
 
 static void
-randomize (void)
+init_local_tick (void)
 {
   if (!flag_random_seed)
     {
-      unsigned HOST_WIDE_INT value;
-      static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
-
       /* Get some more or less random data.  */
 #ifdef HAVE_GETTIMEOFDAY
       {
-       struct timeval tv;
+       struct timeval tv;
 
-       gettimeofday (&tv, NULL);
+       gettimeofday (&tv, NULL);
        local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
       }
 #else
@@ -478,15 +475,47 @@ randomize (void)
          local_tick = (unsigned) now;
       }
 #endif
-      value = local_tick ^ getpid ();
-
-      sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
-      flag_random_seed = random_seed;
     }
-  else if (!local_tick)
+  else
     local_tick = -1;
 }
 
+/* Set up a default flag_random_seed and local_tick, unless the user
+   already specified one.  Must be called after init_local_tick.  */
+
+static void
+init_random_seed (void)
+{
+  unsigned HOST_WIDE_INT value;
+  static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
+
+  value = local_tick ^ getpid ();
+
+  sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
+  flag_random_seed = random_seed;
+}
+
+/* Obtain the random_seed string.  Unless NOINIT, initialize it if
+   it's not provided in the command line.  */
+
+const char *
+get_random_seed (bool noinit)
+{
+  if (!flag_random_seed && !noinit)
+    init_random_seed ();
+  return flag_random_seed;
+}
+
+/* Modify the random_seed string to VAL.  Return its previous
+   value.  */
+
+const char *
+set_random_seed (const char *val)
+{
+  const char *old = flag_random_seed;
+  flag_random_seed = val;
+  return old;
+}
 
 /* Decode the string P as an integral parameter.
    If the string is indeed an integer return its numeric value else
@@ -1277,7 +1306,8 @@ print_switch_values (print_switch_fn_type print_fn)
 
   /* Fill in the -frandom-seed option, if the user didn't pass it, so
      that it can be printed below.  This helps reproducibility.  */
-  randomize ();
+  if (!flag_random_seed)
+    init_random_seed ();
 
   /* Print the options as passed.  */
   pos = print_single_switch (print_fn, pos,
@@ -2119,7 +2149,7 @@ toplev_main (unsigned int argc, const char **argv)
      enough to default flags appropriately.  */
   decode_options (argc, argv);
 
-  randomize ();
+  init_local_tick ();
 
   /* Exit early if we can (e.g. -help).  */
   if (!exit_after_options)
index a23d52c..524708d 100644 (file)
@@ -1,5 +1,5 @@
 /* toplev.h - Various declarations for functions found in toplev.c
-   Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005
+   Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -191,4 +191,9 @@ exact_log2 (unsigned HOST_WIDE_INT x)
 extern const char *get_src_pwd        (void);
 extern bool set_src_pwd                       (const char *);
 
+/* Functions used to manipulate the random seed.  */
+
+extern const char *get_random_seed (bool);
+extern const char *set_random_seed (const char *);
+
 #endif /* ! GCC_TOPLEV_H */
index 53cec8f..baf94b2 100644 (file)
@@ -6497,7 +6497,7 @@ get_file_function_name (const char *type)
       clean_symbol_name (q);
 
       sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
-              crc32_string (0, flag_random_seed));
+              crc32_string (0, get_random_seed (false)));
 
       p = q;
     }