From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E943E3858C53 for ; Mon, 17 Apr 2023 22:11:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E943E3858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681769472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6eQ8QS3sgnN7+ezFlDV3SV22O0Qz7lzGrCskLt7MBHE=; b=fO4tBKIKnoF49Bqy8TSk+qQ/KDkqoZcUrF46k0iLSUF+887jH4GA579NkbNiUSIVRNAfdl oQGUb+vzFX0DrksIzkVnzBR2bFuWuhQTiCwbVoX/Ko29y/nZ1tvMsEUz9ox9qTOaLtpknt WLowhyFpl23yGPvwJ6iTL6cxsxwhrQU= 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-636-Ide8QGNRPgiMTA5AyMRHUw-1; Mon, 17 Apr 2023 18:11:11 -0400 X-MC-Unique: Ide8QGNRPgiMTA5AyMRHUw-1 Received: by mail-qt1-f198.google.com with SMTP id f36-20020a05622a1a2400b003deb2fa544bso19147637qtb.0 for ; Mon, 17 Apr 2023 15:11:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681769470; x=1684361470; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6eQ8QS3sgnN7+ezFlDV3SV22O0Qz7lzGrCskLt7MBHE=; b=djouGU+vJJN7lx4Rn6y29RrsfJmXzA2MHjFL8VUGbDo5mNiV1tnzaw8GmApNSFGiCv w8YnRBvlr67HEsTRoUMl3ftr9k5tYOjF/15Ht3Eegho30tWtvadaNTwi9XwkANwxRILg 2AcTxz9MoWFh96D+3woW8SPBPeb0nWpCSH8XJvpCEGz/EWhFRbBkJLhJLdPMcAW29gdo 88z2cBShcWRP1h4pmNXvZdTHTSH2a7o7KNfXWTNYxPzaeaoXja5Mb/vts5RcClj5nZNg R2OOfCFV/jndi4jW/rjwyQ9uxIuOGYKAf0D9QHtkpCn1a0BOAgQMcA2lqAHNYatxH0a6 3Bgg== X-Gm-Message-State: AAQBX9eXhg6AJ3HxRA2vUAmdwNwd7y51jN6VkwzUVmGy62USFFdqTkcE Y5KBey5IBE6YfzKBD6VyD/i06PorteBvXnFJpNMkc/TnbyLOFw8rI4O2slTT6N2U9nWZr0s9RX1 OFMyRmWwZ0fT9QXo+yA== X-Received: by 2002:a05:622a:253:b0:3e9:15fa:791a with SMTP id c19-20020a05622a025300b003e915fa791amr25770286qtx.27.1681769470508; Mon, 17 Apr 2023 15:11:10 -0700 (PDT) X-Google-Smtp-Source: AKy350adSII5Ipe8G3YefD7dDQ6Ta3g6mMeSqth1pSEyi6wYNbWUbwjaX7iZlgwlvmq4gjG1nvGzJg== X-Received: by 2002:a05:622a:253:b0:3e9:15fa:791a with SMTP id c19-20020a05622a025300b003e915fa791amr25770252qtx.27.1681769470194; Mon, 17 Apr 2023 15:11:10 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id a29-20020a05620a439d00b0074de75f783fsm1475544qkp.26.2023.04.17.15.11.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Apr 2023 15:11:09 -0700 (PDT) Message-ID: <79e922cf-a6cb-99f7-6f91-03e85697e53a@redhat.com> Date: Mon, 17 Apr 2023 18:11:08 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] c++: bound ttp level lowering [PR109531] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20230417184419.4043285-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230417184419.4043285-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 List-Id: On 4/17/23 14:44, Patrick Palka wrote: > Here when level lowering the bound ttp TT via the > substitution T=C, we're neglecting to canonicalize (and therefore strip > of simple typedefs) the resulting template arguments {A} before > determining its new canonical type via hash table lookup. This leads to > an a hash mismatch ICE for the two equivalent types TT and TT> > since iterative_hash_template_arg misbehaves for a non-canonicalized type > argument. > > We can fix this by canonicalizing or coercing the substituted arguments > directly, but given that creation and ordinary substitution of bound > ttps both go through lookup_template_class, which in turn performs > coercion/canonicalization, it seems best to make this code path go > through lookup_template_class as well. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk/13? OK. > PR c++/109531 > > gcc/cp/ChangeLog: > > * pt.cc (tsubst) : > In the level-lowering case just use lookup_template_class > to rebuild the bound ttp. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/canon-type-20.C: New test. > * g++.dg/template/ttp36.C: New test. > --- > gcc/cp/pt.cc | 39 ++++++++++--------- > gcc/testsuite/g++.dg/template/canon-type-20.C | 18 +++++++++ > gcc/testsuite/g++.dg/template/ttp36.C | 12 ++++++ > 3 files changed, 50 insertions(+), 19 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/template/canon-type-20.C > create mode 100644 gcc/testsuite/g++.dg/template/ttp36.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index fcc8e0d1d57..e065ace5c55 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -16232,7 +16232,6 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) > { > case TEMPLATE_TYPE_PARM: > case TEMPLATE_TEMPLATE_PARM: > - case BOUND_TEMPLATE_TEMPLATE_PARM: > if (cp_type_quals (t)) > { > r = tsubst (TYPE_MAIN_VARIANT (t), args, complain, in_decl); > @@ -16274,24 +16273,6 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) > only instantiated during satisfaction. */ > PLACEHOLDER_TYPE_CONSTRAINTS_INFO (r) = ci; > > - if (code == BOUND_TEMPLATE_TEMPLATE_PARM) > - { > - tree tinfo = TYPE_TEMPLATE_INFO (t); > - /* We might need to substitute into the types of non-type > - template parameters. */ > - tree tmpl = tsubst (TI_TEMPLATE (tinfo), args, > - complain, in_decl); > - if (tmpl == error_mark_node) > - return error_mark_node; > - tree argvec = tsubst (TI_ARGS (tinfo), args, > - complain, in_decl); > - if (argvec == error_mark_node) > - return error_mark_node; > - > - TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (r) > - = build_template_info (tmpl, argvec); > - } > - > if (TYPE_STRUCTURAL_EQUALITY_P (t)) > SET_TYPE_STRUCTURAL_EQUALITY (r); > else > @@ -16299,6 +16280,26 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) > } > break; > > + case BOUND_TEMPLATE_TEMPLATE_PARM: > + { > + tree tinfo = TYPE_TEMPLATE_INFO (t); > + /* We might need to substitute into the types of non-type > + template parameters. This also lowers the level of > + the ttp appropriately. */ > + tree tmpl = tsubst (TI_TEMPLATE (tinfo), args, > + complain, in_decl); > + if (tmpl == error_mark_node) > + return error_mark_node; > + tree argvec = tsubst (TI_ARGS (tinfo), args, > + complain, in_decl); > + if (argvec == error_mark_node) > + return error_mark_node; > + r = lookup_template_class (tmpl, argvec, in_decl, NULL_TREE, > + /*entering_scope=*/false, complain); > + r = cp_build_qualified_type (r, cp_type_quals (t), complain); > + break; > + } > + > case TEMPLATE_PARM_INDEX: > /* OK, now substitute the type of the non-type parameter. We > couldn't do it earlier because it might be an auto parameter, > diff --git a/gcc/testsuite/g++.dg/template/canon-type-20.C b/gcc/testsuite/g++.dg/template/canon-type-20.C > new file mode 100644 > index 00000000000..e40261037e5 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/canon-type-20.C > @@ -0,0 +1,18 @@ > +// PR c++/109531 > +// { dg-do compile { target c++11 } } > +// { dg-additional-options "--param=hash-table-verification-limit=1000" } > + > +template > +using A = int; > + > +struct B { using type = int; }; > +struct C { using type = A; }; > + > +template > +struct D { > + template class TT> > + TT f (); > +}; > + > +template struct D; > +template struct D; > diff --git a/gcc/testsuite/g++.dg/template/ttp36.C b/gcc/testsuite/g++.dg/template/ttp36.C > new file mode 100644 > index 00000000000..2df00855cf7 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/ttp36.C > @@ -0,0 +1,12 @@ > +// Verify we propagate cv-quals when level-lowering a bound ttp. > + > +template > +struct B { > + template class TT> > + void f(const TT *); > + > + template class TT> > + void f(TT *); // { dg-bogus "cannot be overloaded" } > +}; > + > +template struct B;