[{"id":3675429,"web_url":"http://patchwork.ozlabs.org/comment/3675429/","msgid":"<f55af3ce-9cea-4538-a93d-251fcb3e0720@redhat.com>","list_archive_url":null,"date":"2026-04-09T17:59:10","subject":"Re: [PATCH] c++: Unshare expr in get_template_parm_object [PR124792]","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"On 4/9/26 12:35 PM, Jakub Jelinek wrote:\n> On Thu, Apr 09, 2026 at 12:07:42PM -0400, Jason Merrill wrote:\n>>> With reflection, we can create the NTTPOs during constant evaluation rather than\n>>> after cxx_eval_outermost_constant_expr has unshared those, so later\n>>> processing within the same cxx_eval_outermost_constant_expr call can modify\n>>> those not unshared trees.\n>>> Now, from reflect.cc get_template_parm_object is called directly from\n>>> eval_reflect_constant_string (I think not a problem, the argument should be\n>>> always STRING_CST in that case), eval_reflect_constant_array (also not\n>>> a problem IMHO, as the outer CONSTRUCTOR is freshly created by\n>>> get_range_elts and what is inside of it is unshared by\n>>>               if (VAR_P (expr))\n>>>                 expr = unshare_expr (DECL_INITIAL (expr));\n>>> ) and then indirectly (convert_reflect_constant_arg ->\n>>> convert_nontype_argument -> create_template_parm_object) from\n>>> within get_range_elts, eval_reflect_constant, eval_reflect_object,\n>>> eval_reflect_function.  So, if we don't do unsharing in\n>>> get_template_parm_object because it is philosophically attractive but\n>>> wastes compile time memory too much when things are usually unshared,\n>>\n>> Actually, I'm not sure it does waste too much memory; a quick check with\n>> -fmem-report shows no difference in the totals on compiling stdc++.h as\n>> C++26.  And since we'd only unshare in the case where we're actually\n>> creating a new variable, it might actually mean less unsharing in the case\n>> of repetitive patterns.\n>>\n>>> (and yet another question is unshare_constructor vs. unshare_expr),\n>>\n>> Or even unshare_expr_without_location (like PR91165) if we unshare in\n>> get_TPO since all occurrences of the same value get the same variable.\n>>\n>> It seems that many places use unshare_constructor to protect against things\n>> like split_nonconstant_init or cxx_eval_store_expression but not a modifying\n>> walk_tree like cp_genericize.\n> \n> So, do you want something like the patch below then?\n\nI think so, yes.\n\n> I think in the modules.cc (aka !check_init) case the CONSTRUCTOR is already\n> not shared because it has been read from the module, but I could be wrong.\n\nAgreed.\n\n> And another question is about that\n>        /* If EXPR contains any PTRMEM_CST, they will get clobbered by\n>           lower_var_init before we're done mangling.  So store the original\n>           value elsewhere.  We only need to unshare EXPR if it's not yet\n>           been processed.  */\n>        tree copy = check_init ? unshare_constructor (expr) : expr;\n>        hash_map_safe_put<hm_ggc> (tparm_obj_values, decl, copy);\n> I guess lower_var_init is done late these days, but still, if we need\n> tparm_obj_values at all, couldn't we do it solely for the cases where\n> expr contains any PTRMEM_CSTs inside of it (so search all the nested\n> CONSTRUCTORs if we find PTRMEM_CSTs, similarly how cplus_expand_constant\n> does that, just don't expand anything, just return bool that it contains\n> them and unshare/register in that case), and otherwise just use\n> DECL_INITIAL?\n\nSure, though I doubt that would make a noticeable difference.\n\n> 2026-04-09  Jakub Jelinek  <jakub@redhat.com>\n> \n> \tPR c++/124792\n> \t* pt.cc (get_template_parm_object): Call unshare_expr_without_location\n> \ton expr if check_init.\n> \n> \t* g++.dg/reflect/pr124792.C: New test.\n> \n> --- gcc/cp/pt.cc.jj\t2026-04-09 18:18:26.461536563 +0200\n> +++ gcc/cp/pt.cc\t2026-04-09 18:23:33.840288646 +0200\n> @@ -7551,6 +7551,8 @@ get_template_parm_object (tree expr, tre\n>     DECL_NAME (decl) = name;\n>     SET_DECL_ASSEMBLER_NAME (decl, name);\n>     comdat_linkage (decl);\n> +  if (check_init)\n> +    expr = unshare_expr_without_location (expr);\n>   \n>     if (!zero_init_p (type))\n>       {\n> --- gcc/testsuite/g++.dg/reflect/pr124792.C.jj\t2026-04-09 18:18:08.189674154 +0200\n> +++ gcc/testsuite/g++.dg/reflect/pr124792.C\t2026-04-09 18:18:08.189674154 +0200\n> @@ -0,0 +1,11 @@\n> +// PR c++/124792\n> +// { dg-do compile { target c++26 } }\n> +// { dg-additional-options \"-freflection\" }\n> +\n> +#include <meta>\n> +\n> +struct S { const char *name = nullptr; };\n> +\n> +constexpr auto a = std::define_static_array (std::vector { S { std::define_static_string (\"foo\") } });\n> +constexpr auto b = std::define_static_array (std::vector { S { std::define_static_string (\"foo\") },\n> +\t\t\t\t\t\t\t   S { std::define_static_string (\"bar\") } });\n> \n> \n> \tJakub\n>","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=bYV+JpNN;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::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=bYV+JpNN","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::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 4fs74Q2rB2z1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 03:59:49 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 4984D4BA2E15\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  9 Apr 2026 17:59:47 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 9E7BD4BA2E0C\n for <gcc-patches@gcc.gnu.org>; Thu,  9 Apr 2026 17:59:15 +0000 (GMT)","from mail-qt1-f199.google.com (mail-qt1-f199.google.com\n [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-117-tWAHskftPna3YHxjaJmuXw-1; Thu, 09 Apr 2026 13:59:13 -0400","by mail-qt1-f199.google.com with SMTP id\n d75a77b69052e-50d984c74a8so31076281cf.1\n for <gcc-patches@gcc.gnu.org>; Thu, 09 Apr 2026 10:59:13 -0700 (PDT)","from [192.168.50.130]\n (130-44-146-247.s12789.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com.\n [130.44.146.247]) by smtp.gmail.com with ESMTPSA id\n d75a77b69052e-50dd5637f4fsm1892551cf.28.2026.04.09.10.59.11\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Thu, 09 Apr 2026 10:59:11 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 4984D4BA2E15","OpenDKIM Filter v2.11.0 sourceware.org 9E7BD4BA2E0C"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 9E7BD4BA2E0C","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 9E7BD4BA2E0C","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775757555; cv=none;\n b=IyBpFVOcFZBlSz4GJXY3qjxcrxKc4/+uLiKdgu9w+NpFFe+oLLc7OplSb//m04nv9uchz6aDMMySeRMigARxgtWrLcGo2pg/J8Eo6Rbs34+8rFePukxMJINXiL2NG8amajMfofp3w+8yNcEJ9cq59XD8Ef/2x9nLKZDf2NPSqq4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775757555; c=relaxed/simple;\n bh=eFDzK2ZYDAFuhR3YK8AcZKvCLz3MRznamV4/DYWpYhY=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=UgPs7FKfLxgPieqN1bUwXzG9LqoRMPq8lUSMXJtMkfYpH8uTzFdiPS+4rr5ln5B+YzcMQmRWsf1bIpidEzkAFJlAJO4Mmzs4hSgBB43fllDzG/vvUTmFMr4gvLmSAcPIWnlS0ACltUjsf/P8SeHZdZzz0/sKyblXqzrdEtvi5M8=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1775757555;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=nKv3T/36vs08jtwMqKdVRxVpS7Yxk1gYEaA/fzHmwIo=;\n b=bYV+JpNN3g3wGqQSxKzeYwV4rtzA8XZbqZUFNzWHKMwXA/MJ7my+wrP9xZa+RNtJDJ9lso\n jWJ9n7sablqxSqHF5jTDwQjQTgXllKUgqNfHyiLTnVyuRme8A/MgV8XBKJVRwvuHG4A5KI\n yYwRvRsCoyqwX/+qo6nKIo0WFEQitu8=","X-MC-Unique":"tWAHskftPna3YHxjaJmuXw-1","X-Mimecast-MFC-AGG-ID":"tWAHskftPna3YHxjaJmuXw_1775757553","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775757553; x=1776362353;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:cc:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=nKv3T/36vs08jtwMqKdVRxVpS7Yxk1gYEaA/fzHmwIo=;\n b=jeW/AiLSxFMvMqC2O2SzlvPYB2J6UjUkxBGXPxBAkkgn5cNHRLu9qkaYSeud9slOqt\n RKUp5Qz3dHuJF3/z9i8Bg/VAm5wshrgzQaiGqBQCNQQipA4erXygLKaDA7z5moja3EW6\n +O5j/M6ilbqCeeT4OfNvlidlXSGmtmbrSMY+LAelOTq9AQ4eEPNstWADrJTr1qj8G0jM\n KaExxgfKG/qRNFKde309/a/GMcAQDInw6XnRrgsmq1ioGrMVvuBsqdbRNnyfbHb0nhkT\n vblB5mQAU9rFW6kiMRbMkaCnlT0zOTb4gtAF+JMcjbfVYUgKnq39znkaAHW+lRqtvOcB\n 39ng==","X-Forwarded-Encrypted":"i=1;\n AJvYcCWixoHm9zPTxqgZwff16xrSqNcyuEAv85HtXw6V5FrgXt+m7nOKIjprPb64KprICQjyC90NAVYYK8Smcw==@gcc.gnu.org","X-Gm-Message-State":"AOJu0YyPg9ay5J+FySXU8zt+FPxUqBcukyPpxC1tAUFWUqoNEm9BSNGw\n Q5hk1VH6Pa8tRhpxdpiq26EdkUnmDMs8F2ho4RfWT/jJdcx+w9m4rt4JFpm3rZSmWsg17BVo2W9\n 72DxQDC0z2T9/Nzmo/1WyhJUJipeMTvr6QvdpIihNU6cN8cRBzYxTdxBuLKE=","X-Gm-Gg":"AeBDietTNzUDQp6lfTXvkFrDWZ2XKmxizIQNQkvmlIdA7joRbv55LMHiH+/bLuQRNh2\n vLHtnAJGjpfzdZzxyBhoep5BlG6E2AWvBpTsPVHGBNwHtUwuEvJktI65JKAwGcwd0oDI7eTt5fx\n 7d+b+2D+F8gOWkmfrPBoMeCpe2KbXB296PrzpvSklZlqL2cbGZIHRoQcZqzEIwK1z+yyUCNC8Ng\n qVXqQZESyJMvgBE3bmb1ck4VRY0WjkPdwZtzG8GcwYHCwrHlvqviGkeN56Jb3WnH/Z7pyjnJGsy\n i5pnYwrL7A/ANwgzzO6av/FSOBTAXnbLNVaqvtwmliCdv9IBK04sjhW6/AbwyroVcIM/JULpAEW\n z8RbYZF3z7yl85nGqmMP8EXDoVk0a+q0kv1ntxDM0li4pGkve7q+5Mh37Ehch2bR7C5JkA5X/7M\n lsID7Nl/5AYc53MHBU0gkRtJrTvgUuY/0=","X-Received":["by 2002:a05:622a:1493:b0:4f1:b742:35c2 with SMTP id\n d75a77b69052e-50dd5ad2efamr3766141cf.22.1775757552910;\n Thu, 09 Apr 2026 10:59:12 -0700 (PDT)","by 2002:a05:622a:1493:b0:4f1:b742:35c2 with SMTP id\n d75a77b69052e-50dd5ad2efamr3765581cf.22.1775757552380;\n Thu, 09 Apr 2026 10:59:12 -0700 (PDT)"],"Message-ID":"<f55af3ce-9cea-4538-a93d-251fcb3e0720@redhat.com>","Date":"Thu, 9 Apr 2026 13:59:10 -0400","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] c++: Unshare expr in get_template_parm_object [PR124792]","To":"Jakub Jelinek <jakub@redhat.com>","Cc":"Patrick Palka <ppalka@redhat.com>, chzn@mail.ustc.edu.cn,\n gcc-patches@gcc.gnu.org","References":"<15b4a0ee.835e2.19d6ab44456.Coremail.chzn@mail.ustc.edu.cn>\n <58536bff.85d93.19d6cecd862.Coremail.chzn@mail.ustc.edu.cn>\n <0ce6469a-6ef2-2d0a-f9e2-6c54d7caff01@idea>\n <1be00eb4-570e-41af-8349-770940eee76e@redhat.com> <addVcdge2uqtSg2T@tucnak>\n <a59bb4a6-0b88-40c9-b84a-2df21f214704@redhat.com> <adfVRQUvuvgBZXuF@tucnak>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"<adfVRQUvuvgBZXuF@tucnak>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"syAqSLQ2hZN4cb_PJpFGZtZo9O3TUYOrOfi_Z9OU-X8_1775757553","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}},{"id":3677302,"web_url":"http://patchwork.ozlabs.org/comment/3677302/","msgid":"<89dac1ff-3e56-c9b3-9c56-897d6881a000@idea>","list_archive_url":null,"date":"2026-04-14T16:15:25","subject":"Re: [PATCH] c++: Unshare expr in get_template_parm_object [PR124792]","submitter":{"id":78319,"url":"http://patchwork.ozlabs.org/api/people/78319/","name":"Patrick Palka","email":"ppalka@redhat.com"},"content":"On Thu, 9 Apr 2026, Jason Merrill wrote:\n\n> On 4/9/26 12:35 PM, Jakub Jelinek wrote:\n> > On Thu, Apr 09, 2026 at 12:07:42PM -0400, Jason Merrill wrote:\n> > > > With reflection, we can create the NTTPOs during constant evaluation\n> > > > rather than\n> > > > after cxx_eval_outermost_constant_expr has unshared those, so later\n> > > > processing within the same cxx_eval_outermost_constant_expr call can\n> > > > modify\n> > > > those not unshared trees.\n> > > > Now, from reflect.cc get_template_parm_object is called directly from\n> > > > eval_reflect_constant_string (I think not a problem, the argument should\n> > > > be\n> > > > always STRING_CST in that case), eval_reflect_constant_array (also not\n> > > > a problem IMHO, as the outer CONSTRUCTOR is freshly created by\n> > > > get_range_elts and what is inside of it is unshared by\n> > > >               if (VAR_P (expr))\n> > > >                 expr = unshare_expr (DECL_INITIAL (expr));\n> > > > ) and then indirectly (convert_reflect_constant_arg ->\n> > > > convert_nontype_argument -> create_template_parm_object) from\n> > > > within get_range_elts, eval_reflect_constant, eval_reflect_object,\n> > > > eval_reflect_function.  So, if we don't do unsharing in\n> > > > get_template_parm_object because it is philosophically attractive but\n> > > > wastes compile time memory too much when things are usually unshared,\n> > > \n> > > Actually, I'm not sure it does waste too much memory; a quick check with\n> > > -fmem-report shows no difference in the totals on compiling stdc++.h as\n> > > C++26.  And since we'd only unshare in the case where we're actually\n> > > creating a new variable, it might actually mean less unsharing in the case\n> > > of repetitive patterns.\n> > > \n> > > > (and yet another question is unshare_constructor vs. unshare_expr),\n> > > \n> > > Or even unshare_expr_without_location (like PR91165) if we unshare in\n> > > get_TPO since all occurrences of the same value get the same variable.\n> > > \n> > > It seems that many places use unshare_constructor to protect against\n> > > things\n> > > like split_nonconstant_init or cxx_eval_store_expression but not a\n> > > modifying\n> > > walk_tree like cp_genericize.\n> > \n> > So, do you want something like the patch below then?\n> \n> I think so, yes.\n\nLGTM too, but for GCC 16 shouldn't we go with Jakub's original patch\nthat is specific to reflection?\n\n> \n> > I think in the modules.cc (aka !check_init) case the CONSTRUCTOR is already\n> > not shared because it has been read from the module, but I could be wrong.\n> \n> Agreed.\n> \n> > And another question is about that\n> >        /* If EXPR contains any PTRMEM_CST, they will get clobbered by\n> >           lower_var_init before we're done mangling.  So store the original\n> >           value elsewhere.  We only need to unshare EXPR if it's not yet\n> >           been processed.  */\n> >        tree copy = check_init ? unshare_constructor (expr) : expr;\n> >        hash_map_safe_put<hm_ggc> (tparm_obj_values, decl, copy);\n> > I guess lower_var_init is done late these days, but still, if we need\n> > tparm_obj_values at all, couldn't we do it solely for the cases where\n> > expr contains any PTRMEM_CSTs inside of it (so search all the nested\n> > CONSTRUCTORs if we find PTRMEM_CSTs, similarly how cplus_expand_constant\n> > does that, just don't expand anything, just return bool that it contains\n> > them and unshare/register in that case), and otherwise just use\n> > DECL_INITIAL?\n> \n> Sure, though I doubt that would make a noticeable difference.\n> \n> > 2026-04-09  Jakub Jelinek  <jakub@redhat.com>\n> > \n> > \tPR c++/124792\n> > \t* pt.cc (get_template_parm_object): Call unshare_expr_without_location\n> > \ton expr if check_init.\n> > \n> > \t* g++.dg/reflect/pr124792.C: New test.\n> > \n> > --- gcc/cp/pt.cc.jj\t2026-04-09 18:18:26.461536563 +0200\n> > +++ gcc/cp/pt.cc\t2026-04-09 18:23:33.840288646 +0200\n> > @@ -7551,6 +7551,8 @@ get_template_parm_object (tree expr, tre\n> >     DECL_NAME (decl) = name;\n> >     SET_DECL_ASSEMBLER_NAME (decl, name);\n> >     comdat_linkage (decl);\n> > +  if (check_init)\n> > +    expr = unshare_expr_without_location (expr);\n> >       if (!zero_init_p (type))\n> >       {\n> > --- gcc/testsuite/g++.dg/reflect/pr124792.C.jj\t2026-04-09\n> > 18:18:08.189674154 +0200\n> > +++ gcc/testsuite/g++.dg/reflect/pr124792.C\t2026-04-09 18:18:08.189674154\n> > +0200\n> > @@ -0,0 +1,11 @@\n> > +// PR c++/124792\n> > +// { dg-do compile { target c++26 } }\n> > +// { dg-additional-options \"-freflection\" }\n> > +\n> > +#include <meta>\n> > +\n> > +struct S { const char *name = nullptr; };\n> > +\n> > +constexpr auto a = std::define_static_array (std::vector { S {\n> > std::define_static_string (\"foo\") } });\n> > +constexpr auto b = std::define_static_array (std::vector { S {\n> > std::define_static_string (\"foo\") },\n> > +\t\t\t\t\t\t\t   S {\n> > std::define_static_string (\"bar\") } });\n> > \n> > \n> > \tJakub\n> > \n> \n>","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=etYoMaLo;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::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=etYoMaLo","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.133.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::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 4fw8XQ0J9cz1yHH\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 02:16:04 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id D79934BA2E11\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 16:16:02 +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 24CCB4BA2E39\n for <gcc-patches@gcc.gnu.org>; Tue, 14 Apr 2026 16:15:31 +0000 (GMT)","from mail-qv1-f70.google.com (mail-qv1-f70.google.com\n [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-212-Af0-NAEpPyu5KCdBkIcogg-1; Tue, 14 Apr 2026 12:15:29 -0400","by mail-qv1-f70.google.com with SMTP id\n 6a1803df08f44-8acaea1ff11so5099356d6.2\n for <gcc-patches@gcc.gnu.org>; Tue, 14 Apr 2026 09:15:29 -0700 (PDT)","from [2600:4040:aa66:bf00:9e8e:99ff:fed1:71f]\n ([2600:4040:aa66:bf00:9e8e:99ff:fed1:71f])\n by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-8aca57b465bsm70178486d6.38.2026.04.14.09.15.26\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 14 Apr 2026 09:15:26 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org D79934BA2E11","OpenDKIM Filter v2.11.0 sourceware.org 24CCB4BA2E39"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 24CCB4BA2E39","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 24CCB4BA2E39","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776183331; cv=none;\n b=S7Yha3Nhy4Ty/CcqjuKkgFv4PtuaameZoMCuSk12QmRHh0BL85SssIShtAtKMc8QDP8/LE0UhE/8LSoeOXGyKK3w+//oqdNBmkMIV9E8c+zx3Sbc8/fuRPonD1OgIOqPxtyY6BFwPdFS6+1yd5ll+2AFmciDtziWYex510Itd70=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776183331; c=relaxed/simple;\n bh=I59OviT3VpzxRKqAY9Y7+QkCDf3BVkEjJQpqHs/N/w8=;\n h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version;\n b=vno0sLOPEdLEgGv1UB4Xsil6d/r5kLK6UHHv8bZl/LnT9xR3/aCexFuXmKpotPagfzcmGwCShiCBEQl82xKkm+Z2Pg+PbNqWljCXfSxjP3a7dmFifA8GQfKhsf2JxWS5rw4OpaAHT+u3+vV+D33wDefwGU10mSjOK1D5p/VGRvg=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776183330;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=BX8ymML3tZEasiIj6iLLVOeHxTy62cg8QDpV3aa698s=;\n b=etYoMaLorHCBNX8jyGEs3Ed67/FpxyC+iGL/gi7WMglL1ZTy0RY5kERQlQvR1lS/E+kypF\n uc2WIFoOukl2iJ8w5zdYKzT/ClFhBsqeFN8qZLwCmKH14lJqzlOC/NN8qAAafKQbAosUnd\n REnZRmREpz62J7jduFSCpwwFvBtwp8Q=","X-MC-Unique":"Af0-NAEpPyu5KCdBkIcogg-1","X-Mimecast-MFC-AGG-ID":"Af0-NAEpPyu5KCdBkIcogg_1776183328","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776183328; x=1776788128;\n h=mime-version:references:message-id:in-reply-to:subject:cc:to:date\n :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=BX8ymML3tZEasiIj6iLLVOeHxTy62cg8QDpV3aa698s=;\n b=R6otvsTZOz17BBv5s0ROh16wDpcA4qx7FTM0036GkE/AwFRiflZZEqDYYXJM/Yf/5T\n aHFT+05NKaGYT4r4jX4beUWl0HjuB+u8fzpyUg06vZaX6wJAMTDWrI0u8cXbxwTojr8O\n g7b7GkGuWLR0t2OAr26k8K6hI3YFR1kL2bRQrgR32aoTbUVOCrm+Sf5pbB+Ns8txkohh\n +H9/FjAdeRuup6DvqUQM/sZFm/KAmIYeFCAMQMh4CidsRR2MBjMNf0ev6UsYLdZNV73X\n JivpAfVjmI9QGGAlVUBZXjdXQiifH+2UKgjcttvgyPsDyPgrW+60xpKbk+TpHOuGEB8T\n cvRg==","X-Forwarded-Encrypted":"i=1;\n AFNElJ8oMVpOtSsPvxAhigqEeu0VBG1p76ZmS9mxK8J36/41MdZckOQJb2k1E9h8mzrUGUcRRewaI0dADfEOnw==@gcc.gnu.org","X-Gm-Message-State":"AOJu0YyqYO5NIaBMlRwRUUA/9J+BGRkhyvbkNeSaf21aaCJecTHODZsN\n slYU25T+U+zYkq+Dq90sNUc7cYdgIaCDBnbkLXl8eeCPRqyR3UdNHB/sg15dCIUgXEQVOA41kOH\n 5UwQg2Xmc+pmTrZZ80QHwjOMICwcMGd43UbHfOfAxTaZ8+FEwClRp5xux4Y4=","X-Gm-Gg":"AeBDiesZu+Z+5IOEeEQ1aYKwnEIU0C0VKIjWgpqz5Hic7fXhR8iXb2oG/46X2E0GW63\n TXDFGXJfCL3K/7ui4D7hHzCcjsbCfCX9d4izAW9EDhghdb9LGrbezKfOUPQGbG1AbtjIsMvO7oq\n 30UtKQxFpjWQCkysE6xNBBeDtDqnNtlSgaPOMweqrHuS2KSslcFH39VPm5Kkk8P4JH3sO0SJowc\n BecWE8blIUAcCIIssolvorDsC33TkD7e7HxA9ROpRXqT5wqjww4omlQA6GXkdQBGNfHR6snbUeo\n ek/VmJWneOqw3LeSTfXuAROQKKFjl6dVwabW4J3AH0Ymkk/7VDLyzu7sLlVAdHZui8tW6i1aEr2\n XsMSOXPqWzVq1CsqCXYuz2NiY9TaGc6SeBznzGRccpRoa75WvIGnG3A==","X-Received":["by 2002:a05:6214:2024:b0:8ac:8337:ca0e with SMTP id\n 6a1803df08f44-8ac862ad020mr215267796d6.6.1776183328147;\n Tue, 14 Apr 2026 09:15:28 -0700 (PDT)","by 2002:a05:6214:2024:b0:8ac:8337:ca0e with SMTP id\n 6a1803df08f44-8ac862ad020mr215267086d6.6.1776183327668;\n Tue, 14 Apr 2026 09:15:27 -0700 (PDT)"],"From":"Patrick Palka <ppalka@redhat.com>","X-Google-Original-From":"Patrick Palka <patrick@idea>","Date":"Tue, 14 Apr 2026 12:15:25 -0400 (EDT)","To":"Jason Merrill <jason@redhat.com>","cc":"Jakub Jelinek <jakub@redhat.com>, Patrick Palka <ppalka@redhat.com>,\n chzn@mail.ustc.edu.cn, gcc-patches@gcc.gnu.org","Subject":"Re: [PATCH] c++: Unshare expr in get_template_parm_object [PR124792]","In-Reply-To":"<f55af3ce-9cea-4538-a93d-251fcb3e0720@redhat.com>","Message-ID":"<89dac1ff-3e56-c9b3-9c56-897d6881a000@idea>","References":"<15b4a0ee.835e2.19d6ab44456.Coremail.chzn@mail.ustc.edu.cn>\n <58536bff.85d93.19d6cecd862.Coremail.chzn@mail.ustc.edu.cn>\n <0ce6469a-6ef2-2d0a-f9e2-6c54d7caff01@idea>\n <1be00eb4-570e-41af-8349-770940eee76e@redhat.com> <addVcdge2uqtSg2T@tucnak>\n <a59bb4a6-0b88-40c9-b84a-2df21f214704@redhat.com> <adfVRQUvuvgBZXuF@tucnak>\n <f55af3ce-9cea-4538-a93d-251fcb3e0720@redhat.com>","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"5NBALH4FmyfyUavo-X6yslzV6k9_7Hw4uC17UETzr6M_1776183328","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain; charset=US-ASCII","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>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}},{"id":3677303,"web_url":"http://patchwork.ozlabs.org/comment/3677303/","msgid":"<91d18100-1c43-4075-8b66-4ce2e9d9e835@redhat.com>","list_archive_url":null,"date":"2026-04-14T16:18:45","subject":"Re: [PATCH] c++: Unshare expr in get_template_parm_object [PR124792]","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"On 4/14/26 12:15 PM, Patrick Palka wrote:\n> On Thu, 9 Apr 2026, Jason Merrill wrote:\n> \n>> On 4/9/26 12:35 PM, Jakub Jelinek wrote:\n>>> On Thu, Apr 09, 2026 at 12:07:42PM -0400, Jason Merrill wrote:\n>>>>> With reflection, we can create the NTTPOs during constant evaluation\n>>>>> rather than\n>>>>> after cxx_eval_outermost_constant_expr has unshared those, so later\n>>>>> processing within the same cxx_eval_outermost_constant_expr call can\n>>>>> modify\n>>>>> those not unshared trees.\n>>>>> Now, from reflect.cc get_template_parm_object is called directly from\n>>>>> eval_reflect_constant_string (I think not a problem, the argument should\n>>>>> be\n>>>>> always STRING_CST in that case), eval_reflect_constant_array (also not\n>>>>> a problem IMHO, as the outer CONSTRUCTOR is freshly created by\n>>>>> get_range_elts and what is inside of it is unshared by\n>>>>>                if (VAR_P (expr))\n>>>>>                  expr = unshare_expr (DECL_INITIAL (expr));\n>>>>> ) and then indirectly (convert_reflect_constant_arg ->\n>>>>> convert_nontype_argument -> create_template_parm_object) from\n>>>>> within get_range_elts, eval_reflect_constant, eval_reflect_object,\n>>>>> eval_reflect_function.  So, if we don't do unsharing in\n>>>>> get_template_parm_object because it is philosophically attractive but\n>>>>> wastes compile time memory too much when things are usually unshared,\n>>>>\n>>>> Actually, I'm not sure it does waste too much memory; a quick check with\n>>>> -fmem-report shows no difference in the totals on compiling stdc++.h as\n>>>> C++26.  And since we'd only unshare in the case where we're actually\n>>>> creating a new variable, it might actually mean less unsharing in the case\n>>>> of repetitive patterns.\n>>>>\n>>>>> (and yet another question is unshare_constructor vs. unshare_expr),\n>>>>\n>>>> Or even unshare_expr_without_location (like PR91165) if we unshare in\n>>>> get_TPO since all occurrences of the same value get the same variable.\n>>>>\n>>>> It seems that many places use unshare_constructor to protect against\n>>>> things\n>>>> like split_nonconstant_init or cxx_eval_store_expression but not a\n>>>> modifying\n>>>> walk_tree like cp_genericize.\n>>>\n>>> So, do you want something like the patch below then?\n>>\n>> I think so, yes.\n> \n> LGTM too, but for GCC 16 shouldn't we go with Jakub's original patch\n> that is specific to reflection?\n\nI don't think this patch has significant risk.\n\nJason","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=R3f63o4c;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::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=R3f63o4c","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::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 4fw8c74kmCz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 02:19:19 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id D5B604BA2E13\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 16:19:17 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 5B4444BA2E06\n for <gcc-patches@gcc.gnu.org>; Tue, 14 Apr 2026 16:18:50 +0000 (GMT)","from mail-qt1-f200.google.com (mail-qt1-f200.google.com\n [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-563-hReNZAeuNee2-_J7nS1Ujw-1; Tue, 14 Apr 2026 12:18:48 -0400","by mail-qt1-f200.google.com with SMTP id\n d75a77b69052e-50d8e4c29caso143120841cf.0\n for <gcc-patches@gcc.gnu.org>; Tue, 14 Apr 2026 09:18:48 -0700 (PDT)","from [192.168.50.130]\n (130-44-146-247.s12789.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com.\n [130.44.146.247]) by smtp.gmail.com with ESMTPSA id\n d75a77b69052e-50dd54fcaa4sm109970301cf.20.2026.04.14.09.18.46\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Tue, 14 Apr 2026 09:18:46 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org D5B604BA2E13","OpenDKIM Filter v2.11.0 sourceware.org 5B4444BA2E06"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 5B4444BA2E06","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 5B4444BA2E06","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776183530; cv=none;\n b=xWnIm9aTfNTx9oWnR5/4kxqTVYwWcgl4nqQGIX2QaNjTLxOlv//+fSVacQgcEQALpFIHa0lxDMvJ1uZfslPAQ0qg2yYwOgNQ4zuHN4iQxfGLzPg0VnZbX9CQxcoxRVXkj0N9V2gyX0Cb8xwM08tH0HMpegqBHinLnK6xykgoopA=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776183530; c=relaxed/simple;\n bh=ZpCYi9Ke5NxduX15IQ29OBD+/7Oc3XWsPOmJ7yDaSy0=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=RNLrYyKVeVziIHHn9PR5cKUKLTGW487GKonAMCVKdPE5KFvs8oKZHyHE8c4Zh+7TEYkA4B89DR9w2xtUnN0/5ZQ+UQjy9c48J0RvJjb05t4lHgg2H0PbtPxy/xEYfBWwVzuM3SovkIT6Wwlag/+hyto2b3TYkBUFA2mruPvSSG4=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776183530;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=PGydZkcsVaSRJxJRpJB0FdGk+S/31QUcRQVqKj7r8m0=;\n b=R3f63o4c0GX8q/sje169m7nOWB8GgDaw/nuWu/miEZ6DLRuBtBIo2tABvvUur1flgaoJSe\n FBg+0kBFS3V4eMVwUhKX/exb9yh86KW0WJhSmCFsbIWoiXNwS1X26EBlseurAF0GToqsMS\n dbfnpi7ydBzbtGOwtNrRcxR1EBzVPII=","X-MC-Unique":"hReNZAeuNee2-_J7nS1Ujw-1","X-Mimecast-MFC-AGG-ID":"hReNZAeuNee2-_J7nS1Ujw_1776183528","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776183528; x=1776788328;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:cc:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=PGydZkcsVaSRJxJRpJB0FdGk+S/31QUcRQVqKj7r8m0=;\n b=hbjfarl+6lPu1XbLPt9x/5vYKzOHOoryI1TT1nTsLiVfGy9VQtfWEuKbeFFhPHYEPQ\n Ea9+gLsfuoH3QGFdZwwl3kYeCw74D0RX0Fa6+WZFulMjQNrRfikLejCGZWvaKqtdnIx4\n 7xFFTDoACfl6iewD7XDnzBwUHURJJD7qXGxEia15J18H21OiGfCFxKSGFYPMRx7MJJJ/\n M4Th2od+2eLzOO2opaBdKh16Lp7BCgTaei/VpCrk2cfdb1TTeei5qDA1kNDFuxE8twML\n bDcTDJHWhqU+2Zir1e2DNact49U9gLfgpGm11NPNct0JrQwfrFBDU3D/aXb0Ufj9uZnp\n +HkA==","X-Forwarded-Encrypted":"i=1;\n AFNElJ8Vbu3oByGbk3DD6UxKld9lGxcForfhtgRwEOiuDuVAREbFiyIXEGtzdW30HsSyrjc6Zb3y2SXZO/t49g==@gcc.gnu.org","X-Gm-Message-State":"AOJu0Yyqd9ZAaB0cstVFi1cgdatm6x5D0OwVO74e+ZmKlVQH//7RFCsE\n v+2BmTc6bnRLFPnqqH3GT5E8K62xBFpWIbXcSJ1cp818Rwx/8wOoLBD0TPbMlCgDiMHSLsdpzQ3\n TbhfOSgV44aEfnBQbowBJos7B/qFbd+++BxKJW9Dv2jPnsVgNaYecaG31qRw=","X-Gm-Gg":"AeBDiesoSzkTo6nv/k28N070JujvrgnfapKRsOO1r25C7P0yoXx8W25Ug8j24t79Dv9\n hu2hY2uZgAoZDJ8OxUgGhPKn1qFtFl/3OwjyQgy7jEXRcNIlx/ZCd3y1FTukOiV2EjG1H+pzM/3\n sbxbrQQVQvmvCUcrREHlWKKxAK3TkTZIq03xIvnrEwlG7EcaNEs8CEPYFP03SiB3NjwajhvTjci\n iTYiI1+S4MIPNeMKM2gSCjDw7avuOTtfJsigbsfBVgrBTyjaTaA97lPT1YYwnhp6kxbjXcoD3TB\n wPwCY2TJxJLJb3rBcETeuPXf5X1ydaIuCWr5xVNTnYYK/782FElCEajEXegQcGVeiwk/zg/Ds2G\n 98shAg/bHhV0Ya1ZBFS0qtvGYLI+1dZ7rtgrACtfFZPhO3AwzhVSM94N+S4KVNFWhP4rPdxOHFP\n s++9U8vtuBor3rLX28Wt+pceY4CcL+xZwWPDfcfYEzpA==","X-Received":["by 2002:ac8:5d13:0:b0:50b:4726:f152 with SMTP id\n d75a77b69052e-50dd5b346demr264074651cf.8.1776183528030;\n Tue, 14 Apr 2026 09:18:48 -0700 (PDT)","by 2002:ac8:5d13:0:b0:50b:4726:f152 with SMTP id\n d75a77b69052e-50dd5b346demr264074081cf.8.1776183527441;\n Tue, 14 Apr 2026 09:18:47 -0700 (PDT)"],"Message-ID":"<91d18100-1c43-4075-8b66-4ce2e9d9e835@redhat.com>","Date":"Tue, 14 Apr 2026 12:18:45 -0400","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] c++: Unshare expr in get_template_parm_object [PR124792]","To":"Patrick Palka <ppalka@redhat.com>","Cc":"Jakub Jelinek <jakub@redhat.com>, chzn@mail.ustc.edu.cn,\n gcc-patches@gcc.gnu.org","References":"<15b4a0ee.835e2.19d6ab44456.Coremail.chzn@mail.ustc.edu.cn>\n <58536bff.85d93.19d6cecd862.Coremail.chzn@mail.ustc.edu.cn>\n <0ce6469a-6ef2-2d0a-f9e2-6c54d7caff01@idea>\n <1be00eb4-570e-41af-8349-770940eee76e@redhat.com> <addVcdge2uqtSg2T@tucnak>\n <a59bb4a6-0b88-40c9-b84a-2df21f214704@redhat.com> <adfVRQUvuvgBZXuF@tucnak>\n <f55af3ce-9cea-4538-a93d-251fcb3e0720@redhat.com>\n <89dac1ff-3e56-c9b3-9c56-897d6881a000@idea>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"<89dac1ff-3e56-c9b3-9c56-897d6881a000@idea>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"1aiOgv5aE0f3g1Hv6eyk5tdtcziL9PiYzCFpJ8-ROvU_1776183528","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}},{"id":3677738,"web_url":"http://patchwork.ozlabs.org/comment/3677738/","msgid":"<CAMOnLZYUsrd5DGXBziOY=mt0iZD72fMchJXCkG70oVOUvtZYDg@mail.gmail.com>","list_archive_url":null,"date":"2026-04-15T15:29:56","subject":"Re: [PATCH] c++: Unshare expr in get_template_parm_object [PR124792]","submitter":{"id":78319,"url":"http://patchwork.ozlabs.org/api/people/78319/","name":"Patrick Palka","email":"ppalka@redhat.com"},"content":"👍\n\nPatrick Palka reacted via Gmail\n<https://www.google.com/gmail/about/?utm_source=gmail-in-product&utm_medium=et&utm_campaign=emojireactionemail#app>\n\nOn Tue, Apr 14, 2026 at 12:18 PM Jason Merrill <jason@redhat.com> wrote:\n\n> On 4/14/26 12:15 PM, Patrick Palka wrote:\n> > On Thu, 9 Apr 2026, Jason Merrill wrote:\n> >\n> >> On 4/9/26 12:35 PM, Jakub Jelinek wrote:\n> >>> On Thu, Apr 09, 2026 at 12:07:42PM -0400, Jason Merrill wrote:\n> >>>>> With reflection, we can create the NTTPOs during constant evaluation\n> >>>>> rather than\n> >>>>> after cxx_eval_outermost_constant_expr has unshared those, so later\n> >>>>> processing within the same cxx_eval_outermost_constant_expr call can\n> >>>>> modify\n> >>>>> those not unshared trees.\n> >>>>> Now, from reflect.cc get_template_parm_object is called directly from\n> >>>>> eval_reflect_constant_string (I think not a problem, the argument\n> should\n> >>>>> be\n> >>>>> always STRING_CST in that case), eval_reflect_constant_array (also\n> not\n> >>>>> a problem IMHO, as the outer CONSTRUCTOR is freshly created by\n> >>>>> get_range_elts and what is inside of it is unshared by\n> >>>>>                if (VAR_P (expr))\n> >>>>>                  expr = unshare_expr (DECL_INITIAL (expr));\n> >>>>> ) and then indirectly (convert_reflect_constant_arg ->\n> >>>>> convert_nontype_argument -> create_template_parm_object) from\n> >>>>> within get_range_elts, eval_reflect_constant, eval_reflect_object,\n> >>>>> eval_reflect_function.  So, if we don't do unsharing in\n> >>>>> get_template_parm_object because it is philosophically attractive but\n> >>>>> wastes compile time memory too much when things are usually unshared,\n> >>>>\n> >>>> Actually, I'm not sure it does waste too much memory; a quick check\n> with\n> >>>> -fmem-report shows no difference in the totals on compiling stdc++.h\n> as\n> >>>> C++26.  And since we'd only unshare in the case where we're actually\n> >>>> creating a new variable, it might actually mean less unsharing in the\n> case\n> >>>> of repetitive patterns.\n> >>>>\n> >>>>> (and yet another question is unshare_constructor vs. unshare_expr),\n> >>>>\n> >>>> Or even unshare_expr_without_location (like PR91165) if we unshare in\n> >>>> get_TPO since all occurrences of the same value get the same variable.\n> >>>>\n> >>>> It seems that many places use unshare_constructor to protect against\n> >>>> things\n> >>>> like split_nonconstant_init or cxx_eval_store_expression but not a\n> >>>> modifying\n> >>>> walk_tree like cp_genericize.\n> >>>\n> >>> So, do you want something like the patch below then?\n> >>\n> >> I think so, yes.\n> >\n> > LGTM too, but for GCC 16 shouldn't we go with Jakub's original patch\n> > that is specific to reflection?\n>\n> I don't think this patch has significant risk.\n>\n> Jason\n>\n>","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=TvsGwqXM;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::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=TvsGwqXM","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::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 4fwlTx1nCpz1yHM\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 01:30:59 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id E3B744BA2E14\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 15:30:57 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id E56494BA2E0A\n for <gcc-patches@gcc.gnu.org>; Wed, 15 Apr 2026 15:30:28 +0000 (GMT)","from mail-ed1-f69.google.com (mail-ed1-f69.google.com\n [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-641-34eZcNDfNSq6EW5-knyyKA-1; Wed, 15 Apr 2026 11:30:09 -0400","by mail-ed1-f69.google.com with SMTP id\n 4fb4d7f45d1cf-6714dd276f4so252048a12.2\n for <gcc-patches@gcc.gnu.org>; Wed, 15 Apr 2026 08:30:09 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org E3B744BA2E14","OpenDKIM Filter v2.11.0 sourceware.org E56494BA2E0A"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org E56494BA2E0A","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org E56494BA2E0A","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776267029; cv=none;\n b=EHv/l3PQ4aIalQd3O001Cy/S1xtPeJhvLINhOTFw6yyaJG2E51MqMzCLYR/qKGa5sEk0emmB0PQFE0UFYFybnnRliGojWaM/N2BOxeCtuYWEc5KcKqabCDzQbmmuaMuIopsavspcIEF0tzIiFkAcJI8En4Fworf5F8AWt0jEvpI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776267029; c=relaxed/simple;\n bh=BSrMVUghu8WzXQ/iN4vm6l98UJSY0pKtgU5zg0Ftlug=;\n h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To;\n b=HmG4zDRUZz86ycUKxK1VKojkEfaOXKVUguoZ6K/tFkb3Fd5x7MZFdsOmfQqedH5fd5PMuARHTRMFlG41s0j5Tzg2HTXQ+3qHDrkAo9nYBByB02qArMW6fXDHoprX2q5YXblsBAMtIYerldltCpo4RH91unZQS7Xn/2fKdIsqaL8=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776267028;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=QwJVf+9fjatJnmsjdpO32Owe1gL8V5uANXbZ1gx0zPc=;\n b=TvsGwqXMPRR0/GjqYUmrM/w456dTYYiqNqWZA41c3LrODBeyr9IHRR/YFN91jTSaLPyqk+\n Pa958wFRq2yaaGaaJjVyt+NS/scHrxmPosvTYbTEtBt9TMZjuaplFx4cHHnrmDnKEiY9uf\n jyTzDr+uJwM8sKGmifxKmMuROB1JcMI=","X-MC-Unique":"34eZcNDfNSq6EW5-knyyKA-1","X-Mimecast-MFC-AGG-ID":"34eZcNDfNSq6EW5-knyyKA_1776267009","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776267008; x=1776871808;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=QwJVf+9fjatJnmsjdpO32Owe1gL8V5uANXbZ1gx0zPc=;\n b=aJnPXDpdFU15Cnqn3NUC+I3zvY+zijVSh8BdXm3TjUU2cgOxRiT296uJ4zCjPV68aN\n OXcOYaidqPnhuy+76uT80XVXD2UPG+de+pWwbR73VPEGoSmiDs7Tl39wg1nI0geSehlo\n dXS+7ka23HfatX7N9qc4JmUHHl/0K8mLiBetbM4qbx13dVFKedIrAqs0dG4JJi/OzXfl\n lkGyL1RYJ6U84e+5Qn1EIxD6O1MSaHqZ4pfr+xGzD2cSj9QxXwATs5cKXntGjVN/u14+\n uEnKzXZ9Jxq2yPP5cpzElFqMEtpV+C1cAPFKnvWi5E75vDMIbdDlBNVFQus3g4Y399Ix\n 5YJw==","X-Forwarded-Encrypted":"i=1;\n AFNElJ+KnVR/zfYZR0NSRSEksu4BaE24Fc+1P4IYPBcPxH7ird1+ByOkkoKKJFk0yQvTHMZRBjRxK3hmWWydHw==@gcc.gnu.org","X-Gm-Message-State":"AOJu0YwEVdA96iCtkoIpCq6bnssaBiOkgrRCPgh7dDH3OqP++Y1Q7bHF\n COOF9IEp/3AR2Gd5xpj/aW71PD6Oqd0csGec2WhXHOvXfuqWPBz06/hOegq7UOKzeS3RfUE+0Go\n 2VwT6vn5757N7FVV7j0yGlNleSY4+1dIpBwIvu150QGA+TmApaQuJdAYqpGJ40xltcdvVAkDU8H\n O4Npoe6bRaeqBdHxv7w0g/2iXcSbeN5rM7NE96A/i8BzTTIAtsQy4BPMrK92GCiRN0pC4AjmL28\n g==","X-Gm-Gg":"AeBDies0XcVPkCJlJm0Nd26+z5anrV7BwGeWT6YIyrSfz7tdQKsNtR80JoGxGMfaEe8\n HschIpClMQnEneXfGwNkva2R0bj+LtwlBs5ibZXk2KfonY38ZHA9gzH4L0lTRlPPJeWL2wlIuDP\n es8A59sgv+5Hiv/o8YWg2K5iDHGtCSj4ct/6w2L5FIhAx0M3MnQImamb916kFjMtUn3wGktB7aS\n upNxkX57AhC+AhgAFQWFE/+nC9bDS6af2JEosw=","X-Received":["by 2002:a05:6402:1eca:b0:66b:3e6c:4772 with SMTP id\n 4fb4d7f45d1cf-672378659d0mr779391a12.3.1776267008395;\n Wed, 15 Apr 2026 08:30:08 -0700 (PDT)","by 2002:a05:6402:1eca:b0:66b:3e6c:4772 with SMTP id\n 4fb4d7f45d1cf-672378659d0mr779372a12.3.1776267007845; Wed, 15 Apr 2026\n 08:30:07 -0700 (PDT)"],"MIME-Version":"1.0","References":"<15b4a0ee.835e2.19d6ab44456.Coremail.chzn@mail.ustc.edu.cn>\n <58536bff.85d93.19d6cecd862.Coremail.chzn@mail.ustc.edu.cn>\n <0ce6469a-6ef2-2d0a-f9e2-6c54d7caff01@idea>\n <1be00eb4-570e-41af-8349-770940eee76e@redhat.com>\n <addVcdge2uqtSg2T@tucnak> <a59bb4a6-0b88-40c9-b84a-2df21f214704@redhat.com>\n <adfVRQUvuvgBZXuF@tucnak> <f55af3ce-9cea-4538-a93d-251fcb3e0720@redhat.com>\n <89dac1ff-3e56-c9b3-9c56-897d6881a000@idea>\n <91d18100-1c43-4075-8b66-4ce2e9d9e835@redhat.com>","In-Reply-To":"<91d18100-1c43-4075-8b66-4ce2e9d9e835@redhat.com>","From":"Patrick Palka <ppalka@redhat.com>","Date":"Wed, 15 Apr 2026 11:29:56 -0400","X-Gm-Features":"AQROBzAFqAOT-PQP_cTwY2j1ETFaPh-1QmfbDDS2cEcU04mS_N5yuiN9kqQbaC0","Message-ID":"\n <CAMOnLZYUsrd5DGXBziOY=mt0iZD72fMchJXCkG70oVOUvtZYDg@mail.gmail.com>","Subject":"Re: [PATCH] c++: Unshare expr in get_template_parm_object [PR124792]","To":"Jason Merrill <jason@redhat.com>","Cc":"Jakub Jelinek <jakub@redhat.com>, chzn@mail.ustc.edu.cn,\n gcc-patches@gcc.gnu.org","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"ew_iSpT-jXBIGh2Hvg1j2ao1_a8yvxBRbm_rIRgEADM_1776267009","X-Mimecast-Originator":"redhat.com","Content-Type":"multipart/alternative; boundary=\"000000000000077aa3064f8164ff\"","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>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]