Message ID | 20230308025945.648936-1-jason@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E5723854178 for <patchwork@sourceware.org>; Wed, 8 Mar 2023 03:00:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E5723854178 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678244421; bh=Xnd/2BbDG55W/MHCzORIJVqtMX8/7OdK14VlJe3Gxk8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hS7KwT2W+f0wRIOnFIs6uH4gudc+86+h7mad6B9qNyK9QPJvp4LVk/gugQTdK0DbV dWEHGHQ+NFtIai7L2zaGZ/OjlbtV8JB+foN6Ddq95tEDgmD2VBl5aI6wrYci7fyIBd m/pRJl/S5jizlLnkMckGDBn+Y1poE+MJjWJM/DZk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id EAC613858422 for <gcc-patches@gcc.gnu.org>; Wed, 8 Mar 2023 02:59:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAC613858422 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-cUQduKlYN8G_0RS07L4ZOQ-1; Tue, 07 Mar 2023 21:59:50 -0500 X-MC-Unique: cUQduKlYN8G_0RS07L4ZOQ-1 Received: by mail-qt1-f198.google.com with SMTP id t22-20020ac86a16000000b003bd1c0f74cfso8358019qtr.20 for <gcc-patches@gcc.gnu.org>; Tue, 07 Mar 2023 18:59:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678244389; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Xnd/2BbDG55W/MHCzORIJVqtMX8/7OdK14VlJe3Gxk8=; b=JN3qwGub2+7v2JEU75z6RWji6ZXrlOYPnQCoM9yOJwPebAt4m8gK7KAx1Cjpe70unI vZnWD3GmQ/sULZGNOUEw2LadW0+G6UKJzytq4NWVmHS8d/pZEZCe+70BErTDqZEKtC7N X+vOYq5myJSC0ocaEGZwR53MzDicj3Jflp733uggaRVXclE4CXi5UgWzxcsKx7obs4hJ b+nWDo1k/GGFYA3/JEaNkyiFGFyQnW7HqcHqMqesmiRwX9MadhZJiJiOxInU4oJpUmlw UXa0z4uCc23PgX8i6zL7IbYgxvuXlEfGc3J2lm/I7ws5pK7/aLoSFtGN4nSQSkX/yLht SBrg== X-Gm-Message-State: AO0yUKVvOmohsfmOvL0jTjXnbrb0uib5VbxMC1l8u5mF7efr2zIhQLbt sskUCsx3cZcY/Wugfp6Zde9Y+tu7AWVcg1LAVMP2s0iwn4sQXqMeJvYbUlvNax6xy8FWZP3Y3/Q m/gcbE+gblyvHJiuVFCXKFqezsuYZB0ZBaCkI5t6419xyBtv5R6AeQJ7mpZgZLwzkogUDeZtHoA == X-Received: by 2002:a05:622a:1792:b0:3bf:d9d2:487d with SMTP id s18-20020a05622a179200b003bfd9d2487dmr26770813qtk.8.1678244389489; Tue, 07 Mar 2023 18:59:49 -0800 (PST) X-Google-Smtp-Source: AK7set9SnlZwO6JE9+YiCgYp1jsdi8Bpd2sItAyPsyMbTUBt+LSgPOtW607j5ZL3Ko3aPzNIv42TRQ== X-Received: by 2002:a05:622a:1792:b0:3bf:d9d2:487d with SMTP id s18-20020a05622a179200b003bfd9d2487dmr26770790qtk.8.1678244388982; Tue, 07 Mar 2023 18:59:48 -0800 (PST) Received: from jason.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id 69-20020a370448000000b00742709bc5edsm10665605qke.5.2023.03.07.18.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 18:59:48 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Jan Hubicka <hubicka@ucw.cz> Subject: [PATCH RFC] c++: lambda mangling alias issues [PR107897] Date: Tue, 7 Mar 2023 21:59:44 -0500 Message-Id: <20230308025945.648936-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Jason Merrill via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jason Merrill <jason@redhat.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[RFC] c++: lambda mangling alias issues [PR107897]
|
|
Commit Message
Jason Merrill
March 8, 2023, 2:59 a.m. UTC
Tested x86_64-pc-linux-gnu. Does this look good, or do we want to factor the flag clearing into a symtab_node counterpart to cgraph_node::reset? -- 8< -- In 107897, by the time we are looking at the mangling clash, the alias has already been removed from the symbol table by analyze_functions, so we can't look at n->cpp_implicit_alias. So just assume that it's an alias if it's internal. In 108887 the problem is that removing the mangling alias from the symbol table confuses analyze_functions, because it ended up as first_analyzed somehow, so it becomes a dangling pointer. Fixed by clearing various flags to neutralize the alias. PR c++/107897 PR c++/108887 gcc/cp/ChangeLog: * decl2.cc (record_mangling): Improve symbol table handling. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-lambda3.C: Use -flto if supported. * g++.dg/cpp0x/lambda/lambda-mangle7.C: New test. --- gcc/cp/decl2.cc | 25 +++++-- .../g++.dg/cpp0x/lambda/lambda-mangle7.C | 70 +++++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C | 1 + 3 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C base-commit: 4f181f9c7ee3efc509d185fdfda33be9018f1611
Comments
> Tested x86_64-pc-linux-gnu. Does this look good, or do we want to factor the > flag clearing into a symtab_node counterpart to cgraph_node::reset? > > -- 8< -- > > In 107897, by the time we are looking at the mangling clash, the > alias has already been removed from the symbol table by analyze_functions, > so we can't look at n->cpp_implicit_alias. So just assume that it's an > alias if it's internal. > > In 108887 the problem is that removing the mangling alias from the symbol > table confuses analyze_functions, because it ended up as first_analyzed > somehow, so it becomes a dangling pointer. Fixed by clearing various flags > to neutralize the alias. > > PR c++/107897 > PR c++/108887 > > gcc/cp/ChangeLog: > > * decl2.cc (record_mangling): Improve symbol table handling. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-lambda3.C: Use -flto if supported. > * g++.dg/cpp0x/lambda/lambda-mangle7.C: New test. > --- > gcc/cp/decl2.cc | 25 +++++-- > .../g++.dg/cpp0x/lambda/lambda-mangle7.C | 70 +++++++++++++++++++ > gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C | 1 + > 3 files changed, 91 insertions(+), 5 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C > > diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc > index 387e24542cd..e6e58b08de4 100644 > --- a/gcc/cp/decl2.cc > +++ b/gcc/cp/decl2.cc > @@ -4742,15 +4742,30 @@ record_mangling (tree decl, bool need_warning) > = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id), > INSERT); > > - /* If this is already an alias, remove the alias, because the real > + /* If this is already an alias, cancel the alias, because the real > decl takes precedence. */ > if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot)) > - if (symtab_node *n = symtab_node::get (*slot)) > - if (n->cpp_implicit_alias) > + { > + if (symtab_node *n = symtab_node::get (*slot)) > { > - n->remove (); > - *slot = NULL_TREE; > + if (n->cpp_implicit_alias) > + { > + /* Actually removing the node isn't safe if other code is already > + holding a pointer to it, so just neutralize it. */ > + n->remove_from_same_comdat_group (); > + n->analyzed = false; > + n->definition = false; > + n->alias = false; > + n->cpp_implicit_alias = false; We have n->reset () for that which is used in similar situation when frontends overwrites extern inline function by its different offline implementation. reset doesn't call remove_from_same_comdat_group probably because it was never used on anything in comdat group. So I think it would make sense to call n->reset() here and add remove_from_same_comdat_group into that. OK with that change. Honza > + } > } > + else > + /* analyze_functions might have already removed the alias from the > + symbol table if it's internal. */ > + gcc_checking_assert (!TREE_PUBLIC (*slot)); > + > + *slot = NULL_TREE; > + } > > if (!*slot) > *slot = decl; > diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C > new file mode 100644 > index 00000000000..c7946a2be08 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C > @@ -0,0 +1,70 @@ > +// PR c++/108887 > +// { dg-do compile { target c++11 } } > + > +template <int __v> struct integral_constant { > + static constexpr int value = __v; > +}; > +using false_type = integral_constant<false>; > +template <bool, bool, typename...> struct __result_of_impl; > +template <typename _Functor, typename... _ArgTypes> > +struct __result_of_impl<false, false, _Functor, _ArgTypes...> { > + typedef decltype(0) type; > +}; > +template <typename... _ArgTypes> > +struct __invoke_result > + : __result_of_impl<false_type::value, false_type::value, _ArgTypes...> {}; > +template <typename, typename _Fn, typename... _Args> > +void __invoke_impl(_Fn __f, _Args... __args) { > + __f(__args...); > +} > +template <typename, typename _Callable, typename... _Args> > +void __invoke_r(_Callable __fn, _Args... __args) { > + using __result = __invoke_result<_Args...>; > + using __type = typename __result::type; > + __invoke_impl<__type>(__fn, __args...); > +} > +struct QString { > + QString(const char *); > +}; > +template <typename> class function; > +template <typename _Functor> struct _Base_manager { > + static _Functor _M_get_pointer(int) { __builtin_abort (); } > +}; > +template <typename, typename> class _Function_handler; > +template <typename _Res, typename _Functor, typename... _ArgTypes> > +struct _Function_handler<_Res(_ArgTypes...), _Functor> { > + using _Base = _Base_manager<_Functor>; > + static _Res _M_invoke(const int &__functor, _ArgTypes &&...__args) { > + auto __trans_tmp_1 = _Base::_M_get_pointer(__functor); > + __invoke_r<_Res>(__trans_tmp_1, __args...); > + } > +}; > +template <typename _Res, typename... _ArgTypes> > +struct function<_Res(_ArgTypes...)> { > + template <typename _Functor> > + using _Handler = _Function_handler<_Res(_ArgTypes...), _Functor>; > + template <typename _Functor> function(_Functor) { > + using _My_handler = _Handler<_Functor>; > + _M_invoker = _My_handler::_M_invoke; > + } > + using _Invoker_type = _Res (*)(const int &, _ArgTypes &&...); > + _Invoker_type _M_invoker; > +}; > +struct QRegularExpression { > + QRegularExpression(QString); > +}; > +struct AbstractAccount { > + void get(function<void(AbstractAccount *)>, > + function<void(AbstractAccount *)>); > +}; > +struct AbstractTimelineModel { > + AbstractAccount m_account; > +}; > +struct LinkPaginationTimelineModel : AbstractTimelineModel { > + void fillTimeline(); > +}; > +void LinkPaginationTimelineModel::fillTimeline() { > + [] {}; > + m_account.get([](AbstractAccount *) { static QRegularExpression re(""); }, > + [](AbstractAccount *) {}); > +} > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C > index 291e451ca1a..a7cb6c5dece 100644 > --- a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C > @@ -1,4 +1,5 @@ > // { dg-do run { target c++20 } } > +// { dg-additional-options "-flto" { target lto } } (PR107897) > > template<typename T> > concept C1 = __is_same_as(T, int) > > base-commit: 4f181f9c7ee3efc509d185fdfda33be9018f1611 > -- > 2.31.1 >
On 3/8/23 10:53, Jan Hubicka wrote: >> Tested x86_64-pc-linux-gnu. Does this look good, or do we want to factor the >> flag clearing into a symtab_node counterpart to cgraph_node::reset? >> >> -- 8< -- >> >> In 107897, by the time we are looking at the mangling clash, the >> alias has already been removed from the symbol table by analyze_functions, >> so we can't look at n->cpp_implicit_alias. So just assume that it's an >> alias if it's internal. >> >> In 108887 the problem is that removing the mangling alias from the symbol >> table confuses analyze_functions, because it ended up as first_analyzed >> somehow, so it becomes a dangling pointer. Fixed by clearing various flags >> to neutralize the alias. >> >> PR c++/107897 >> PR c++/108887 >> >> gcc/cp/ChangeLog: >> >> * decl2.cc (record_mangling): Improve symbol table handling. >> >> gcc/testsuite/ChangeLog: >> >> * g++.dg/cpp2a/concepts-lambda3.C: Use -flto if supported. >> * g++.dg/cpp0x/lambda/lambda-mangle7.C: New test. >> --- >> gcc/cp/decl2.cc | 25 +++++-- >> .../g++.dg/cpp0x/lambda/lambda-mangle7.C | 70 +++++++++++++++++++ >> gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C | 1 + >> 3 files changed, 91 insertions(+), 5 deletions(-) >> create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C >> >> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc >> index 387e24542cd..e6e58b08de4 100644 >> --- a/gcc/cp/decl2.cc >> +++ b/gcc/cp/decl2.cc >> @@ -4742,15 +4742,30 @@ record_mangling (tree decl, bool need_warning) >> = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id), >> INSERT); >> >> - /* If this is already an alias, remove the alias, because the real >> + /* If this is already an alias, cancel the alias, because the real >> decl takes precedence. */ >> if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot)) >> - if (symtab_node *n = symtab_node::get (*slot)) >> - if (n->cpp_implicit_alias) >> + { >> + if (symtab_node *n = symtab_node::get (*slot)) >> { >> - n->remove (); >> - *slot = NULL_TREE; >> + if (n->cpp_implicit_alias) >> + { >> + /* Actually removing the node isn't safe if other code is already >> + holding a pointer to it, so just neutralize it. */ >> + n->remove_from_same_comdat_group (); >> + n->analyzed = false; >> + n->definition = false; >> + n->alias = false; >> + n->cpp_implicit_alias = false; > We have n->reset () for that which is used in similar situation when > frontends overwrites extern inline function by its different offline > implementation. The problem there is that reset() is a member of cgraph_node, not symtab_node, and I need something that works for variables as well. > reset doesn't call remove_from_same_comdat_group probably because it was > never used on anything in comdat group. So I think it would make sense > to call n->reset() here and add remove_from_same_comdat_group into that. > > OK with that change. > Honza >> + } >> } >> + else >> + /* analyze_functions might have already removed the alias from the >> + symbol table if it's internal. */ >> + gcc_checking_assert (!TREE_PUBLIC (*slot)); >> + >> + *slot = NULL_TREE; >> + } >> >> if (!*slot) >> *slot = decl; >> diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C >> new file mode 100644 >> index 00000000000..c7946a2be08 >> --- /dev/null >> +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C >> @@ -0,0 +1,70 @@ >> +// PR c++/108887 >> +// { dg-do compile { target c++11 } } >> + >> +template <int __v> struct integral_constant { >> + static constexpr int value = __v; >> +}; >> +using false_type = integral_constant<false>; >> +template <bool, bool, typename...> struct __result_of_impl; >> +template <typename _Functor, typename... _ArgTypes> >> +struct __result_of_impl<false, false, _Functor, _ArgTypes...> { >> + typedef decltype(0) type; >> +}; >> +template <typename... _ArgTypes> >> +struct __invoke_result >> + : __result_of_impl<false_type::value, false_type::value, _ArgTypes...> {}; >> +template <typename, typename _Fn, typename... _Args> >> +void __invoke_impl(_Fn __f, _Args... __args) { >> + __f(__args...); >> +} >> +template <typename, typename _Callable, typename... _Args> >> +void __invoke_r(_Callable __fn, _Args... __args) { >> + using __result = __invoke_result<_Args...>; >> + using __type = typename __result::type; >> + __invoke_impl<__type>(__fn, __args...); >> +} >> +struct QString { >> + QString(const char *); >> +}; >> +template <typename> class function; >> +template <typename _Functor> struct _Base_manager { >> + static _Functor _M_get_pointer(int) { __builtin_abort (); } >> +}; >> +template <typename, typename> class _Function_handler; >> +template <typename _Res, typename _Functor, typename... _ArgTypes> >> +struct _Function_handler<_Res(_ArgTypes...), _Functor> { >> + using _Base = _Base_manager<_Functor>; >> + static _Res _M_invoke(const int &__functor, _ArgTypes &&...__args) { >> + auto __trans_tmp_1 = _Base::_M_get_pointer(__functor); >> + __invoke_r<_Res>(__trans_tmp_1, __args...); >> + } >> +}; >> +template <typename _Res, typename... _ArgTypes> >> +struct function<_Res(_ArgTypes...)> { >> + template <typename _Functor> >> + using _Handler = _Function_handler<_Res(_ArgTypes...), _Functor>; >> + template <typename _Functor> function(_Functor) { >> + using _My_handler = _Handler<_Functor>; >> + _M_invoker = _My_handler::_M_invoke; >> + } >> + using _Invoker_type = _Res (*)(const int &, _ArgTypes &&...); >> + _Invoker_type _M_invoker; >> +}; >> +struct QRegularExpression { >> + QRegularExpression(QString); >> +}; >> +struct AbstractAccount { >> + void get(function<void(AbstractAccount *)>, >> + function<void(AbstractAccount *)>); >> +}; >> +struct AbstractTimelineModel { >> + AbstractAccount m_account; >> +}; >> +struct LinkPaginationTimelineModel : AbstractTimelineModel { >> + void fillTimeline(); >> +}; >> +void LinkPaginationTimelineModel::fillTimeline() { >> + [] {}; >> + m_account.get([](AbstractAccount *) { static QRegularExpression re(""); }, >> + [](AbstractAccount *) {}); >> +} >> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C >> index 291e451ca1a..a7cb6c5dece 100644 >> --- a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C >> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C >> @@ -1,4 +1,5 @@ >> // { dg-do run { target c++20 } } >> +// { dg-additional-options "-flto" { target lto } } (PR107897) >> >> template<typename T> >> concept C1 = __is_same_as(T, int) >> >> base-commit: 4f181f9c7ee3efc509d185fdfda33be9018f1611 >> -- >> 2.31.1 >> >
On 3/8/23 11:15, Jason Merrill wrote: > On 3/8/23 10:53, Jan Hubicka wrote: >>> Tested x86_64-pc-linux-gnu. Does this look good, or do we want to >>> factor the >>> flag clearing into a symtab_node counterpart to cgraph_node::reset? >>> >>> -- 8< -- >>> >>> In 107897, by the time we are looking at the mangling clash, the >>> alias has already been removed from the symbol table by >>> analyze_functions, >>> so we can't look at n->cpp_implicit_alias. So just assume that it's an >>> alias if it's internal. >>> >>> In 108887 the problem is that removing the mangling alias from the >>> symbol >>> table confuses analyze_functions, because it ended up as first_analyzed >>> somehow, so it becomes a dangling pointer. Fixed by clearing various >>> flags >>> to neutralize the alias. >>> >>> PR c++/107897 >>> PR c++/108887 >>> >>> gcc/cp/ChangeLog: >>> >>> * decl2.cc (record_mangling): Improve symbol table handling. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * g++.dg/cpp2a/concepts-lambda3.C: Use -flto if supported. >>> * g++.dg/cpp0x/lambda/lambda-mangle7.C: New test. >>> --- >>> gcc/cp/decl2.cc | 25 +++++-- >>> .../g++.dg/cpp0x/lambda/lambda-mangle7.C | 70 +++++++++++++++++++ >>> gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C | 1 + >>> 3 files changed, 91 insertions(+), 5 deletions(-) >>> create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C >>> >>> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc >>> index 387e24542cd..e6e58b08de4 100644 >>> --- a/gcc/cp/decl2.cc >>> +++ b/gcc/cp/decl2.cc >>> @@ -4742,15 +4742,30 @@ record_mangling (tree decl, bool need_warning) >>> = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE >>> (id), >>> INSERT); >>> - /* If this is already an alias, remove the alias, because the real >>> + /* If this is already an alias, cancel the alias, because the real >>> decl takes precedence. */ >>> if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot)) >>> - if (symtab_node *n = symtab_node::get (*slot)) >>> - if (n->cpp_implicit_alias) >>> + { >>> + if (symtab_node *n = symtab_node::get (*slot)) >>> { >>> - n->remove (); >>> - *slot = NULL_TREE; >>> + if (n->cpp_implicit_alias) >>> + { >>> + /* Actually removing the node isn't safe if other code is >>> already >>> + holding a pointer to it, so just neutralize it. */ >>> + n->remove_from_same_comdat_group (); >>> + n->analyzed = false; >>> + n->definition = false; >>> + n->alias = false; >>> + n->cpp_implicit_alias = false; >> We have n->reset () for that which is used in similar situation when >> frontends overwrites extern inline function by its different offline >> implementation. > > The problem there is that reset() is a member of cgraph_node, not > symtab_node, and I need something that works for variables as well. > >> reset doesn't call remove_from_same_comdat_group probably because it was >> never used on anything in comdat group. So I think it would make sense >> to call n->reset() here and add remove_from_same_comdat_group into that. How about moving it to symtab_node and using dyn_cast for the cgraph bits, like this:
On 3/8/23 11:54, Jason Merrill wrote: > On 3/8/23 11:15, Jason Merrill wrote: >> On 3/8/23 10:53, Jan Hubicka wrote: >>>> Tested x86_64-pc-linux-gnu. Does this look good, or do we want to >>>> factor the >>>> flag clearing into a symtab_node counterpart to cgraph_node::reset? >>>> >>>> -- 8< -- >>>> >>>> In 107897, by the time we are looking at the mangling clash, the >>>> alias has already been removed from the symbol table by >>>> analyze_functions, >>>> so we can't look at n->cpp_implicit_alias. So just assume that it's an >>>> alias if it's internal. >>>> >>>> In 108887 the problem is that removing the mangling alias from the >>>> symbol >>>> table confuses analyze_functions, because it ended up as first_analyzed >>>> somehow, so it becomes a dangling pointer. Fixed by clearing >>>> various flags >>>> to neutralize the alias. >>>> >>>> PR c++/107897 >>>> PR c++/108887 >>>> >>>> gcc/cp/ChangeLog: >>>> >>>> * decl2.cc (record_mangling): Improve symbol table handling. >>>> >>>> gcc/testsuite/ChangeLog: >>>> >>>> * g++.dg/cpp2a/concepts-lambda3.C: Use -flto if supported. >>>> * g++.dg/cpp0x/lambda/lambda-mangle7.C: New test. >>>> --- >>>> gcc/cp/decl2.cc | 25 +++++-- >>>> .../g++.dg/cpp0x/lambda/lambda-mangle7.C | 70 >>>> +++++++++++++++++++ >>>> gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C | 1 + >>>> 3 files changed, 91 insertions(+), 5 deletions(-) >>>> create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C >>>> >>>> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc >>>> index 387e24542cd..e6e58b08de4 100644 >>>> --- a/gcc/cp/decl2.cc >>>> +++ b/gcc/cp/decl2.cc >>>> @@ -4742,15 +4742,30 @@ record_mangling (tree decl, bool need_warning) >>>> = mangled_decls->find_slot_with_hash (id, >>>> IDENTIFIER_HASH_VALUE (id), >>>> INSERT); >>>> - /* If this is already an alias, remove the alias, because the real >>>> + /* If this is already an alias, cancel the alias, because the real >>>> decl takes precedence. */ >>>> if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot)) >>>> - if (symtab_node *n = symtab_node::get (*slot)) >>>> - if (n->cpp_implicit_alias) >>>> + { >>>> + if (symtab_node *n = symtab_node::get (*slot)) >>>> { >>>> - n->remove (); >>>> - *slot = NULL_TREE; >>>> + if (n->cpp_implicit_alias) >>>> + { >>>> + /* Actually removing the node isn't safe if other code is >>>> already >>>> + holding a pointer to it, so just neutralize it. */ >>>> + n->remove_from_same_comdat_group (); >>>> + n->analyzed = false; >>>> + n->definition = false; >>>> + n->alias = false; >>>> + n->cpp_implicit_alias = false; >>> We have n->reset () for that which is used in similar situation when >>> frontends overwrites extern inline function by its different offline >>> implementation. >> >> The problem there is that reset() is a member of cgraph_node, not >> symtab_node, and I need something that works for variables as well. >> >>> reset doesn't call remove_from_same_comdat_group probably because it was >>> never used on anything in comdat group. So I think it would make sense >>> to call n->reset() here and add remove_from_same_comdat_group into that. > > How about moving it to symtab_node and using dyn_cast for the cgraph > bits, like this: Ping? (Patch in attachment in earlier message)
On 3/14/23 11:16, Jason Merrill wrote: > On 3/8/23 11:54, Jason Merrill wrote: >> On 3/8/23 11:15, Jason Merrill wrote: >>> On 3/8/23 10:53, Jan Hubicka wrote: >>>>> Tested x86_64-pc-linux-gnu. Does this look good, or do we want to >>>>> factor the >>>>> flag clearing into a symtab_node counterpart to cgraph_node::reset? >>>>> >>>>> -- 8< -- >>>>> >>>>> In 107897, by the time we are looking at the mangling clash, the >>>>> alias has already been removed from the symbol table by >>>>> analyze_functions, >>>>> so we can't look at n->cpp_implicit_alias. So just assume that >>>>> it's an >>>>> alias if it's internal. >>>>> >>>>> In 108887 the problem is that removing the mangling alias from the >>>>> symbol >>>>> table confuses analyze_functions, because it ended up as >>>>> first_analyzed >>>>> somehow, so it becomes a dangling pointer. Fixed by clearing >>>>> various flags >>>>> to neutralize the alias. >>>>> >>>>> PR c++/107897 >>>>> PR c++/108887 >>>>> >>>>> gcc/cp/ChangeLog: >>>>> >>>>> * decl2.cc (record_mangling): Improve symbol table handling. >>>>> >>>>> gcc/testsuite/ChangeLog: >>>>> >>>>> * g++.dg/cpp2a/concepts-lambda3.C: Use -flto if supported. >>>>> * g++.dg/cpp0x/lambda/lambda-mangle7.C: New test. >>>>> --- >>>>> gcc/cp/decl2.cc | 25 +++++-- >>>>> .../g++.dg/cpp0x/lambda/lambda-mangle7.C | 70 >>>>> +++++++++++++++++++ >>>>> gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C | 1 + >>>>> 3 files changed, 91 insertions(+), 5 deletions(-) >>>>> create mode 100644 >>>>> gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C >>>>> >>>>> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc >>>>> index 387e24542cd..e6e58b08de4 100644 >>>>> --- a/gcc/cp/decl2.cc >>>>> +++ b/gcc/cp/decl2.cc >>>>> @@ -4742,15 +4742,30 @@ record_mangling (tree decl, bool need_warning) >>>>> = mangled_decls->find_slot_with_hash (id, >>>>> IDENTIFIER_HASH_VALUE (id), >>>>> INSERT); >>>>> - /* If this is already an alias, remove the alias, because the real >>>>> + /* If this is already an alias, cancel the alias, because the real >>>>> decl takes precedence. */ >>>>> if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot)) >>>>> - if (symtab_node *n = symtab_node::get (*slot)) >>>>> - if (n->cpp_implicit_alias) >>>>> + { >>>>> + if (symtab_node *n = symtab_node::get (*slot)) >>>>> { >>>>> - n->remove (); >>>>> - *slot = NULL_TREE; >>>>> + if (n->cpp_implicit_alias) >>>>> + { >>>>> + /* Actually removing the node isn't safe if other code >>>>> is already >>>>> + holding a pointer to it, so just neutralize it. */ >>>>> + n->remove_from_same_comdat_group (); >>>>> + n->analyzed = false; >>>>> + n->definition = false; >>>>> + n->alias = false; >>>>> + n->cpp_implicit_alias = false; >>>> We have n->reset () for that which is used in similar situation when >>>> frontends overwrites extern inline function by its different offline >>>> implementation. >>> >>> The problem there is that reset() is a member of cgraph_node, not >>> symtab_node, and I need something that works for variables as well. >>> >>>> reset doesn't call remove_from_same_comdat_group probably because it >>>> was >>>> never used on anything in comdat group. So I think it would make sense >>>> to call n->reset() here and add remove_from_same_comdat_group into >>>> that. >> >> How about moving it to symtab_node and using dyn_cast for the cgraph >> bits, like this: > > Ping? (Patch in attachment in earlier message) >
Hello, On Wed, Mar 08 2023, Jason Merrill via Gcc-patches wrote: > On 3/8/23 11:15, Jason Merrill wrote: >> On 3/8/23 10:53, Jan Hubicka wrote: [...] >>> We have n->reset () for that which is used in similar situation when >>> frontends overwrites extern inline function by its different offline >>> implementation. >> >> The problem there is that reset() is a member of cgraph_node, not >> symtab_node, and I need something that works for variables as well. >> >>> reset doesn't call remove_from_same_comdat_group probably because it was >>> never used on anything in comdat group. So I think it would make sense >>> to call n->reset() here and add remove_from_same_comdat_group into that. > > How about moving it to symtab_node and using dyn_cast for the cgraph > bits, like this: > From 1d869ceb04573727e59be6518903133c8654069a Mon Sep 17 00:00:00 2001 > From: Jason Merrill <jason@redhat.com> > Date: Mon, 6 Mar 2023 15:33:45 -0500 > Subject: [PATCH] c++: lambda mangling alias issues [PR107897] > To: gcc-patches@gcc.gnu.org > > In 107897, by the time we are looking at the mangling clash, the > alias has already been removed from the symbol table by analyze_functions, > so we can't look at n->cpp_implicit_alias. So just assume that it's an > alias if it's internal. > > In 108887 the problem is that removing the mangling alias from the symbol > table confuses analyze_functions, because it ended up as first_analyzed > somehow, so it becomes a dangling pointer. Fixed by clearing various flags > to neutralize the alias. > > PR c++/107897 > PR c++/108887 > > gcc/ChangeLog: > > * cgraph.h: Move reset() from cgraph_node to symtab_node. > * cgraphunit.cc (symtab_node::reset): Adjust. > > gcc/cp/ChangeLog: > > * decl2.cc (record_mangling): Use symtab_node::reset. The patch is OK. Thanks, Martin
> > How about moving it to symtab_node and using dyn_cast for the cgraph bits, > like this: > From 1d869ceb04573727e59be6518903133c8654069a Mon Sep 17 00:00:00 2001 > From: Jason Merrill <jason@redhat.com> > Date: Mon, 6 Mar 2023 15:33:45 -0500 > Subject: [PATCH] c++: lambda mangling alias issues [PR107897] > To: gcc-patches@gcc.gnu.org > > In 107897, by the time we are looking at the mangling clash, the > alias has already been removed from the symbol table by analyze_functions, > so we can't look at n->cpp_implicit_alias. So just assume that it's an > alias if it's internal. > > In 108887 the problem is that removing the mangling alias from the symbol > table confuses analyze_functions, because it ended up as first_analyzed > somehow, so it becomes a dangling pointer. Fixed by clearing various flags > to neutralize the alias. > > PR c++/107897 > PR c++/108887 > > gcc/ChangeLog: > > * cgraph.h: Move reset() from cgraph_node to symtab_node. > * cgraphunit.cc (symtab_node::reset): Adjust. > > gcc/cp/ChangeLog: > > * decl2.cc (record_mangling): Use symtab_node::reset. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-lambda3.C: Use -flto if supported. > * g++.dg/cpp0x/lambda/lambda-mangle7.C: New test. OK and I apologize for the delay (my travels were more busy than I hoped) Honza
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 387e24542cd..e6e58b08de4 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -4742,15 +4742,30 @@ record_mangling (tree decl, bool need_warning) = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id), INSERT); - /* If this is already an alias, remove the alias, because the real + /* If this is already an alias, cancel the alias, because the real decl takes precedence. */ if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot)) - if (symtab_node *n = symtab_node::get (*slot)) - if (n->cpp_implicit_alias) + { + if (symtab_node *n = symtab_node::get (*slot)) { - n->remove (); - *slot = NULL_TREE; + if (n->cpp_implicit_alias) + { + /* Actually removing the node isn't safe if other code is already + holding a pointer to it, so just neutralize it. */ + n->remove_from_same_comdat_group (); + n->analyzed = false; + n->definition = false; + n->alias = false; + n->cpp_implicit_alias = false; + } } + else + /* analyze_functions might have already removed the alias from the + symbol table if it's internal. */ + gcc_checking_assert (!TREE_PUBLIC (*slot)); + + *slot = NULL_TREE; + } if (!*slot) *slot = decl; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C new file mode 100644 index 00000000000..c7946a2be08 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle7.C @@ -0,0 +1,70 @@ +// PR c++/108887 +// { dg-do compile { target c++11 } } + +template <int __v> struct integral_constant { + static constexpr int value = __v; +}; +using false_type = integral_constant<false>; +template <bool, bool, typename...> struct __result_of_impl; +template <typename _Functor, typename... _ArgTypes> +struct __result_of_impl<false, false, _Functor, _ArgTypes...> { + typedef decltype(0) type; +}; +template <typename... _ArgTypes> +struct __invoke_result + : __result_of_impl<false_type::value, false_type::value, _ArgTypes...> {}; +template <typename, typename _Fn, typename... _Args> +void __invoke_impl(_Fn __f, _Args... __args) { + __f(__args...); +} +template <typename, typename _Callable, typename... _Args> +void __invoke_r(_Callable __fn, _Args... __args) { + using __result = __invoke_result<_Args...>; + using __type = typename __result::type; + __invoke_impl<__type>(__fn, __args...); +} +struct QString { + QString(const char *); +}; +template <typename> class function; +template <typename _Functor> struct _Base_manager { + static _Functor _M_get_pointer(int) { __builtin_abort (); } +}; +template <typename, typename> class _Function_handler; +template <typename _Res, typename _Functor, typename... _ArgTypes> +struct _Function_handler<_Res(_ArgTypes...), _Functor> { + using _Base = _Base_manager<_Functor>; + static _Res _M_invoke(const int &__functor, _ArgTypes &&...__args) { + auto __trans_tmp_1 = _Base::_M_get_pointer(__functor); + __invoke_r<_Res>(__trans_tmp_1, __args...); + } +}; +template <typename _Res, typename... _ArgTypes> +struct function<_Res(_ArgTypes...)> { + template <typename _Functor> + using _Handler = _Function_handler<_Res(_ArgTypes...), _Functor>; + template <typename _Functor> function(_Functor) { + using _My_handler = _Handler<_Functor>; + _M_invoker = _My_handler::_M_invoke; + } + using _Invoker_type = _Res (*)(const int &, _ArgTypes &&...); + _Invoker_type _M_invoker; +}; +struct QRegularExpression { + QRegularExpression(QString); +}; +struct AbstractAccount { + void get(function<void(AbstractAccount *)>, + function<void(AbstractAccount *)>); +}; +struct AbstractTimelineModel { + AbstractAccount m_account; +}; +struct LinkPaginationTimelineModel : AbstractTimelineModel { + void fillTimeline(); +}; +void LinkPaginationTimelineModel::fillTimeline() { + [] {}; + m_account.get([](AbstractAccount *) { static QRegularExpression re(""); }, + [](AbstractAccount *) {}); +} diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C index 291e451ca1a..a7cb6c5dece 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda3.C @@ -1,4 +1,5 @@ // { dg-do run { target c++20 } } +// { dg-additional-options "-flto" { target lto } } (PR107897) template<typename T> concept C1 = __is_same_as(T, int)