diff mbox series

diagnostics: Follow DECL_ABSTRACT_ORIGIN links in lhd_decl_printable_name [PR102061]

Message ID 20240703061142.23604-1-peter0x44@disroot.org
State New
Headers show
Series diagnostics: Follow DECL_ABSTRACT_ORIGIN links in lhd_decl_printable_name [PR102061] | expand

Commit Message

Peter0x44 July 3, 2024, 6:11 a.m. UTC
Currently, if a warning references a cloned function, the name of the cloned
function will be emitted in the "In function 'xyz'" part of the diagnostic,
which users aren't supposed to see. This patch follows the DECL_ABSTRACT_ORIGIN
links until encountering the original function.

gcc/ChangeLog:
	PR diagnostics/102061
	* langhooks.cc (lhd_decl_printable_name): Follow DECL_ABSTRACT_ORIGIN
	links to the source

Signed-off-by: Peter Damianov <peter0x44@disroot.org>
---

I would add a testcase but I'm not familiar with that process, and would need
some help. I also did not bootstrap or test this patch, I'm posting to see if
the CI will do it for me.

I used "while" because I'm not sure if there can be clones of clones or not.
The second check is because I see comments elsewhere that say:
"DECL_ABSTRACT_ORIGIN can point to itself", so I want to avoid a potential
infinite loop.

 gcc/langhooks.cc | 2 ++
 1 file changed, 2 insertions(+)

Comments

Richard Biener July 3, 2024, 8:24 a.m. UTC | #1
On Wed, Jul 3, 2024 at 8:18 AM Peter Damianov <peter0x44@disroot.org> wrote:
>
> Currently, if a warning references a cloned function, the name of the cloned
> function will be emitted in the "In function 'xyz'" part of the diagnostic,
> which users aren't supposed to see. This patch follows the DECL_ABSTRACT_ORIGIN
> links until encountering the original function.
>
> gcc/ChangeLog:
>         PR diagnostics/102061
>         * langhooks.cc (lhd_decl_printable_name): Follow DECL_ABSTRACT_ORIGIN
>         links to the source
>
> Signed-off-by: Peter Damianov <peter0x44@disroot.org>
> ---
>
> I would add a testcase but I'm not familiar with that process, and would need
> some help. I also did not bootstrap or test this patch, I'm posting to see if
> the CI will do it for me.
>
> I used "while" because I'm not sure if there can be clones of clones or not.
> The second check is because I see comments elsewhere that say:
> "DECL_ABSTRACT_ORIGIN can point to itself", so I want to avoid a potential
> infinite loop.
>
>  gcc/langhooks.cc | 2 ++
>  1 file changed, 2 insertions(+)
>
> 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);

DECL_ABSTRACT_ORIGIN is maintained to point to the original function, there's
no need to "iterate" here.  You should be able to do

     decl = DECL_ORIGIN (decl);

>    gcc_assert (decl && DECL_NAME (decl));
>    return IDENTIFIER_POINTER (DECL_NAME (decl));
>  }
> --
> 2.39.2
>
diff mbox series

Patch

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));
 }