From patchwork Fri Apr 17 17:35:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1272370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=kZnsUnRZ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 493jtY2sJ8z9sPF for ; Sat, 18 Apr 2020 03:36:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C22B384BC03; Fri, 17 Apr 2020 17:36:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C22B384BC03 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587144961; bh=r/GKbrtnxzCEUJTgi4ui8cMSJc7ZrHaxHMnm84zPNSI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kZnsUnRZR4f7a/nGE+0CZRYSHSlTu8vUl4qRb2sitGsWa87LHZhNL5mJTbwYGQnDw I7LrzwX0aeoIv+kVr8ZTZM5hGqT+XPp/3U5PidEOiI45eGwTPK6Tv1rjZAvtLriFOh Tc5kgnFiJ4sQGcNkrY4XnhlrYP66d5fhydOFkmCs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 6487D3851429 for ; Fri, 17 Apr 2020 17:35:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6487D3851429 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-372-yJxqxv5FMEeS2Qef6qzggQ-1; Fri, 17 Apr 2020 13:35:55 -0400 X-MC-Unique: yJxqxv5FMEeS2Qef6qzggQ-1 Received: by mail-qt1-f198.google.com with SMTP id g23so2951070qto.0 for ; Fri, 17 Apr 2020 10:35:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yfDLrYsj1MPibKHwWrF3/Y6oQeLplcenf2hSAdCE4mE=; b=uRBP3f5gEG9DfeENteReWv+b0GmPQKC9+q12oKrSko2bQZljW3oMpuSCcR65555x27 Vxcv6uWuitNhb8IaC77ah1+AEuB7LeFJ3r6rsxCUCtpkWOxuZTgKt7kO73RoAf6gdOiq qkDIK4DIZMjQthKc0x7aMOAL5LODLun7AaP3egZHaLiPoJaJBeAy/C+tnbkbPo5G0sh5 CqMrAmeTsaIAJU6xfRiMt7hj37zJn794UKj8HU8sEC6AdbUrbf5W5zy/Y/TBHS1A7qnt B59WSMCsCwPaCWgUmpmy9lV9fdrpDEUp2hFnSbWo3K/rPMrNtGRshX+qlx8m9QcY1fv+ kojw== X-Gm-Message-State: AGi0PuahmZvrp1Xny5qMrizRgKvPjcrWuE9ysJ3G+CXM2y7+0RhiDMbs VJcy4ayWqbl09Fq+AOAcBGlfqellTj5ya4cWE8Yif5b9MFrft5pR8kQ3lLwUW5hOLQJTFzAwX7T qg8hg7veGK7n3wWEHfw== X-Received: by 2002:a05:6214:1e5:: with SMTP id c5mr3677895qvu.79.1587144954536; Fri, 17 Apr 2020 10:35:54 -0700 (PDT) X-Google-Smtp-Source: APiQypJ0ZPUb87E3ATZijPk1fvO8thfcMmRm3+SOmw4IX1ugrW1oufpSvTqmRFlDEt45zGqxDheqnA== X-Received: by 2002:a05:6214:1e5:: with SMTP id c5mr3677868qvu.79.1587144954247; Fri, 17 Apr 2020 10:35:54 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id g133sm5313887qke.73.2020.04.17.10.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2020 10:35:53 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: spec_hasher::equal and PARM_DECLs [PR94632] Date: Fri, 17 Apr 2020 13:35:34 -0400 Message-Id: <20200417173534.3476212-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.1.107.gefe3874640 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-28.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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 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@gcc.gnu.org Sender: "Gcc-patches" In the testcase below, during specialization of c::d, we build two identical specializations of the parameter type b -- one when substituting into c::d's TYPE_ARG_TYPES and another when substituting into c::d's DECL_ARGUMENTS. We don't reuse the first specialization the second time around as a consequence of the fix for PR c++/56247 which made PARM_DECLs always compare different from one another during spec_hasher::equal. As a result, when looking up existing specializations of 'b', spec_hasher::equal considers the template argument decltype(e')::k to be different from decltype(e'')::k, where e' and e'' are the result of two calls to tsubst_copy on the PARM_DECL e. Since the two specializations are considered different due to the mentioned fix, their TYPE_CANONICAL points to themselves even though they are otherwise identical types, and this triggers an ICE in maybe_rebuild_function_decl_type when comparing the TYPE_ARG_TYPES of c::d to its DECL_ARGUMENTS. This patch fixes this issue at the spec_hasher::equal level by ignoring the 'comparing_specializations' flag in cp_tree_equal whenever the DECL_CONTEXTs of the two parameters are identical. This seems to be a sufficient condition to be able to correctly compare PARM_DECLs structurally. (This also subsumes the CONSTRAINT_VAR_P check since constraint variables all have empty, and therefore identical, DECL_CONTEXTs.) I can think of two other ways to avoid this ICE. One solution would be to do maybe_rebuild_function_decl_type only when we have instantiated the function, and not when we are just specializing it during instantiation of an enclosing class template. This would avoid the problematic same_type_p call altogether. Another solution would be to set up a local_specialization_stack in instantiate_class_template_1 so that we can reuse PARM_DECL specializations during tsubst_copy. As a consequence, e' and e'' mentioned above would be identical. Do one of these three solutions seem right? This patch passes 'make check-c++', and a full bootstrap/regtest is in progress. gcc/cp/ChangeLog: PR c++/94632 * tree.c (cp_tree_equal) : Ignore comparing_specializations if the parameters' contexts are identical. gcc/testsuite/ChangeLog: PR c++/94632 * g++.dg/template/canon-type-14.C: New test. --- gcc/cp/tree.c | 5 +++-- gcc/testsuite/g++.dg/template/canon-type-14.C | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/canon-type-14.C diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 8e4934c0009..dc4f1f48d3c 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3723,11 +3723,12 @@ cp_tree_equal (tree t1, tree t2) up for expressions that involve 'this' in a member function template. */ - if (comparing_specializations && !CONSTRAINT_VAR_P (t1)) + if (comparing_specializations + && DECL_CONTEXT (t1) != DECL_CONTEXT (t2)) /* When comparing hash table entries, only an exact match is good enough; we don't want to replace 'this' with the version from another function. But be more flexible - with local parameters in a requires-expression. */ + with parameters with identical contexts. */ return false; if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))) diff --git a/gcc/testsuite/g++.dg/template/canon-type-14.C b/gcc/testsuite/g++.dg/template/canon-type-14.C new file mode 100644 index 00000000000..fa05bdb9a74 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/canon-type-14.C @@ -0,0 +1,8 @@ +// PR c++/94632 +// { dg-do compile { target c++11 } } + +template struct b; +template class c { + template static void d(f e, b); +}; +template class c;