From patchwork Fri Jan 12 12:45:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 187724 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp146816dyc; Fri, 12 Jan 2024 04:46:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQTJTBzuWSQpJIJtINQYXp7B52zFZKI/Rn+DVJpdWli5gftKzWGsogg6nAp3ZIIMPfujeU X-Received: by 2002:a0c:da88:0:b0:680:cd23:83f3 with SMTP id z8-20020a0cda88000000b00680cd2383f3mr1004174qvj.13.1705063601605; Fri, 12 Jan 2024 04:46:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705063601; cv=pass; d=google.com; s=arc-20160816; b=j8ivvcZBOEcMYTHKZheg8MDAUSQZvsa4d4cgSqwdQAq7IHAuOjN7xjyUc1k6bOu1+L 3iIUusCdvaXHby83xKmKhQOOZ6apnQ0GCReCueD3rx0801GWMowcia6PVyHfpUuCVyDh Ldq+F0z6uXvUZEVSPhC3fCd5S6+bQGF5D5V10HpW8fqMwOzzhRF/jVbuubiEwDTEym17 SFcAwTNschm+8YxpqE/mfYezB7PIwk102tbt7uC6KFtlWsNTQ8WmqWhACJET/fAK1I0c gjUMibFIUIUeTi7NnNbtuR8Wg9MW9BW0kYg11yGi3UWnse402JNyHt8MPdleL4VixG4q iR7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=uNDnWoDuP+z4/g/tL2fJ42F5itxvjLKPEp9FCXuWaIs=; fh=JMpZv2J29RGu8tsbhleL0qutPMO7pMr4Aamzj6OhL5I=; b=QH2Rx4d7+A6kLEGoTg7sVUEMgCI60nHoTBu63IOxeLRscymmguvRSZQXZbFYrPwZTp aWajpqvsLf93xGrqYjswRCukQrxw2IWZobzocKjqsmKZWoRcu8oHKbIPLXgbTd4mA3sX Jj1qj/t+uYQuRfoexddI/QZemasyCKnnc5TSugY9QvYNwnJ4bYrHaEQLFxTNuMZ0MLH2 0kLSqgil2ZSrI/r3js9Z1AVljhX0PhcV/o2deDrNvRNMW9RVNFRGKJFxjsF5YHV8AVwk 6LbveZqqITr6VnhFh1mdHwARBmlP9DS7f//rCNUFjxBQ2ppo/3KcmTuw849rSGbWjr6/ SU5g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="UJL7r/E6"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z16-20020a0cf010000000b0067fc6e06530si2741535qvk.188.2024.01.12.04.46.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 04:46:41 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="UJL7r/E6"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 469963858015 for ; Fri, 12 Jan 2024 12:46:41 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 993113858D37 for ; Fri, 12 Jan 2024 12:45:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 993113858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 993113858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705063554; cv=none; b=savnOooSP89drnXdrTFvzGXpa7eTk0wVmUmn9WbPHwvyujvwgBKgKT6Dc7iFa+qFlciTL03ulWXdsqUsCDbpjWHv/Lu5p+SGHL2qK6GOhutgxefyimykT8tK7hfyoCfprRd6SGRVE6OsxShF4ha+8HT6JAnoD1diZtAzKNhuny8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705063554; c=relaxed/simple; bh=uRImCGo2dwqFXA7cxXCx+wP3UDNonkB1WvdS0sKKmD8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=x1+xuXzNMQItOcAL0Cf0QYnM/kaH7hTzMwUeVc6fQ6n/+JAO3KRn7b1dIkEpnT/D810wegdxyJcaIJnQ9xabTTta/v8gWYO4PsFhi8pkeHta5x/ZDEk2pafD5zeDmAI6Dg0HOFcY6Zh66Aohc7fEqgOivrxg8GVocPs06tn00DI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705063552; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=uNDnWoDuP+z4/g/tL2fJ42F5itxvjLKPEp9FCXuWaIs=; b=UJL7r/E6bUrjiLnSpeb71HTEXmO8Jdh0p38bNjOvHtJzYeCHro/fk0h7DN/LH0OIiB3rzy 2JfaY/hT81IYzIgFF8xlFknRDHqHgZMw1RbUFMwlyojjgc8VSn5MTGzE3YL0RshTgxrPHr BGbuvTO6ke6EUKRrSgdrQl7fmCdPjhA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-PP_VSBG1Nte9jg4Vwjjbvw-1; Fri, 12 Jan 2024 07:45:50 -0500 X-MC-Unique: PP_VSBG1Nte9jg4Vwjjbvw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 92809887188; Fri, 12 Jan 2024 12:45:50 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5613FC25AC8; Fri, 12 Jan 2024 12:45:50 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 40CCjlAX3314709 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 12 Jan 2024 13:45:48 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40CCjkiL3314708; Fri, 12 Jan 2024 13:45:46 +0100 Date: Fri, 12 Jan 2024 13:45:46 +0100 From: Jakub Jelinek To: Jason Merrill , waffl3x Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, demangle: Implement https://github.com/itanium-cxx-abi/cxx-abi/issues/148 non-proposal Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787888770733053335 X-GMAIL-MSGID: 1787888770733053335 Hi! The following patch attempts to implement what apparently clang++ implemented for explicit object member function mangling, but nobody actually proposed in patch form in https://github.com/itanium-cxx-abi/cxx-abi/issues/148 Ok for trunk if it passes full bootstrap/regtest? So far just tested on the new testcases. 2024-01-12 Jakub Jelinek gcc/cp/ * mangle.cc (write_nested_name): Mangle explicit object member functions with H as per https://github.com/itanium-cxx-abi/cxx-abi/issues/148 non-proposal. gcc/testsuite/ * g++.dg/abi/mangle79.C: New test. include/ * demangle.h (enum demangle_component_type): Add DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION. libiberty/ * cp-demangle.c (FNQUAL_COMPONENT_CASE): Add case for DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION. (d_dump): Handle DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION. (d_nested_name): Parse H after N in nested name. (d_count_templates_scopes): Handle DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION. (d_print_mod): Likewise. (d_print_function_type): Likewise. * testsuite/demangle-expected: Add tests for explicit object member functions. Jakub --- gcc/cp/mangle.cc.jj 2024-01-12 10:07:31.248231747 +0100 +++ gcc/cp/mangle.cc 2024-01-12 11:37:35.790915463 +0100 @@ -1247,6 +1247,8 @@ write_nested_name (const tree decl) write_char ('R'); } } + else if (DECL_XOBJ_MEMBER_FUNCTION_P (decl)) + write_char ('H'); /* Is this a template instance? */ if (tree info = maybe_template_info (decl)) --- gcc/testsuite/g++.dg/abi/mangle79.C.jj 2024-01-12 13:18:20.782917924 +0100 +++ gcc/testsuite/g++.dg/abi/mangle79.C 2024-01-12 13:26:01.297433970 +0100 @@ -0,0 +1,61 @@ +// { dg-do compile { target c++11 } } +// { dg-options "" } + +struct S { + static void foo (S); + void foo (this S); // { dg-warning "explicit object member function only available with" "" { target c++20_down } } + template + static void bar (S, T); + template + void bar (this S, T); // { dg-warning "explicit object member function only available with" "" { target c++20_down } } + static void baz (const S &); + void baz (this const S &); // { dg-warning "explicit object member function only available with" "" { target c++20_down } } +}; + +void +S::foo (S) +{ +} + +void +S::foo (this S) // { dg-warning "explicit object member function only available with" "" { target c++20_down } } +{ +} + +template +void +S::bar (S, T) +{ +} + +template +void +S::bar (this S, T) // { dg-warning "explicit object member function only available with" "" { target c++20_down } } +{ +} + +void +S::baz (const S &) +{ +} + +void +S::baz (this const S &) // { dg-warning "explicit object member function only available with" "" { target c++20_down } } +{ +} + +void +qux (S *p) +{ + S::foo (*p); + p->foo (); + S::bar <5> (*p, 0); + p->bar <5> (0); +} + +// { dg-final { scan-assembler "_ZN1S3fooES_" } } +// { dg-final { scan-assembler "_ZNH1S3fooES_" } } +// { dg-final { scan-assembler "_ZN1S3barILi5EiEEvS_T0_" } } +// { dg-final { scan-assembler "_ZNH1S3barILi5EiEEvS_T0_" } } +// { dg-final { scan-assembler "_ZN1S3bazERKS_" } } +// { dg-final { scan-assembler "_ZNH1S3bazERKS_" } } --- include/demangle.h.jj 2024-01-03 12:07:25.330409694 +0100 +++ include/demangle.h 2024-01-12 11:43:27.543915280 +0100 @@ -314,6 +314,8 @@ enum demangle_component_type /* C++11: An rvalue reference modifying a member function. The one subtree is the type which is being referenced. */ DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS, + /* C++23: A member function with explict object parameter. */ + DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION, /* A vendor qualifier. The left subtree is the type which is being qualified, and the right subtree is the name of the qualifier. */ --- libiberty/cp-demangle.c.jj 2024-01-03 12:07:48.498085118 +0100 +++ libiberty/cp-demangle.c 2024-01-12 13:06:04.526281733 +0100 @@ -581,6 +581,7 @@ static char *d_demangle (const char *, i case DEMANGLE_COMPONENT_CONST_THIS: \ case DEMANGLE_COMPONENT_REFERENCE_THIS: \ case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: \ + case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: \ case DEMANGLE_COMPONENT_TRANSACTION_SAFE: \ case DEMANGLE_COMPONENT_NOEXCEPT: \ case DEMANGLE_COMPONENT_THROW_SPEC @@ -749,6 +750,9 @@ d_dump (struct demangle_component *dc, i case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: printf ("rvalue reference this\n"); break; + case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: + printf ("explicit object parameter\n"); + break; case DEMANGLE_COMPONENT_TRANSACTION_SAFE: printf ("transaction_safe this\n"); break; @@ -1547,6 +1551,8 @@ d_name (struct d_info *di, int substable /* ::= N [] [] E ::= N [] [] E + ::= N H E + ::= N H E */ static struct demangle_component * @@ -1559,13 +1565,24 @@ d_nested_name (struct d_info *di) if (! d_check_char (di, 'N')) return NULL; - pret = d_cv_qualifiers (di, &ret, 1); - if (pret == NULL) - return NULL; + if (d_peek_char (di) == 'H') + { + d_advance (di, 1); + di->expansion += sizeof "this"; + pret = &ret; + rqual = d_make_comp (di, DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION, + NULL, NULL); + } + else + { + pret = d_cv_qualifiers (di, &ret, 1); + if (pret == NULL) + return NULL; - /* Parse the ref-qualifier now and then attach it - once we have something to attach it to. */ - rqual = d_ref_qualifier (di, NULL); + /* Parse the ref-qualifier now and then attach it + once we have something to attach it to. */ + rqual = d_ref_qualifier (di, NULL); + } *pret = d_prefix (di, 1); if (*pret == NULL) @@ -4427,6 +4444,7 @@ d_count_templates_scopes (struct d_print case DEMANGLE_COMPONENT_CONST_THIS: case DEMANGLE_COMPONENT_REFERENCE_THIS: case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: + case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: case DEMANGLE_COMPONENT_TRANSACTION_SAFE: case DEMANGLE_COMPONENT_NOEXCEPT: case DEMANGLE_COMPONENT_THROW_SPEC: @@ -6521,6 +6539,8 @@ d_print_mod (struct d_print_info *dpi, i case DEMANGLE_COMPONENT_RVALUE_REFERENCE: d_append_string (dpi, "&&"); return; + case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: + return; case DEMANGLE_COMPONENT_COMPLEX: d_append_string (dpi, " _Complex"); return; @@ -6559,11 +6579,13 @@ d_print_function_type (struct d_print_in { int need_paren; int need_space; + int xobj_memfn; struct d_print_mod *p; struct d_print_mod *hold_modifiers; need_paren = 0; need_space = 0; + xobj_memfn = 0; for (p = mods; p != NULL; p = p->next) { if (p->printed) @@ -6586,7 +6608,8 @@ d_print_function_type (struct d_print_in need_space = 1; need_paren = 1; break; - FNQUAL_COMPONENT_CASE: + case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: + xobj_memfn = 1; break; default: break; @@ -6617,6 +6640,8 @@ d_print_function_type (struct d_print_in d_append_char (dpi, ')'); d_append_char (dpi, '('); + if (xobj_memfn) + d_append_string (dpi, "this "); if (d_right (dc) != NULL) d_print_comp (dpi, options, d_right (dc)); --- libiberty/testsuite/demangle-expected.jj 2023-12-03 17:44:57.266453553 +0100 +++ libiberty/testsuite/demangle-expected 2024-01-12 12:22:56.647587418 +0100 @@ -1700,3 +1700,12 @@ void f() requires C # requires after () _Z1fIiEvvQ1CIT_E void f() requires C + +_ZNH1S3fooES_ +S::foo(this S) + +_ZNH1S3barILi5EiEEvS_T0_ +void S::bar<5, int>(this S, int) + +_ZNH1S3bazERKS_ +S::baz(this S const&)