Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2233400/?format=api
{ "id": 2233400, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2233400/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/afr51pcAuC2Fmubs@tucnak/", "project": { "id": 17, "url": "http://patchwork.ozlabs.org/api/1.1/projects/17/?format=api", "name": "GNU Compiler Collection", "link_name": "gcc", "list_id": "gcc-patches.gcc.gnu.org", "list_email": "gcc-patches@gcc.gnu.org", "web_url": null, "scm_url": null, "webscm_url": null }, "msgid": "<afr51pcAuC2Fmubs@tucnak>", "date": "2026-05-06T08:20:38", "name": "c++: Reflection vs. CLASSTYPE_TYPEINFO_VAR/ANON_AGGR_TYPE_FIELD sharing [PR124991]", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "a68f936b810a67af23c8d406f80214a069920af2", "submitter": { "id": 671, "url": "http://patchwork.ozlabs.org/api/1.1/people/671/?format=api", "name": "Jakub Jelinek", "email": "jakub@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/afr51pcAuC2Fmubs@tucnak/mbox/", "series": [ { "id": 502968, "url": "http://patchwork.ozlabs.org/api/1.1/series/502968/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=502968", "date": "2026-05-06T08:20:38", "name": "c++: Reflection vs. CLASSTYPE_TYPEINFO_VAR/ANON_AGGR_TYPE_FIELD sharing [PR124991]", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/502968/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2233400/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2233400/checks/", "tags": {}, "headers": { "Return-Path": "<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "gcc-patches@gcc.gnu.org" ], "Delivered-To": [ "patchwork-incoming@legolas.ozlabs.org", "gcc-patches@gcc.gnu.org" ], "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=e4CLI8Z5;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)", "sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=e4CLI8Z5", "sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com", "sourceware.org; spf=pass smtp.mailfrom=redhat.com", "sourceware.org; arc=none smtp.remote-ip=170.10.133.124" ], "Received": [ "from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g9XTz0jNdz1y04\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 21:00:23 +1000 (AEST)", "from vm01.sourceware.org (localhost [IPv6:::1])\n\tby sourceware.org (Postfix) with ESMTP id 368284BA23F5\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 6 May 2026 11:00:21 +0000 (GMT)", "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by sourceware.org (Postfix) with ESMTP id 31B744BA23D3\n for <gcc-patches@gcc.gnu.org>; Wed, 6 May 2026 08:20:46 +0000 (GMT)", "from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-426--EpARlEWM4Ss-v82MhRlCw-1; Wed,\n 06 May 2026 04:20:43 -0400", "from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id CAE2118005B5\n for <gcc-patches@gcc.gnu.org>; Wed, 6 May 2026 08:20:42 +0000 (UTC)", "from tucnak.zalov.cz (unknown [10.44.48.41])\n by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 144BE3002D2D; Wed, 6 May 2026 08:20:41 +0000 (UTC)", "from tucnak.zalov.cz (localhost [127.0.0.1])\n by tucnak.zalov.cz (8.18.1/8.18.1) with ESMTPS id 6468Kd7o202530\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);\n Wed, 6 May 2026 10:20:39 +0200", "(from jakub@localhost)\n by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 6468KdMh202529;\n Wed, 6 May 2026 10:20:39 +0200" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 368284BA23F5", "OpenDKIM Filter v2.11.0 sourceware.org 31B744BA23D3" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 31B744BA23D3", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 31B744BA23D3", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778055646; cv=none;\n b=fGvpAfOtWYBCpu+MtYU/CpZ60TOCff3hRMAD46XxOVoJfbe0qY134s+5NZcrG2mvjaR3kXnKufKxohQi63izZj2XTBENG2IS3pKIoXrQQmGAXlpZBB7jlCSpxt+XutB+zjQvo4wA2RAdKFJit/80Lvbl+AIWLmJzyVUSAavrsfo=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1778055646; c=relaxed/simple;\n bh=XNSlD6GXCxxgdpowQKiUMkcrySw1Ytz3ZlMP9N5kSHo=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=plaDP+6I1U30kBD5u4F37pXvSJUhVxgOtwaJgUMaBMlNeOgbCrEhFdNtbx1/NcnP0MPRGtJ/NTQ2M9pluo18sv/4etErghIc6jDnZHanzGGVcnOs0PxpzVrenY7bzTiEutNgFhN4VepcjIBraHlzHIifJKYpA/9Wp61X8qs0Xe8=", "ARC-Authentication-Results": "i=1; sourceware.org;\n dkim=pass (1024-bit key, unprotected)\n header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=e4CLI8Z5", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1778055645;\n h=from:from:reply-to:reply-to:subject:subject:date:date:\n message-id:message-id:to:to:cc:cc:mime-version:mime-version:\n content-type:content-type; bh=DWO1orxOpIzYsvLOIKCBMizH7HcW9gwvX9+U3SUKZZU=;\n b=e4CLI8Z5PLijzW5G7jl7pZn/UvpXIoNEd2DZ4RePo6fknSgdLlbKZDawMHytIm7ogFqQ72\n nD/SUNfN1CwFIQ97RsidV65r5cey/MESBW5bqu67EkSnhAGPFzHQNp1YAO8C/7UaMgFE7f\n mHPlCI/8o+idLmkFsscOIZli8z4EFHo=", "X-MC-Unique": "-EpARlEWM4Ss-v82MhRlCw-1", "X-Mimecast-MFC-AGG-ID": "-EpARlEWM4Ss-v82MhRlCw_1778055643", "Date": "Wed, 6 May 2026 10:20:38 +0200", "From": "Jakub Jelinek <jakub@redhat.com>", "To": "Jason Merrill <jason@redhat.com>, Marek Polacek <polacek@redhat.com>", "Cc": "gcc-patches@gcc.gnu.org", "Subject": "[PATCH] c++: Reflection vs.\n CLASSTYPE_TYPEINFO_VAR/ANON_AGGR_TYPE_FIELD sharing [PR124991]", "Message-ID": "<afr51pcAuC2Fmubs@tucnak>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.4", "X-Mimecast-Spam-Score": "0", "X-Mimecast-MFC-PROC-ID": "L9S4QK9OeN22PM_moZ1u1YnzVkJahA8hVZF4har1Nqw_1778055643", "X-Mimecast-Originator": "redhat.com", "Content-Type": "text/plain; charset=us-ascii", "Content-Disposition": "inline", "X-BeenThere": "gcc-patches@gcc.gnu.org", "X-Mailman-Version": "2.1.30", "Precedence": "list", "List-Id": "Gcc-patches mailing list <gcc-patches.gcc.gnu.org>", "List-Unsubscribe": "<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <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>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>", "Reply-To": "Jakub Jelinek <jakub@redhat.com>", "Errors-To": "gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org" }, "content": "Hi!\n\ntypeinfo_var element of lang_type is used for 2 purposes,\nCLASSTYPE_TYPEINFO_VAR and ANON_AGGR_TYPE_FIELD, a VAR_DECL for types\nfor which we need typeid etc. and FIELD_DECL for anonymous union/struct\ntypes inside of classes.\nWithout reflection one can't ask for typeid of the anonymous union/struct\ntypes, so sharing the same tree for both purposes is fine, but with\nreflection we can ICE.\n\nAs anonymous unions are fairly rare and asking about typeid of those will be\neven rarer, the following patch attempts to fix that without actually\ngrowing the lang_type struct size by using the same tree for both. If it\nis NULL_TREE, both CLASSTYPE_TYPEINFO_VAR and ANON_AGGR_TYPE_FIELD\nare NULL, if it is a VAR_DECL, it is the former, if it is a FIELD_DECL,\nit is the latter, in the really rare case we need both it is turned\ninto a TREE_LIST where TREE_VALUE is CLASSTYPE_TYPEINFO_VAR and\nTREE_PURPOSE is ANON_AGGR_TYPE_FIELD.\n\nBootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/16.2?\n\nNote, CWG3130 fortunately disallows attempts to create a different object\nof ANON_AGGR_TYPE_P type (will need to implement that part), so the other\nworries from PR124991 (that one can create a variable or member or parameter\netc. with the anon union type and get confused by ANON_AGGR_TYPE_FIELD on it\nor trying to tweak lookup rules etc.) are gone.\n\n2026-05-06 Jakub Jelinek <jakub@redhat.com>\n\n\tPR c++/124991\n\t* cp-tree.h (struct lang_type): Document typeinfo_var member.\n\t(get_classtype_typeinfo_var): New inline function.\n\t(CLASSTYPE_TYPEINFO_VAR): Use it.\n\t(set_classtype_typeinfo_var): New inline function.\n\t(SET_CLASSTYPE_TYPEINFO_VAR): Define.\n\t(get_anon_aggr_type_field): New inline function.\n\t(ANON_AGGR_TYPE_FIELD): Use it.\n\t(set_anon_aggr_type_field): New inline function.\n\t(SET_ANON_AGGR_TYPE_FIELD): Define.\n\t* decl.cc (fixup_anonymous_aggr): Use SET_ANON_AGGR_TYPE_FIELD\n\tinstead of ANON_AGGR_TYPE_FIELD.\n\t* module.cc (trees_in::read_class_def): Use\n\tSET_CLASSTYPE_TYPEINFO_VAR instead of setting\n\tCLASSTYPE_TYPEINFO_VAR and do it even for ANON_AGGR_TYPE_P\n\ttypes. Use SET_ANON_AGGR_TYPE_FIELD instead of setting\n\tANON_AGGR_TYPE_FIELD.\n\t* rtti.cc (get_tinfo_decl_direct): Use SET_CLASSTYPE_TYPEINFO_VAR\n\tinstead of setting CLASSTYPE_TYPEINFO_VAR.\n\t* semantics.cc (finish_member_declaration): Use\n\tSET_ANON_AGGR_TYPE_FIELD instead of setting ANON_AGGR_TYPE_FIELD.\n\n\t* g++.dg/reflect/anon5.C: New test.\n\n\n\tJakub", "diff": "--- gcc/cp/cp-tree.h.jj\t2026-04-28 08:52:42.674411768 +0200\n+++ gcc/cp/cp-tree.h\t2026-05-05 11:26:48.237006358 +0200\n@@ -2682,6 +2682,9 @@ struct GTY(()) lang_type {\n tree primary_base;\n vec<tree_pair_s, va_gc> *vcall_indices;\n tree vtables;\n+ /* CLASSTYPE_TYPEINFO_VAR and/or ANON_AGGR_TYPE_FIELD. If both,\n+ this is a TREE_LIST with the former as TREE_VALUE and the latter\n+ as TREE_PURPOSE. */\n tree typeinfo_var;\n vec<tree, va_gc> *vbases;\n tree as_base;\n@@ -3075,11 +3078,44 @@ struct GTY(()) lang_type {\n #define CLASSTYPE_VTABLES(NODE) \\\n (LANG_TYPE_CLASS_CHECK (NODE)->vtables)\n \n+/* Helper for CLASSTYPE_TYPEINFO_VAR. */\n+\n+inline tree\n+get_classtype_typeinfo_var (tree typeinfo_var)\n+{\n+ if (typeinfo_var == NULL_TREE)\n+ return NULL_TREE;\n+ if (TREE_CODE (typeinfo_var) == TREE_LIST)\n+ return TREE_VALUE (typeinfo_var);\n+ if (VAR_P (typeinfo_var))\n+ return typeinfo_var;\n+ return NULL_TREE;\n+}\n+\n /* The std::type_info variable representing this class, or NULL if no\n such variable has been created. This field is only set for the\n TYPE_MAIN_VARIANT of the class. */\n #define CLASSTYPE_TYPEINFO_VAR(NODE) \\\n- (LANG_TYPE_CLASS_CHECK (NODE)->typeinfo_var)\n+ get_classtype_typeinfo_var (LANG_TYPE_CLASS_CHECK (NODE)->typeinfo_var)\n+\n+/* Helper for SET_CLASSTYPE_TYPEINFO_VAR. */\n+\n+inline tree &\n+set_classtype_typeinfo_var (tree &typeinfo_var)\n+{\n+ if (typeinfo_var == NULL_TREE)\n+ return typeinfo_var;\n+ if (TREE_CODE (typeinfo_var) == FIELD_DECL)\n+ typeinfo_var = build_tree_list (typeinfo_var, NULL_TREE);\n+ if (TREE_CODE (typeinfo_var) == TREE_LIST)\n+ return TREE_VALUE (typeinfo_var);\n+ return typeinfo_var;\n+}\n+\n+/* Setter for that. */\n+#define SET_CLASSTYPE_TYPEINFO_VAR(NODE, VAR) \\\n+ (set_classtype_typeinfo_var (LANG_TYPE_CLASS_CHECK (NODE)->typeinfo_var) \\\n+ = (VAR))\n \n /* Accessor macros for the BINFO_VIRTUALS list. */\n \n@@ -5407,9 +5443,42 @@ get_vec_init_expr (tree t)\n #define ANON_UNION_TYPE_P(NODE) \\\n (TREE_CODE (NODE) == UNION_TYPE && ANON_AGGR_TYPE_P (NODE))\n \n+/* Helper for ANON_AGGR_TYPE_FIELD. */\n+\n+inline tree\n+get_anon_aggr_type_field (tree typeinfo_var)\n+{\n+ if (typeinfo_var == NULL_TREE)\n+ return NULL_TREE;\n+ if (TREE_CODE (typeinfo_var) == TREE_LIST)\n+ return TREE_PURPOSE (typeinfo_var);\n+ if (TREE_CODE (typeinfo_var) == FIELD_DECL)\n+ return typeinfo_var;\n+ return NULL_TREE;\n+}\n+\n /* For an ANON_AGGR_TYPE_P the single FIELD_DECL it is used with. */\n #define ANON_AGGR_TYPE_FIELD(NODE) \\\n- (LANG_TYPE_CLASS_CHECK (NODE)->typeinfo_var)\n+ get_anon_aggr_type_field (LANG_TYPE_CLASS_CHECK (NODE)->typeinfo_var)\n+\n+/* Helper for SET_ANON_AGGR_TYPE_FIELD. */\n+\n+inline tree &\n+set_anon_aggr_type_field (tree &typeinfo_var)\n+{\n+ if (typeinfo_var == NULL_TREE)\n+ return typeinfo_var;\n+ if (VAR_P (typeinfo_var))\n+ typeinfo_var = build_tree_list (NULL_TREE, typeinfo_var);\n+ if (TREE_CODE (typeinfo_var) == TREE_LIST)\n+ return TREE_PURPOSE (typeinfo_var);\n+ return typeinfo_var;\n+}\n+\n+/* Setter for that. */\n+#define SET_ANON_AGGR_TYPE_FIELD(NODE, FIELD) \\\n+ (set_anon_aggr_type_field (LANG_TYPE_CLASS_CHECK (NODE)->typeinfo_var) \\\n+ = (FIELD))\n \n /* Define fields and accessors for nodes representing declared names. */\n \n--- gcc/cp/decl.cc.jj\t2026-04-28 08:52:47.345330582 +0200\n+++ gcc/cp/decl.cc\t2026-05-05 11:22:05.379600563 +0200\n@@ -6200,7 +6200,7 @@ fixup_anonymous_aggr (tree t)\n vec_safe_truncate (vec, store);\n \n /* Wipe RTTI info. */\n- CLASSTYPE_TYPEINFO_VAR (t) = NULL_TREE;\n+ SET_CLASSTYPE_TYPEINFO_VAR (t, NULL_TREE);\n \n /* Anonymous aggregates cannot have fields with ctors, dtors or complex\n assignment operators (because they cannot have these methods themselves).\n--- gcc/cp/module.cc.jj\t2026-05-05 10:39:23.498137518 +0200\n+++ gcc/cp/module.cc\t2026-05-05 11:24:58.090794839 +0200\n@@ -13730,9 +13730,8 @@ trees_in::read_class_def (tree defn, tre\n \t\t{\n \t\t CLASSTYPE_BEFRIENDING_CLASSES (type_dup)\n \t\t = CLASSTYPE_BEFRIENDING_CLASSES (type);\n-\t\t if (!ANON_AGGR_TYPE_P (type))\n-\t\t CLASSTYPE_TYPEINFO_VAR (type_dup)\n-\t\t = CLASSTYPE_TYPEINFO_VAR (type);\n+\t\t SET_CLASSTYPE_TYPEINFO_VAR (type_dup,\n+\t\t\t\t\t CLASSTYPE_TYPEINFO_VAR (type));\n \t\t}\n \t for (tree v = type; v; v = TYPE_NEXT_VARIANT (v))\n \t\tTYPE_LANG_SPECIFIC (v) = ls;\n@@ -13773,7 +13772,7 @@ trees_in::read_class_def (tree defn, tre\n \t\t to the as-base FIELD_DECL copy. */\n \t\t gcc_checking_assert (ANON_AGGR_TYPE_FIELD (anon_type));\n \t\t else\n-\t\t ANON_AGGR_TYPE_FIELD (anon_type) = decl;\n+\t\t SET_ANON_AGGR_TYPE_FIELD (anon_type, decl);\n \t\t}\n \n \t if (TREE_CODE (decl) == USING_DECL\n--- gcc/cp/rtti.cc.jj\t2026-03-27 10:17:14.033332387 +0100\n+++ gcc/cp/rtti.cc\t2026-05-05 11:23:27.832261102 +0200\n@@ -490,7 +490,7 @@ get_tinfo_decl_direct (tree type, tree n\n \n d = pushdecl_top_level_and_finish (d, NULL_TREE);\n if (CLASS_TYPE_P (type))\n-\tCLASSTYPE_TYPEINFO_VAR (TYPE_MAIN_VARIANT (type)) = d;\n+\tSET_CLASSTYPE_TYPEINFO_VAR (TYPE_MAIN_VARIANT (type), d);\n \n /* Add decl to the global array of tinfo decls. */\n vec_safe_push (unemitted_tinfo_decls, d);\n--- gcc/cp/semantics.cc.jj\t2026-04-30 10:18:13.827688681 +0200\n+++ gcc/cp/semantics.cc\t2026-05-05 11:24:36.620143633 +0200\n@@ -4284,7 +4284,7 @@ finish_member_declaration (tree decl)\n && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))\n {\n gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));\n- ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))) = decl;\n+ SET_ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl)), decl);\n }\n \n if (TREE_CODE (decl) == USING_DECL)\n--- gcc/testsuite/g++.dg/reflect/anon5.C.jj\t2026-05-05 11:52:55.849584570 +0200\n+++ gcc/testsuite/g++.dg/reflect/anon5.C\t2026-05-05 12:03:15.339521433 +0200\n@@ -0,0 +1,16 @@\n+// PR c++/124991\n+// { dg-do run { target c++26 } }\n+// { dg-additional-options \"-freflection\" }\n+\n+#include <meta>\n+\n+struct X { union { char b; float c; }; };\n+constexpr auto ctx = std::meta::access_context::unchecked ();\n+\n+int\n+main ()\n+{\n+ if (typeid (typename [: parent_of (^^X::b) :])\n+ != typeid (typename [: members_of (^^X, ctx)[0] :]))\n+ __builtin_abort ();\n+}\n", "prefixes": [] }