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 00E9B3858C66 for ; Mon, 15 May 2023 14:41:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00E9B3858C66 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=1684161677; h=from:from: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=TXtMCfvvfH+q4ZfLGg0C0U8Ngrw9B5frR54aQALOAIU=; b=TPbd/6jOIgsWeyjaZn7plstWpn1aFsY3wdZYMviXgCxh2vOdeh+OoYnaecUVI3W6j6XzDM a7C8Gj3VlswFM8KAbAPVxgT9nRl4TuF2Zo7WSdvA9UKP5JV5r7xgtp7t/WBRCV/ZrAA8SV LbIjto9hUMmwUjvV5qZG23zltKv7Bf4= 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-582-MIz7w7-0PT-v2fGYQX2L0g-1; Mon, 15 May 2023 10:41:16 -0400 X-MC-Unique: MIz7w7-0PT-v2fGYQX2L0g-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-3f533a580a2so8490461cf.3 for ; Mon, 15 May 2023 07:41:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161675; x=1686753675; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TXtMCfvvfH+q4ZfLGg0C0U8Ngrw9B5frR54aQALOAIU=; b=WAv8mxnjlk2do1RfWvmmkWMLx57hvgX+V2smaLV67uwkTLPRZZYP7aufQHtIdML9JW a2zylM/1GpR0Pca5dzePAPI3xaSOUbuDDb76i+PiW9POZSt2sCLGzNUfurPglqXN3598 QWdMA4ZYwUIrqeGXsluBh4MVQfQTvWhURxiqapTsGPr5/rTb20qE4Gz+BTs0XHGKgP+g kHoytguREzoqh28G/XksMrxoCT8FXC+CA/ZGRzFUuFGQXfaUWc+RL25251Sy8msMogYI P/YTRrQqPiaYTWF/Wv3Ke0zLihiUzHH5k+TakaGt3Gw/UAhvSYjyjUyNk8v4+N+2ch+H MnUg== X-Gm-Message-State: AC+VfDx5umnHh0XH8E1J7hfI86axmNryR7JsMvTOQVqzPBEUdCHjVdnu cEJf/GtdPkXUwS/XyYArh86OJvFh+eApTHVgkoYSWGxqyT2oEuwxZL64c8E/Em2F8Y4dxSqqd7y HXp7Qus9eBY0qWbJTUw== X-Received: by 2002:a05:622a:2d4:b0:3f3:8b74:dee1 with SMTP id a20-20020a05622a02d400b003f38b74dee1mr46147859qtx.43.1684161675366; Mon, 15 May 2023 07:41:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4FRffDGdMeGjx9yFcBdQSTWie98pW/H9RPyCtIVubFY6/wSZ2HKLUXqek48633097rW0a+ug== X-Received: by 2002:a05:622a:2d4:b0:3f3:8b74:dee1 with SMTP id a20-20020a05622a02d400b003f38b74dee1mr46147823qtx.43.1684161675035; Mon, 15 May 2023 07:41:15 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id u3-20020ae9c003000000b0074df476504asm7290393qkk.61.2023.05.15.07.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:41:14 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 15 May 2023 10:41:13 -0400 (EDT) To: Jason Merrill cc: gcc-patches@gcc.gnu.org Subject: Re: [pushed] c++: fix TTP level reduction cache In-Reply-To: <20230503043023.2076907-1-jason@redhat.com> Message-ID: <49821b58-e4dd-a41e-122f-08ac92d3da99@idea> References: <20230503043023.2076907-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_PORT 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 Wed, 3 May 2023, Jason Merrill via Gcc-patches wrote: > Tested x86_64-pc-linux-gnu, applying to trunk. > > -- 8< -- > > We try to cache the result of reduce_template_parm_level so that when we > reduce the same parm multiple times we get the same result, but this wasn't > working for template template parms because in that case TYPE is a > TEMPLATE_TEMPLATE_PARM, and so same_type_p was false because of the same > level mismatch that we're trying to adjust for. So in that case compare the > template parms of the template template parms instead. > > The result can be seen in nontype12.C, where we previously gave three > duplicate errors on line 7 and now give only one because subsequent > substitutions use the cache. > > gcc/cp/ChangeLog: > > * pt.cc (reduce_template_parm_level): Fix comparison of > template template parm to cached version. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/nontype12.C: Check for duplicate error. > --- > gcc/cp/pt.cc | 7 ++++++- > gcc/testsuite/g++.dg/template/nontype12.C | 3 ++- > 2 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 471fc20bc5b..5446b5058b7 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -4550,7 +4550,12 @@ reduce_template_parm_level (tree index, tree type, int levels, tree args, > if (TEMPLATE_PARM_DESCENDANTS (index) == NULL_TREE > || (TEMPLATE_PARM_LEVEL (TEMPLATE_PARM_DESCENDANTS (index)) > != TEMPLATE_PARM_LEVEL (index) - levels) > - || !same_type_p (type, TREE_TYPE (TEMPLATE_PARM_DESCENDANTS (index)))) > + || !(TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM > + ? (comp_template_parms > + (DECL_TEMPLATE_PARMS (TYPE_NAME (type)), > + DECL_TEMPLATE_PARMS (TEMPLATE_PARM_DECL > + (TEMPLATE_PARM_DESCENDANTS (index))))) Isn't this comparing the unsubstituted/unlowered template parameters of the ttp vs the substituted/lowered template parameters? So this test should always return false because the depth of the two sets of tparms will always be different. I'm surprised then that this has an effect for g++.dg/template/nontype12.C. Ah, seems it's because compare_template_parms returns true if either set of template parameters contains error_mark_node, for sake of error recovery. In this case, the two sets of template parameters for the ttp in template class> int bar(); are 3 D.2778, 2 , 1 T [original template parameters] 2 <<< error >>>, 1 [substituted/lowered via T=double] where the error_mark_node is due to double not being a valid template parameter before C++20. Perhaps we should be comparing only the innermost parameters instead? That way the test will work in non-erroneous cases for at least for ttps with non-dependent template parameters. We might also want to consider caching the TEMPLATE_TEMPLATE_PARM node as well, by adjusting the hunk in 'tsubst': pt.cc:16234 if (TREE_CODE (t) == TEMPLATE_TYPE_PARM && (arg = TEMPLATE_TYPE_PARM_INDEX (t), r = TEMPLATE_PARM_DESCENDANTS (arg)) && (TEMPLATE_PARM_LEVEL (r) == TEMPLATE_PARM_LEVEL (arg) - levels)) /* Cache the simple case of lowering a type parameter. */ r = TREE_TYPE (r); > + : same_type_p (type, TREE_TYPE (TEMPLATE_PARM_DESCENDANTS (index))))) > { > tree orig_decl = TEMPLATE_PARM_DECL (index); > > diff --git a/gcc/testsuite/g++.dg/template/nontype12.C b/gcc/testsuite/g++.dg/template/nontype12.C > index e37cf8f7646..6642ffd0a13 100644 > --- a/gcc/testsuite/g++.dg/template/nontype12.C > +++ b/gcc/testsuite/g++.dg/template/nontype12.C > @@ -4,7 +4,8 @@ > template struct A > { > template int foo(); // { dg-error "double" "" { target c++17_down } } > - template class> int bar(); // { dg-error "double" "" { target c++17_down } } > + template class> int bar(); // { dg-bogus {double.*C:7:[^\n]*double} } > + // { dg-error "double" "" { target c++17_down } .-1 } > template struct X; // { dg-error "double" "" { target c++17_down } } > }; > > > base-commit: d7cb9720ed54687bd1135c5e6ef90776a9db0bd5 > -- > 2.31.1 > >