On Thu, 20 Mar 2025, Jason Merrill wrote:

> Tested x86_64-pc-linux-gnu.  OK for trunk and backports?
> 
> -- 8< --
> 
> Since the mangling of the second lambda changed (previously we counted all
> lambdas, now we only count lambdas with the same signature), we
> generate_mangling_alias for handler<lambda2> for backward compatibility.
> Since handler is COMDAT, resolve_alias puts the alias in the same comdat
> group as handler itself.  Then create_dispatcher_calls tries to add the
> alias to the same comdat group as the dispatcher, but it's already in a
> same_comdat_group, so we ICE.
> 
> It seems like we're just missing a remove_from_same_comdat_group before
> add_to_same_comdat_group.

LGTM, let's see if Honza has any comments.

Richard.

>       PR c++/114992
> 
> gcc/ChangeLog:
> 
>       * multiple_target.cc (create_dispatcher_calls):
>       remove_from_same_comdat_group before add_to_same_comdat_group.
> 
> gcc/testsuite/ChangeLog:
> 
>       * g++.target/i386/mangling-alias1.C: New test.
> ---
>  gcc/multiple_target.cc                          |  6 +++++-
>  gcc/testsuite/g++.target/i386/mangling-alias1.C | 16 ++++++++++++++++
>  2 files changed, 21 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.target/i386/mangling-alias1.C
> 
> diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc
> index d8becf4d9a9..d25277c0a93 100644
> --- a/gcc/multiple_target.cc
> +++ b/gcc/multiple_target.cc
> @@ -155,7 +155,11 @@ create_dispatcher_calls (struct cgraph_node *node)
>             symtab_node *source = ref->referring;
>             source->create_reference (inode, IPA_REF_ALIAS);
>             if (inode->get_comdat_group ())
> -             source->add_to_same_comdat_group (inode);
> +             {
> +               if (source->same_comdat_group)
> +                 source->remove_from_same_comdat_group ();
> +               source->add_to_same_comdat_group (inode);
> +             }
>           }
>         else
>           gcc_unreachable ();
> diff --git a/gcc/testsuite/g++.target/i386/mangling-alias1.C 
> b/gcc/testsuite/g++.target/i386/mangling-alias1.C
> new file mode 100644
> index 00000000000..70264e2b64e
> --- /dev/null
> +++ b/gcc/testsuite/g++.target/i386/mangling-alias1.C
> @@ -0,0 +1,16 @@
> +// PR c++/114992
> +// { dg-do compile { target { c++11 && x86_64-*-* } } }
> +// { dg-require-ifunc }
> +
> +template <typename Callable>
> +__attribute__((target_clones("avx2", "default")))
> +void handler(Callable) {}
> +
> +inline int func()
> +{
> +  auto l1 = [](int) {}; // different lambda signature
> +  handler([]() {}); // so this one needs a mangling alias
> +  return 42;
> +}
> +
> +int g = func();
> 
> base-commit: 56145ae79b89b823f306c2c241f6a1fe5d604816
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

Reply via email to