From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 45C973857400 for ; Wed, 8 Mar 2023 16:15:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45C973857400 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678292142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cVgqbnpDsBygRWJT4KT/QmeUlQ+N6P8R7rzyIOE109Y=; b=I1yLR9ZeJbC9asMzMraq/kV6mz+UOnG30KqowXkt6f+EgVYJljd4t91Vc/mt5MR30du0+t OAZ5v4E29CHwz0JUPim2d0oF/DJ1AlQ4LZub6yV0Gb2MA5xOcQRQe8YL1036MEYFBd0YLW At85fLA4+JjX8BzIZQUeUEjHZoiy7qI= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-wI-2dzv2Moy2mowYw3xnKw-1; Wed, 08 Mar 2023 11:15:41 -0500 X-MC-Unique: wI-2dzv2Moy2mowYw3xnKw-1 Received: by mail-qv1-f69.google.com with SMTP id y3-20020a0cec03000000b0056ee5b123bbso9594345qvo.7 for ; Wed, 08 Mar 2023 08:15:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678292141; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cVgqbnpDsBygRWJT4KT/QmeUlQ+N6P8R7rzyIOE109Y=; b=k5AdZgG0d/yXXx1Hg0O3YxwQhPaz1BnzGA2crmK/L6wFeAIzgCkiyXLt5XAxVrM3bP /HtcWkG5jkyje5Ua4sObgHvdBtYAJufbDaZivLKuEyVJlZZkByfpsZKRnz+Vit2Sx8bU ZvBthvuD5YB9ngFzYIX1ndj9pOaUuNNQw99U87usJ4Vim3wXUqzZDoPNTeNe1tvlzAcu XIY1geAEJt3EzBngKx9U+5DFTwkJMejlIWnDn4/eRbf5UhPaJAAMGoAFJ8AecZ1gd7sI N8fUaQGOtxcoB+3EfamIYiiRER10rx3mC4CJdje6LzBTiluVQLox+blmPPMViMi8GemM xPKw== X-Gm-Message-State: AO0yUKWaKTtovIAh8HD3nQ1Ba97M0TOH4HnrjKlStmciakh1IP3JkwTJ kFXx1ReE2vRq3rJqXtundqvWL0hwiJboc756kBNKFYzxYCQbsZo0zLh/rsk2jJXJRfhTD7H/qWA TxN9rXBJcSk+VLx53Sw== X-Received: by 2002:a05:622a:5d2:b0:3bf:db54:b622 with SMTP id d18-20020a05622a05d200b003bfdb54b622mr3117092qtb.30.1678292141151; Wed, 08 Mar 2023 08:15:41 -0800 (PST) X-Google-Smtp-Source: AK7set86+gUVDA8uor3F/v9kTzV9mXUKU4N+bVzAuHz6jQRov7LTa1+s4lX6ZqK/ORiXEJXfGvggyA== X-Received: by 2002:a05:622a:5d2:b0:3bf:db54:b622 with SMTP id d18-20020a05622a05d200b003bfdb54b622mr3117052qtb.30.1678292140765; Wed, 08 Mar 2023 08:15:40 -0800 (PST) Received: from [192.168.1.108] (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 t190-20020a3746c7000000b0074235745fdasm11552594qka.58.2023.03.08.08.15.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Mar 2023 08:15:39 -0800 (PST) Message-ID: <4d1a02da-b1b5-1cdb-c435-ba0299d8bd9b@redhat.com> Date: Wed, 8 Mar 2023 11:15:38 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH RFC] c++: lambda mangling alias issues [PR107897] To: Jan Hubicka Cc: gcc-patches@gcc.gnu.org References: <20230308025945.648936-1-jason@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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,NICE_REPLY_A,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 List-Id: 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 struct integral_constant { >> + static constexpr int value = __v; >> +}; >> +using false_type = integral_constant; >> +template struct __result_of_impl; >> +template >> +struct __result_of_impl { >> + typedef decltype(0) type; >> +}; >> +template >> +struct __invoke_result >> + : __result_of_impl {}; >> +template >> +void __invoke_impl(_Fn __f, _Args... __args) { >> + __f(__args...); >> +} >> +template >> +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 class function; >> +template struct _Base_manager { >> + static _Functor _M_get_pointer(int) { __builtin_abort (); } >> +}; >> +template class _Function_handler; >> +template >> +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 >> +struct function<_Res(_ArgTypes...)> { >> + template >> + using _Handler = _Function_handler<_Res(_ArgTypes...), _Functor>; >> + template 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, >> + function); >> +}; >> +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 >> concept C1 = __is_same_as(T, int) >> >> base-commit: 4f181f9c7ee3efc509d185fdfda33be9018f1611 >> -- >> 2.31.1 >> >