From patchwork Sun Sep 17 19:13:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 141183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2266960vqi; Sun, 17 Sep 2023 12:14:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8hFCggZIQgA8QZd9Ae6QmRLRGdexepJEi2GFeFdlVHopLCVnJhAfLEflo2FUA7vnmqUJQ X-Received: by 2002:a17:907:6091:b0:9aa:1794:945b with SMTP id ht17-20020a170907609100b009aa1794945bmr15839985ejc.22.1694978047040; Sun, 17 Sep 2023 12:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694978047; cv=none; d=google.com; s=arc-20160816; b=FIAz2TcbMIxWxUukZWShn3pSEEr4mheymbGaZ11SGf/sB8fLgnbw4wWZ3p16Ba1HJN 6VqK3qGpoIVP9TC9pCfcczOwzxOi192094Jp8zw8tGFBKJHLHMYPTP52SXirYomID2YI 6afanEDwa4O1o3qnCK4V38GkGW0/c7HIGTj7JrG0PCVO+ocWD4R5h7VGDG/bEDglqA31 dl1CEJOf8nYn+9/eyE2q7alQt9C4pM1xMnas7+A27wCFBXURjYoK7NX2rInM4PyK7JZX 6D7hRH8OWGXC2x6Hek63frRO1B60lHjM8sPH9Ba0w0yzyYNlyJT7ebUQGXHMRwFvBDNZ l8Jw== 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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=zEYXPmEpH2T3sC+ZXw8Tv0MX8PWBGXUC76SMSpqgUgc=; fh=1Hi9m88IqcWZGtfSxUrMGG+GBgL26N02X1SANXM6iTs=; b=MHeWgVvoJwt+npxP7jXlcyW01qQbxbsvpEJOaksRfizjoA04EDlqkJmSjRSQxPFKXb zjbNGAjiJHpPPaoxX5xWoHbL1mfL3TvUjj6jrTXXtiByieQVs/XqUNkBpCBOqB9FPirS C/FwGhpI5SlrcUSDUer/gWAD1w5xDhepmc//1+Oem+EJZrkXNA1f7HrCNB+/2I7PKxqv qhFyfAcFtIcsWOoIdaLyzkXYUrfJ3hvodgPtIBGMtN2iFs/h25KBerriOj2hDVBSC2Zk 38uw25x9mliJBDSdNkMoLKSAIaDn1PCKFMP+iR3eEHos8gCGscqMAvi5krwVejPBo6IS Jl7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=md8oJ6KF; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y14-20020a170906470e00b00997e79e646esi6612029ejq.557.2023.09.17.12.14.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 12:14:07 -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=md8oJ6KF; 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 F202D3858433 for ; Sun, 17 Sep 2023 19:14:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F202D3858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694978046; bh=zEYXPmEpH2T3sC+ZXw8Tv0MX8PWBGXUC76SMSpqgUgc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=md8oJ6KFwDx4QQjD5rakeDulMyHLHuHdsZc7En6hll2RzvYCzNSujWiAgxK1bKbGS RPXyHIIYoF1LfccWpM8vwsrJ2Owd/6km/Hoj3dCZmI6OmqioVu+mAMi1Ds6JJwS7pY FxSsywey8Qh9smPlENNaf8fnZmlJ0VcRDd29YsCg= 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 386EA3858D32 for ; Sun, 17 Sep 2023 19:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 386EA3858D32 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-671-kEJramC8PficLwXoPmw_dA-1; Sun, 17 Sep 2023 15:13:17 -0400 X-MC-Unique: kEJramC8PficLwXoPmw_dA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-773b05dfd4eso355457585a.2 for ; Sun, 17 Sep 2023 12:13:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694977996; x=1695582796; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zEYXPmEpH2T3sC+ZXw8Tv0MX8PWBGXUC76SMSpqgUgc=; b=iftGS8U6Bi9vl3IevugguBMSdY/VUlheu52ByLPNCfLUwN8v1GGdkiL1aZc4uOAYvb 0WGBBtI8H6f3kNse1Fcg9w3QC+EDTU3lVna490H/GAeHQiGCoC+Y+pRb3e+6nS5zshek zig/xsu/IyuXCH/rETx6+xtCxqhU9d3h1Gl4vjNxrQP+/l1snqugZl/CfPgYqtSZ8RFd aE+YDA7t4tFrsiCYTlntxTcY7eU5YRDvpbAKJRMUPx4to7+tS/+l4nS/lY+HANfp94FT 5QcVANNI3inXW8tDxdGBqMmwlAEz0w+4PF7l5/28zTVZAyHC5H2yvV21WIGObxNfDBTS lgBg== X-Gm-Message-State: AOJu0YznH6Al6FXnKsnt6LF1G5v/s5uDRLQC9mKu4EuJYheSC7uiOy0o yHA2EaIOrbW8qhfq6P4kI+HqSSsIG/euSWrzjhDqR0eVu6gGl6Nu32H20k9uQwOIxQ5uD65q2jp 0q7yG8qtDbq2PldpT5maDsQU7UA3BtMr+nspX95KmrYISUZCDQ+H9q9zOdVCd78VROgfnQ2P824 E= X-Received: by 2002:a05:620a:1908:b0:767:797b:4115 with SMTP id bj8-20020a05620a190800b00767797b4115mr7820900qkb.60.1694977996449; Sun, 17 Sep 2023 12:13:16 -0700 (PDT) X-Received: by 2002:a05:620a:1908:b0:767:797b:4115 with SMTP id bj8-20020a05620a190800b00767797b4115mr7820885qkb.60.1694977996119; Sun, 17 Sep 2023 12:13:16 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id 27-20020a05620a079b00b00767b24f68edsm2658092qka.62.2023.09.17.12.13.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 12:13:15 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: optimize tsubst_template_decl for function templates Date: Sun, 17 Sep 2023 15:13:04 -0400 Message-ID: <20230917191304.1483576-1-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.216.gbda494f404 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777313300858026684 X-GMAIL-MSGID: 1777313300858026684 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- r14-2655-g92d1425ca78040 made instantiate_template avoid redundantly performing a specialization lookup when instantiating a function or alias template. This patch applies the same optimization to tsubst_template_decl when (partially) instantiating a function template, which allows us to remove a check from register_specialization since tsubst_function_decl no longer calls register_specialization for a function template partial instantiation. gcc/cp/ChangeLog: * pt.cc (register_specialization): Remove now-unnecessary early exit for FUNCTION_DECL partial instantiation. (tsubst_template_decl): Pass use_spec_table=false to tsubst_function_decl. Set DECL_TI_ARGS of a non-lambda FUNCTION_DECL specialization to the full set of arguments. Simplify register_specialization call accordingly. gcc/testsuite/ChangeLog: * g++.dg/template/nontype12.C: Expect two instead of three duplicate diagnostics for A::bar() specialization. --- gcc/cp/pt.cc | 29 +++++++---------------- gcc/testsuite/g++.dg/template/nontype12.C | 1 - 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c311a6b88f5..a0296a1ea16 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -1507,21 +1507,6 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend, || (TREE_CODE (tmpl) == FIELD_DECL && TREE_CODE (spec) == NONTYPE_ARGUMENT_PACK)); - if (TREE_CODE (spec) == FUNCTION_DECL - && uses_template_parms (DECL_TI_ARGS (spec))) - /* This is the FUNCTION_DECL for a partial instantiation. Don't - register it; we want the corresponding TEMPLATE_DECL instead. - We use `uses_template_parms (DECL_TI_ARGS (spec))' rather than - the more obvious `uses_template_parms (spec)' to avoid problems - with default function arguments. In particular, given - something like this: - - template void f(T t1, T t = T()) - - the default argument expression is not substituted for in an - instantiation unless and until it is actually needed. */ - return spec; - spec_entry elt; elt.tmpl = tmpl; elt.args = args; @@ -14663,7 +14648,7 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, tree in_decl = t; tree spec; tree tmpl_args; - tree full_args; + tree full_args = NULL_TREE; tree r; hashval_t hash = 0; @@ -14754,7 +14739,8 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, tree inner = decl; ++processing_template_decl; if (TREE_CODE (inner) == FUNCTION_DECL) - inner = tsubst_function_decl (inner, args, complain, lambda_fntype); + inner = tsubst_function_decl (inner, args, complain, lambda_fntype, + /*use_spec_table=*/false); else { if (TREE_CODE (inner) == TYPE_DECL && !TYPE_DECL_ALIAS_P (inner)) @@ -14792,6 +14778,11 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, } else { + if (TREE_CODE (inner) == FUNCTION_DECL) + /* Set DECL_TI_ARGS to the full set of template arguments, which + tsubst_function_decl didn't do due to use_spec_table=false. */ + DECL_TI_ARGS (inner) = full_args; + DECL_TI_TEMPLATE (inner) = r; DECL_TI_ARGS (r) = DECL_TI_ARGS (inner); } @@ -14822,9 +14813,7 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, if (TREE_CODE (decl) == FUNCTION_DECL && !lambda_fntype) /* Record this non-type partial instantiation. */ - register_specialization (r, t, - DECL_TI_ARGS (DECL_TEMPLATE_RESULT (r)), - false, hash); + register_specialization (r, t, full_args, false, hash); return r; } diff --git a/gcc/testsuite/g++.dg/template/nontype12.C b/gcc/testsuite/g++.dg/template/nontype12.C index 9a9c3ac1e66..e36a9f16f94 100644 --- a/gcc/testsuite/g++.dg/template/nontype12.C +++ b/gcc/testsuite/g++.dg/template/nontype12.C @@ -5,7 +5,6 @@ template struct A { template int foo(); // { dg-error "double" "" { target c++17_down } } template class> int bar(); // { dg-bogus {double[^\n]*\n[^\n]*C:7:[^\n]*double} "" { xfail c++17_down } } - // { dg-error "double" "" { target c++17_down } .-1 } template struct X; // { dg-error "double" "" { target c++17_down } } };