]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gcov-profile: Fix -fcompare-debug with -fprofile-generate [PR100520]
authorMartin Liska <mliska@suse.cz>
Fri, 5 Nov 2021 15:50:06 +0000 (16:50 +0100)
committerMartin Liska <mliska@suse.cz>
Mon, 8 Nov 2021 12:26:31 +0000 (13:26 +0100)
PR gcov-profile/100520

gcc/ChangeLog:

* coverage.c (coverage_compute_profile_id): Strip .gk when
compare debug is used.
* system.h (endswith): New function.

gcc/testsuite/ChangeLog:

* gcc.dg/pr100520.c: New test.

(cherry picked from commit 7553bd35c876efaf8ab0b6661a6102822b99e6e3)

gcc/coverage.c
gcc/system.h
gcc/testsuite/gcc.dg/pr100520.c [new file with mode: 0644]

index 9b98e0173abeeed26e42c39b0b4ef661b75a2b96..17d1beeca3da5c6abd4debf46a99e2526f3fabd3 100644 (file)
@@ -576,8 +576,11 @@ coverage_compute_profile_id (struct cgraph_node *n)
       if (!use_name_only && first_global_object_name)
        chksum = coverage_checksum_string
          (chksum, first_global_object_name);
-      chksum = coverage_checksum_string
-       (chksum, aux_base_name);
+      char *base_name = xstrdup (aux_base_name);
+      if (endswith (base_name, ".gk"))
+       base_name[strlen (base_name) - 3] = '\0';
+      chksum = coverage_checksum_string (chksum, base_name);
+      free (base_name);
     }
 
   /* Non-negative integers are hopefully small enough to fit in all targets.
index a3f5948aaeec3b6c8350a57259113b022f06a16e..b13e9429577ac968f60579bb736d80c75a8f0b1c 100644 (file)
@@ -1291,4 +1291,17 @@ void gcc_stablesort (void *, size_t, size_t,
 #define NULL nullptr
 #endif
 
+/* Return true if STR string ends with SUFFIX.  */
+
+static inline bool
+endswith (const char *str, const char *suffix)
+{
+  size_t str_len = strlen (str);
+  size_t suffix_len = strlen (suffix);
+  if (str_len < suffix_len)
+    return false;
+
+  return memcmp (str + str_len - suffix_len, suffix, suffix_len) == 0;
+}
+
 #endif /* ! GCC_SYSTEM_H */
diff --git a/gcc/testsuite/gcc.dg/pr100520.c b/gcc/testsuite/gcc.dg/pr100520.c
new file mode 100644 (file)
index 0000000..60f79c2
--- /dev/null
@@ -0,0 +1,5 @@
+/* PR gcov-profile/100520 */
+/* { dg-do compile } */
+/* { dg-options "-fcompare-debug -fprofile-generate" } */
+
+static int f() {}