From patchwork Wed Mar 8 02:59:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 65983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp102498wrd; Tue, 7 Mar 2023 19:00:37 -0800 (PST) X-Google-Smtp-Source: AK7set8HbhqOIM+8QWQnRUwQgbYjnCzXxDFdp991QCymW1msFzwrV+1naHA28qP9Vh8d36lS4X+3 X-Received: by 2002:a17:907:b60a:b0:8e9:afb1:65c6 with SMTP id vl10-20020a170907b60a00b008e9afb165c6mr22893108ejc.13.1678244437553; Tue, 07 Mar 2023 19:00:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678244437; cv=none; d=google.com; s=arc-20160816; b=FCKWoQMtpi4d0fAc5HtZx6QhzrWN+doWVuTAFglHoQz751d2E1Th4+AF4C+7AJfvjA 527va46OW5a1uSz8wHxzVDrAvLMzoRo8Di+0ItgxxqkqFVo+F80IJaGWfS/cx5jcm37q fAws61MXMGWg0ZDg0IV7cUUij8AI9LXT2ePUlSxvG/oCOvPntLv0rmPaC2Wavmfm48NL 5jxoM6qym04kHPbIf+Ts/0myK5QRPk3HawOniX9DceeefX7dPPdZ+DCyD5seeMPh1MzK Y7gB2oj1oYFu8NaOxx3k75ZVzNEJChpvNXQQOepq4jiubP5SivhpDnImT66Y6s3gfd6Y BUKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Xnd/2BbDG55W/MHCzORIJVqtMX8/7OdK14VlJe3Gxk8=; b=VuvI/5fNXxfEiM7IJRb6tEWyCuMJwk3S4e4LNXLz8M8Ezp6vgv0NcUx8rpo1LN5Uqk cY25G/TQbQiLR37ZMGEqtATfFsLaKUUx9zXVfihpk4JAtke7uB1FwqEbYaAMcU894RrS 0qArOBXGvM1NOhy7tVbRCAiMCuTLj8RSypfB1t5BimYtqtyPziin3pPnjkAaeOWLiKNc BI1k7FnXw6JyJfWeeeBQg5tzPjEaJv1JKvYQdm6RN3CYwcyRB3pgzzdf5xr61uRuHiQT eJ9yUnXm9J9RRTeNL52nc8FT/Ug4vEs/JrNF6Heqw4etXT2I0fWeI9ngqWlCYhjcENfW NJlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="L+4W/0mW"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s11-20020a170906354b00b008e457e36ac9si2724306eja.777.2023.03.07.19.00.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 19:00:37 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="L+4W/0mW"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8876A3851ABF for ; Wed, 8 Mar 2023 03:00:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8876A3851ABF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678244436; 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=L+4W/0mWdYev92FwcUYr49esh09QDJYVBkCXSt9xBh/10A95ncFg59l4woZ6GOyut shELe/Ify2EO2qoofC+3dNF1cTzcOWA4EIrngq9aDnvKsZMZtXJ6dSVdgF//iGdeEg qUpsfeykmVLWAl/4O/TRsBC/pZBKzZy4H20YUpDQ= 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 ; 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 ; 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-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 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759766839453251180?= X-GMAIL-MSGID: =?utf-8?q?1759766839453251180?= 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 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 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)