From 4de3524f9e88b7b22bdb481163b05a624f090cf9 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Mon, 7 Jul 2025 17:18:23 +0200 Subject: [PATCH] Fix auto-profile.cc:get_original_name 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc index a970eb8972f..1700bf8f2cd 100644 --- a/gcc/auto-profile.cc +++ b/gcc/auto-profile.cc @@ -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); -- 2.47.2