From patchwork Tue Apr 7 07:06:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 132736 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id E26CE4BA2E05 for ; Tue, 7 Apr 2026 07:07:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E26CE4BA2E05 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DsmiX/iM 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 ESMTP id 217E34BA2E05 for ; Tue, 7 Apr 2026 07:06:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 217E34BA2E05 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 217E34BA2E05 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775545605; cv=none; b=PGPCSUhNdLse+3c1WYBjA0QSkYDOYjx1+yviqhKkqpqeyFQmrlnDTe/E1VNXA5Ga2wC2Hznapx2wRYLL8L4qWiXOxK4YNQZ90pJFm11Ii5ephpljTV8dHF83HJgX3ncfdueOPG41Vfu5Y+LCGGeuv9V42nEKzby9RT5stt2JM18= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775545605; c=relaxed/simple; bh=+AKS6QzsYDYdbRdRay3v8lID0TOi9w/mbhvlVZHhp34=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=vXWDlkbL6/G/6BOkNjzHHNfP54tnRRacZ/hj+537APwiWmqwWq89jCDsdg/U+iMfVzNlrhGEyoxChxdaIkLjb3eJ2fdlV91Z4vLYS00O6zRsjAD5/gvxp7MgJoqbmIJ3rU9FNyRnjdrd07mwjvrLGOl33qKG4BPbdI1uCXtX6gA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 217E34BA2E05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775545604; 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:in-reply-to:in-reply-to: references:references; bh=+BVX6eyxiAEyd2BkunJGZ7aWhbN4EuqZDVc6S4kDTGg=; b=DsmiX/iMW7kANTHoF2orIZB2YgxU42+UiWU8+sCg2ZZhj9MmFsK6PAza64BhOTDgjnnSqQ JKpiJWZZTDj4r7mftDQyaOj8aXpIY+xjt35xaUoDSycvDdHMp8Rs5I9VVlUQVTbA1vzsX4 dWfcrACqMYZa3p+yq0AR86guyz42OOY= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-381-aZ2Ld6UINqSbj1LMJpwL0Q-1; Tue, 07 Apr 2026 03:06:43 -0400 X-MC-Unique: aZ2Ld6UINqSbj1LMJpwL0Q-1 X-Mimecast-MFC-AGG-ID: aZ2Ld6UINqSbj1LMJpwL0Q_1775545602 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 068F81956058 for ; Tue, 7 Apr 2026 07:06:42 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.44.48.95]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1E4F11955D84; Tue, 7 Apr 2026 07:06:40 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.18.1/8.18.1) with ESMTPS id 63776c3k1620922 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 7 Apr 2026 09:06:38 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 63776bmS1620921; Tue, 7 Apr 2026 09:06:37 +0200 Date: Tue, 7 Apr 2026 09:06:37 +0200 From: Jakub Jelinek To: Jason Merrill , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Implement mangling for partially instantiated C++26 pack indexing [PR124487] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: nEpHAhvhnqTF3ZLuGFyh95A339enlr2vIjMD5fvw0ts_1775545602 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@gcc.gnu.org On Fri, Apr 03, 2026 at 05:56:08PM -0400, Jason Merrill wrote: > Regarding the TODO, the related case I was thinking about was > > > ::= sZ # sizeof...(T), size of a template parameter pack > > ::= sP * E # sizeof...(T), size of a captured template parameter pack from an alias template > > ...but rather than follow the precedent of a different two-letter > abbreviation, I might use J...E to express the expanded pack, as in > . I've now suggested that on the ABI issue, as well. Here is a patch which implements it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2026-04-07 Jakub Jelinek * mangle.cc (write_type) : Handle even the case of partially substituted pack. (write_expression): Similarly for PACK_INDEX_EXPR. * g++.dg/cpp26/pack-indexing9.C: Remove dg-sorry/dg-bogus, add tests for mangled names and further test coverage. Jakub --- gcc/cp/mangle.cc.jj 2026-04-04 11:17:15.921287840 +0200 +++ gcc/cp/mangle.cc 2026-04-06 09:14:12.484890203 +0200 @@ -2745,16 +2745,19 @@ write_type (tree type) case PACK_INDEX_TYPE: /* https://github.com/itanium-cxx-abi/cxx-abi/issues/175. */ + write_string ("Dy"); if (TREE_CODE (PACK_INDEX_PACK (type)) == TREE_VEC) { - /* TODO: How should this be mangled when the pack is already - expanded? */ - sorry ("mangling type pack index"); - break; + write_char ('J'); + for (int i = 0; i < TREE_VEC_LENGTH (PACK_INDEX_PACK (type)); + ++i) + write_template_arg (TREE_VEC_ELT (PACK_INDEX_PACK (type), + i)); + write_char ('E'); } - write_string ("Dy"); - /* Dy rather than DyDp. */ - write_type (PACK_EXPANSION_PATTERN (PACK_INDEX_PACK (type))); + else + /* Dy rather than DyDp. */ + write_type (PACK_EXPANSION_PATTERN (PACK_INDEX_PACK (type))); write_expression (PACK_INDEX_INDEX (type)); break; @@ -3614,17 +3617,19 @@ write_expression (tree expr) else if (code == PACK_INDEX_EXPR) { /* https://github.com/itanium-cxx-abi/cxx-abi/issues/175. */ + write_string ("sy"); if (TREE_CODE (PACK_INDEX_PACK (expr)) == TREE_VEC) - /* TODO: How should this be mangled when the pack is already - expanded? */ - sorry ("mangling type pack index"); - else { - write_string ("sy"); - /* sy rather than sysp. */ - write_expression (PACK_EXPANSION_PATTERN (PACK_INDEX_PACK (expr))); - write_expression (PACK_INDEX_INDEX (expr)); + write_char ('J'); + for (int i = 0; i < TREE_VEC_LENGTH (PACK_INDEX_PACK (expr)); + ++i) + write_template_arg (TREE_VEC_ELT (PACK_INDEX_PACK (expr), i)); + write_char ('E'); } + else + /* sy rather than sysp. */ + write_expression (PACK_EXPANSION_PATTERN (PACK_INDEX_PACK (expr))); + write_expression (PACK_INDEX_INDEX (expr)); } else if (TREE_CODE (expr) == ALIGNOF_EXPR) { --- gcc/testsuite/g++.dg/cpp26/pack-indexing9.C.jj 2026-03-27 10:17:15.656305903 +0100 +++ gcc/testsuite/g++.dg/cpp26/pack-indexing9.C 2026-04-06 09:27:43.438279320 +0200 @@ -4,24 +4,42 @@ // From . template struct tuple { - template T...[I] get(); // { dg-bogus "sorry, unimplemented: mangling" "" { xfail *-*-* } } + template T...[I] get(); }; int g () { tuple t; + // { dg-final { scan-assembler "_ZN5tupleIJiEE3getILj0EEEDyJiET_v" } } return t.get<0>(); } template concept C = true; +template concept D = true; template struct A { - template void f(T...[I], U...[I]) requires C; // { dg-message "sorry, unimplemented: mangling" } + template void f(T...[I], U...[I]) requires C; + template void h(T...[I], decltype(U...[I])) requires D; }; void h () { A a; + // { dg-final { scan-assembler "_ZN1AIJcidEE1fILi1EJiicEEEvDyJcidET_DyT0_T_Q1CIDyT_TL0__DyTL0_0_TL0__E" } } a.f<1, int, int, char>(1, 2); + // { dg-final { scan-assembler "_ZN1AIJcidEE1hILi1EJLi2ELl3ELj4EEEEvDyJcidET_DtsyT0_T_EQ1DIDyT_TL0__XsyTL0_0_TL0__EE" } } + a.h<1, 2, 3L, 4U>(1, 3L); +} + +template struct E { + template decltype (U...[I]) get(); +}; + +int +i () +{ + E<1, 2L, 3U, 4LL> t; + // { dg-final { scan-assembler "_ZN1EIJLi1ELl2ELj3ELx4EEE3getILj2EEEDtsyJLi1ELl2ELj3ELx4EET_Ev" } } + return t.get<2>(); }