coverage.c (checksum_string): Rename to ...
authorJan Hubicka <jh@suse.cz>
Sun, 18 Jan 2004 15:10:23 +0000 (16:10 +0100)
committerJan Hubicka <hubicka@gcc.gnu.org>
Sun, 18 Jan 2004 15:10:23 +0000 (15:10 +0000)
* coverage.c (checksum_string): Rename to ...
(coverage_checksum_string): ... this one, Use crc32_string; recognize
names containing random number and zero the number out in order to get
match.

From-SVN: r76102

gcc/ChangeLog
gcc/coverage.c

index 47ec2e7fbb9517ce20a32b087427a3334058f643..a7db3f7ba90946749ccb93a342d1580477c63519 100644 (file)
@@ -1,3 +1,10 @@
+2004-01-18  Jan Hubicka  <jh@suse.cz>
+
+       * coverage.c (checksum_string): Rename to ...
+       (coverage_checksum_string): ... this one, Use crc32_string; recognize
+       names containing random number and zero the number out in order to get
+       match.
+
 2004-01-18  Richard Sandiford  <rsandifo@redhat.com>
 
        * config/mips/mips.c (mips_got_alias_set): Mark for PCH.
index f14f0f666fee27ad9e8590d50585f95185be1426..d6322b2ca77cf064a9607c8a9049ea8000fef997 100644 (file)
@@ -109,7 +109,7 @@ static int htab_counts_entry_eq (const void *, const void *);
 static void htab_counts_entry_del (void *);
 static void read_counts_file (void);
 static unsigned compute_checksum (void);
-static unsigned checksum_string (unsigned, const char *);
+static unsigned coverage_checksum_string (unsigned, const char *);
 static tree build_fn_info_type (unsigned);
 static tree build_fn_info_value (const struct function_list *, tree);
 static tree build_ctr_info_type (void);
@@ -405,23 +405,51 @@ coverage_counter_ref (unsigned counter, unsigned no)
    checksum.  */
 
 static unsigned
-checksum_string (unsigned chksum, const char *string)
+coverage_checksum_string (unsigned chksum, const char *string)
 {
-  do
+  int i;
+  char *dup = NULL;
+
+  /* Look for everything that looks if it were produced by
+     get_file_function_name_long and zero out the second part
+     that may result from flag_random_seed.  This is not critical
+     as the checksums are used only for sanity checking.  */
+  for (i = 0; string[i]; i++)
     {
-      unsigned value = *string << 24;
-      unsigned ix;
-
-      for (ix = 8; ix--; value <<= 1)
-       {
-         unsigned feedback;
-
-         feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
-         chksum <<= 1;
-         chksum ^= feedback;
-       }
+      if (!strncmp (string + i, "_GLOBAL__", 9))
+       for (i = i + 9; string[i]; i++)
+         if (string[i]=='_')
+           {
+             int y;
+             unsigned seed;
+
+             for (y = 1; y < 9; y++)
+               if (!(string[i + y] >= '0' && string[i + y] <= '9')
+                   && !(string[i + y] >= 'A' && string[i + y] <= 'F'))
+                 break;
+             if (y != 9 || string[i + 9] != '_')
+               continue;
+             for (y = 10; y < 18; y++)
+               if (!(string[i + y] >= '0' && string[i + y] <= '9')
+                   && !(string[i + y] >= 'A' && string[i + y] <= 'F'))
+                 break;
+             if (y != 18)
+               continue;
+             if (!sscanf (string + i + 10, "%X", &seed))
+               abort ();
+             if (seed != crc32_string (0, flag_random_seed))
+               continue;
+             string = dup = xstrdup (string);
+             for (y = 10; y < 18; y++)
+               dup[i + y] = '0';
+             break;
+           }
+      break;
     }
-  while (*string++);
+
+  chksum = crc32_string (chksum, string);
+  if (dup)
+    free (dup);
 
   return chksum;
 }
@@ -433,8 +461,9 @@ compute_checksum (void)
 {
   unsigned chksum = DECL_SOURCE_LINE (current_function_decl);
 
-  chksum = checksum_string (chksum, DECL_SOURCE_FILE (current_function_decl));
-  chksum = checksum_string
+  chksum = coverage_checksum_string (chksum,
+                                    DECL_SOURCE_FILE (current_function_decl));
+  chksum = coverage_checksum_string
     (chksum, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)));
 
   return chksum;