]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix auto-profile.cc:get_original_name
authorJan Hubicka <hubicka@ucw.cz>
Mon, 7 Jul 2025 15:18:23 +0000 (17:18 +0200)
committerJan Hubicka <hubicka@ucw.cz>
Wed, 9 Jul 2025 10:20:56 +0000 (12:20 +0200)
There are two bugs in get_original_name.  FIrst the for loop walking list of known
suffixes uses sizeos (suffixes).  It evnetually walks to an empty suffix.
Second problem is that strcmp may accept suffixes that are longer.  I.e.
mix up .isra with .israabc.  This is probably not a big deal but the first
bug makes get_original_name to effectively strip all suffixes, even important
one on my setup.

gcc/ChangeLog:

* auto-profile.cc (get_original_name): Fix loop walking the
suffixes.

gcc/auto-profile.cc

index a970eb8972fadd133135d2feff1b8c3a9dd940e8..1700bf8f2cd4664c0f628e1106ceed2e6c21cca9 100644 (file)
@@ -622,9 +622,11 @@ get_original_name (const char *name, bool alloc = true)
     }
   /* Suffixes of clones that compiler generates after auto-profile.  */
   const char *suffixes[] = {"isra", "constprop", "lto_priv", "part", "cold"};
-  for (unsigned i = 0; i < sizeof (suffixes); ++i)
+  for (unsigned i = 0; i < sizeof (suffixes) / sizeof (const char *); ++i)
     {
-      if (strncmp (next_dot + 1, suffixes[i], strlen (suffixes[i])) == 0)
+      int len = strlen (suffixes[i]);
+      if (len == last_dot - next_dot - 1
+         && strncmp (next_dot + 1, suffixes[i], strlen (suffixes[i])) == 0)
        {
          *next_dot = 0;
          return get_original_name (ret, false);