Take: static inline void foo (char *p) { __builtin___memcpy_chk (p, "abc", 3, __builtin_object_size (p, 0)); } static void bar (char *p) __attribute__((noinline)); static void bar (char *p) { foo (p); } void f(char*) __attribute__((noipa)); char buf[2]; void baz (void) __attribute__((noinline)); void baz (void) { bar (buf); f(buf); } void f(char*) {} int main(void) { baz(); } ---- CUT --- Compile the C program with "-O2 -Wall", we get: In function 'foo', inlined from 'bar.constprop' at <source>:12:3: <source>:5:3: warning: '__builtin___memcpy_chk' forming offset 2 is out of the bounds [0, 2] of object 'buf' with type 'char[2]' [-Warray-bounds] 5 | __builtin___memcpy_chk (p, "abc", 3, __builtin_object_size (p, 0)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>: In function 'bar.constprop': <source>:15:6: note: 'buf' declared here 15 | char buf[2]; | ^~~ See how bar.constprop is exposed. That is an internal details. Note compiling it with the C++ front-end we get: inlined from 'void bar(char*)' at <source>:12:7: And then compiling with -flto again we get the bar.constprop. But really we should add another note saying where the clone was created from.
Can you show what you have in mind? It's easy to to strip the .constprop suffix but I'm not sure I understand what you mean by "where the clone was created from."
I suppose he means to follow the DECL_ABSTRACT_ORIGIN links to the origin.
diff --git a/gcc/langhooks.cc b/gcc/langhooks.cc index 61f2b676256..89a89b74535 100644 --- a/gcc/langhooks.cc +++ b/gcc/langhooks.cc @@ -223,6 +223,8 @@ lhd_get_alias_set (tree ARG_UNUSED (t)) const char * lhd_decl_printable_name (tree decl, int ARG_UNUSED (verbosity)) { + while (DECL_ABSTRACT_ORIGIN(decl) && DECL_ABSTRACT_ORIGIN(decl) != decl) + decl = DECL_ABSTRACT_ORIGIN(decl); gcc_assert (decl && DECL_NAME (decl)); return IDENTIFIER_POINTER (DECL_NAME (decl)); } This patch appears to fix the issue. The call site of lhd_decl_printable_name is lhd_print_error_function, which I suppose is used for warnings too. if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE) pp_printf (context->printer, _("In member function %qs"), identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2))); else pp_printf (context->printer, _("In function %qs"), identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
Assigning to Peter as per his request.
I finally got some time to look at the test failures this patch causes. https://gcc.gnu.org/cgit/gcc/tree/gcc/testsuite/gcc.dg/independent-cloneids-1.c Perhaps decl_printable_name is also used when writing names out in RTL dumps. I will take a look later and verify if this is the case. I assume it's desired to have cloned functions mentioned there, but I'm not sure.
I confirmed this is the case. Compiling the example from the testcase independent-cloneids-1.c confirms that lhd_decl_printable_name is also used for -fdump-rtl-final, my patch results in: ;; Function bar (bar.constprop.0, funcdef_no=3, decl_uid=2796, cgraph_uid=5, symbol_order=4) When previously it was: ;; Function bar.constprop (bar.constprop.0, funcdef_no=3, decl_uid=2002, cgraph_uid=5, symbol_order=4) I assume it is desired to include cloned names in the RTL dumps, so following the DECL_ORIGIN in lhd_decl_printable_name isn't okay. Maybe having a separate "lhd_decl_user_readable_name" would be necessary to avoid this. Or potentially doing the "following DECL_ORIGIN links" in lhd_print_error_function, or something more language specific. There might be some other call sites that produce user facing diagnostics which would need this sort of adjustment too, perhaps in the analyzer, but I'm not qualified to tell.