Message ID | 20230503043023.2076907-1-jason@redhat.com |
---|---|
State | Repeat Merge |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1070108vqo; Tue, 2 May 2023 21:31:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4BIUG/OfPPz8DW2/M+hqEK9PElE7gM4qikUYEA2sKyD3tRMD+uRJHDRPXzrtamJMh7lEoJ X-Received: by 2002:a17:907:368b:b0:94e:547b:6322 with SMTP id bi11-20020a170907368b00b0094e547b6322mr1985312ejc.25.1683088276941; Tue, 02 May 2023 21:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683088276; cv=none; d=google.com; s=arc-20160816; b=AfA2CbuymjyT/9FvKY/Q4LMA4cWuaEd5rSKx2x+rANN80I89hbl/vo6bADEpoWnxQS XbPZUc47k32iXL+kcKMDYePRyZy/FV4krQFZbKMaJDSnoSPGsArep+Z8GDa3aaHnaZkj uEONV5qo71DJ60jI5CJ8fjrip+tz9ur2grpxlt0iOOdT/HBkSN0X8d8UUaJSWKAYeA+K rx+NWplC7uMpEtnZN0Wsk0Xc4PvOKsrSu/En1wRZRNXKmtUD0C9nI3WKz2zaNiIhDgCi Y33/q1j+OOsPF3bDUH9IhiikFbY6MGOeLHkGwK+ZZ3h9uQGtiYRpp0F2YCCAozUihwjD Y+QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=KczPAlviS7xWxGZbTh2l0soCmohX7oJ7BPcfBEpuh/Y=; b=upsSDI/7yGv7raQxrWzv5qHM5pO0W5V0DUZoHc5MMiURhjDckIA/wa1GDAnjbEZSOb BQQ/grFcIODAmlX6rIiCN0MTj6RCCAv/3tKqloIY6McwMC8plvcgNq8q7tVX+lFeJEbJ U3LFPebVTbgNwiPavS3esndu6p8CoDxstiFAGrBB+gQqpyzUEA1NEL+e5VEVUevvnm71 JpkbcZz0vLCM5QAzKUA563XqaIEJzf+IPmWeKz13SUtzr/7ka454A2P5+hnHjibE1HgC NdKAU/TtVTxloMix8T7Ia3N3mjMd0YXWNaBZ5LOu9Vb6UsMn+Aqmd2PqFty23M8wSCEI ZNVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=n4f1z9zK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ji14-20020a170907980e00b0095847a3cd83si23361709ejc.874.2023.05.02.21.31.16 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 21:31:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=n4f1z9zK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4B1F3858434 for <ouuuleilei@gmail.com>; Wed, 3 May 2023 04:31:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4B1F3858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683088275; bh=KczPAlviS7xWxGZbTh2l0soCmohX7oJ7BPcfBEpuh/Y=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=n4f1z9zKnDPK+7HLNs4XD9OwKv8UhvuIU34OF+wzbcKuPFweM+VvOM6Aj30qikYlg wb01ei11+peLSlMx90lBL9hUHCXgDTU5qR9AqXM933mIC9H3F/ffTf/ETHVui4T7WK 0GZffumDDVDhK0Bqn4F8YUcutNq5pEhbAQqQ9JRI= 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 ESMTPS id 8A3E93858D20 for <gcc-patches@gcc.gnu.org>; Wed, 3 May 2023 04:30:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A3E93858D20 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-475-LBOdwXNyOf-s_pIi7m132Q-1; Wed, 03 May 2023 00:30:29 -0400 X-MC-Unique: LBOdwXNyOf-s_pIi7m132Q-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3ef33ed8843so25437781cf.1 for <gcc-patches@gcc.gnu.org>; Tue, 02 May 2023 21:30:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683088229; x=1685680229; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KczPAlviS7xWxGZbTh2l0soCmohX7oJ7BPcfBEpuh/Y=; b=SvocZ7Hc5biOTWZOkyBx9JXroPSSw8b5MB/m2O8btjnZb4zVio1y2V6bHnab/b8oJs 6NW14NZlCnL3ns4HryYnXdHCW8nOOTFFGYlceEH6lhKiJVZpwwgFeDLYoUAhx2uXMTQi xKmNTfHAQhF77XBpPdwEKntrUne7/P6jX53SW+Inp1P5JptBcJNiixqF2SbTsB/c/s++ 2dZ84aM927crIg1Bt2g5qWkSb7WGWYLDIfAvjDsUm34lOeLaevcUgGPptvFn6bukjAQN x06IzlbvLldDSycuNn02TugqAPY5m62PrYlZmShMWkMk0s2+l8FSuvk2sF1BnSzI83qe KRkg== X-Gm-Message-State: AC+VfDyHgfi3feQOmICbn/v35YBR7AqN/2ZRzqJw0y+iw/3ozmv4sdLq 6wJnVJtVbfj20qOFu3Dp8up0e+IPEFuckpWSwFS+blgIqDbwIa5yV6CISDVXu5NWJQ99X7sKSF3 OCW8IoARK8XVV7fT3IxykEZfKfXwN6dnnLZGycPGYlSIzCEdnwTh/609DsoegLxsmeASGJK0O4g == X-Received: by 2002:ac8:5a03:0:b0:3f0:a3b6:7c32 with SMTP id n3-20020ac85a03000000b003f0a3b67c32mr28303389qta.46.1683088228999; Tue, 02 May 2023 21:30:28 -0700 (PDT) X-Received: by 2002:ac8:5a03:0:b0:3f0:a3b6:7c32 with SMTP id n3-20020ac85a03000000b003f0a3b67c32mr28303371qta.46.1683088228557; Tue, 02 May 2023 21:30:28 -0700 (PDT) Received: from jason.com (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 e21-20020ac84b55000000b003ef2c959d1bsm10920332qts.67.2023.05.02.21.30.27 for <gcc-patches@gcc.gnu.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 21:30:27 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: fix TTP level reduction cache Date: Wed, 3 May 2023 00:30:23 -0400 Message-Id: <20230503043023.2076907-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.9 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <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>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Jason Merrill via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jason Merrill <jason@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764845973115772783?= X-GMAIL-MSGID: =?utf-8?q?1764845973115772783?= |
Series |
[pushed] c++: fix TTP level reduction cache
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jason Merrill
May 3, 2023, 4:30 a.m. UTC
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(-) base-commit: d7cb9720ed54687bd1135c5e6ef90776a9db0bd5
Comments
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<template<T> 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<typename T> struct A > { > template<T> int foo(); // { dg-error "double" "" { target c++17_down } } > - template<template<T> class> int bar(); // { dg-error "double" "" { target c++17_down } } > + template<template<T> class> int bar(); // { dg-bogus {double.*C:7:[^\n]*double} } > + // { dg-error "double" "" { target c++17_down } .-1 } > template<T> struct X; // { dg-error "double" "" { target c++17_down } } > }; > > > base-commit: d7cb9720ed54687bd1135c5e6ef90776a9db0bd5 > -- > 2.31.1 > >
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))))) + : 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<typename T> struct A { template<T> int foo(); // { dg-error "double" "" { target c++17_down } } - template<template<T> class> int bar(); // { dg-error "double" "" { target c++17_down } } + template<template<T> class> int bar(); // { dg-bogus {double.*C:7:[^\n]*double} } + // { dg-error "double" "" { target c++17_down } .-1 } template<T> struct X; // { dg-error "double" "" { target c++17_down } } };