aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorGeoffrey Keating <geoffk@apple.com>2003-04-12 02:16:46 +0000
committerGeoffrey Keating <geoffk@gcc.gnu.org>2003-04-12 02:16:46 +0000
commita37db56bde9874b6f2113164e2a31c5bc12616c8 (patch)
tree743ad4a7d130f0376f5a69b500437fcf54a84cf5 /gcc/tree.c
parentdf0261868594f8e8c8ec2e1a369ca7fe867a2d02 (diff)
downloadgcc-a37db56bde9874b6f2113164e2a31c5bc12616c8.zip
gcc-a37db56bde9874b6f2113164e2a31c5bc12616c8.tar.gz
gcc-a37db56bde9874b6f2113164e2a31c5bc12616c8.tar.bz2
re PR c++/9393 (Anonymous namespaces and compiling the same file twice)
PR c++/9393 * doc/invoke.texi (Debugging Options): Document -frandom-seed. * configure.in: Check for gettimeofday. * tree.c (flag_random_seed): Define. (default_flag_random_seed): New. (append_random_chars): Use flag_random_seed rather than trying to acquire randomness here. * tree.h (default_flag_random_seed): Declare. * toplev.c (display_help): Add -frandom-seed and -fstack-limit-* descriptions. (decode_f_option): Handle -frandom-seed. (print_switch_values): Call default_flag_random_seed. * flags.h (flag_random_seed): Declare. * configure: Regenerate. * config.in: Regenerate. * config/alpha/t-crtfm: Use -frandom-seed. From-SVN: r65500
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c68
1 files changed, 40 insertions, 28 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 57d76b4..fc4630f 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -4294,6 +4294,38 @@ dump_tree_statistics ()
#define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
+const char *flag_random_seed;
+
+/* Set up a default flag_random_seed value, if there wasn't one already. */
+
+void
+default_flag_random_seed (void)
+{
+ unsigned HOST_WIDE_INT value;
+ char *new_random_seed;
+
+ if (flag_random_seed != NULL)
+ return;
+
+ /* Get some more or less random data. */
+#ifdef HAVE_GETTIMEOFDAY
+ {
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ value = (((unsigned HOST_WIDE_INT) tv.tv_usec << 16)
+ ^ tv.tv_sec ^ getpid ());
+ }
+#else
+ value = getpid ();
+#endif
+
+ /* This slightly overestimates the space required. */
+ new_random_seed = xmalloc (HOST_BITS_PER_WIDE_INT / 3 + 2);
+ sprintf (new_random_seed, HOST_WIDE_INT_PRINT_UNSIGNED, value);
+ flag_random_seed = new_random_seed;
+}
+
/* Appends 6 random characters to TEMPLATE to (hopefully) avoid name
clashes in cases where we can't reliably choose a unique name.
@@ -4305,40 +4337,20 @@ append_random_chars (template)
{
static const char letters[]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- static unsigned HOST_WIDE_INT value;
unsigned HOST_WIDE_INT v;
+ size_t i;
- if (! value)
- {
- struct stat st;
+ default_flag_random_seed ();
- /* VALUE should be unique for each file and must not change between
- compiles since this can cause bootstrap comparison errors. */
-
- if (stat (main_input_filename, &st) < 0)
- {
- /* This can happen when preprocessed text is shipped between
- machines, e.g. with bug reports. Assume that uniqueness
- isn't actually an issue. */
- value = 1;
- }
- else
- {
- /* In VMS, ino is an array, so we have to use both values. We
- conditionalize that. */
-#ifdef VMS
-#define INO_TO_INT(INO) ((int) (INO)[1] << 16 ^ (int) (INO)[2])
-#else
-#define INO_TO_INT(INO) INO
-#endif
- value = st.st_dev ^ INO_TO_INT (st.st_ino) ^ st.st_mtime;
- }
- }
+ /* This isn't a very good hash, but it does guarantee no collisions
+ when the random string is generated by the code above and the time
+ delta is small. */
+ v = 0;
+ for (i = 0; i < strlen (flag_random_seed); i++)
+ v = (v << 4) ^ (v >> (HOST_BITS_PER_WIDE_INT - 4)) ^ flag_random_seed[i];
template += strlen (template);
- v = value;
-
/* Fill in the random bits. */
template[0] = letters[v % 62];
v /= 62;