diff options
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 68 |
1 files changed, 40 insertions, 28 deletions
@@ -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; |