From patchwork Thu Aug 15 11:55:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1972749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Y0RMTHfP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wl3W411X2z1yNr for ; Thu, 15 Aug 2024 21:56:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DBD353858427 for ; Thu, 15 Aug 2024 11:56:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 289803858D29 for ; Thu, 15 Aug 2024 11:56:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 289803858D29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 289803858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723722969; cv=none; b=lAoEvF+CmUvkptPxjIwSXI+IhQeSr5JZx4j0uV0Sd6QfejkCdtnkq6XJrv2wEtwOuPXBT/TBOMwc3HPC/a3yntSlVCd7uo6JP0tvMP/s+UxZMdhk9geDfjYz8sdhoYszerpJv90VW6F16ZPDw9MLnPj8LMpsEAWLB22u0fEIFfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723722969; c=relaxed/simple; bh=FT+I0XfqJ9f0+0V8PU+WS296UCkJccFSyIchFjsg/Ms=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=Q1qXQhBDDfmpQK7hn+zHs8vNC5v5qVqJCrpv0LIMQhEC3eXwF7iyUHmdNaFMGF+8iHvPsaAGQBkzc/UF3yVuZJBJpy9jcyFR68W5A5ARVE24VCamZU92IKMF/BwaA7JudCopeHMzwmnIIlQJqnjQhUKBnnFO0ocQSC7uk+ho0ro= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-70d1cbbeeaeso677945b3a.0 for ; Thu, 15 Aug 2024 04:56:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723722961; x=1724327761; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=AoBaa0V+hsRGDWhWmHppOYI+tj/83Tqgf6Ekfw2sDeA=; b=Y0RMTHfPI8pIEp70cgArwux//MK6ySrNdQKXUU/sPQZTMPsmR5izEsYyLFGn560gz5 nYJCO43aAyhfTvg8ngLz8k/DQaizu8DAkOEIZh/ytGm8Z1mv1594WoVnKwtAaE7MfKpY AT9JVvmNJ2p+lsAWQ3LctdNIVThTbTBxTnJ5k2Lff3rxUdotAcxTSiBH6YEMeTQD5tu+ lyQHhzVCiH4gJJvM+c5nNrofyk0cv/NAV737zvhN8Tt1+WMQpw1fooLWkPBD9o6duHGa J46DeIVWjnnSQ0mAbnD3zIJnn8oBAOG/rXPllxnrPD/0ByND6GUnGZDP1+HHC2ZKJCnc 78QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723722961; x=1724327761; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AoBaa0V+hsRGDWhWmHppOYI+tj/83Tqgf6Ekfw2sDeA=; b=BK1XYsX/P0ICxJCZbWRH+uO1dZuJM0t3IFCpovh/vtcaz40B5a0MHB9EjJRkTALlf6 nqMG6Kil45hEOrazXnu9oyT4EGjPEXGzuEpywNUBJSyfP48GvBBnGcR/GtUVhotoN3pB 1iej5/sv+YlPdhJGjxHg8aUBZpMP61MQl1np+HC5iPUi1/hYYQcIubq3lgC2cqWamQdC dWK4NPIr1E82WmhfPqUygNNDt8DsMfKej7Dp+D3RP4gsQPwPCCvUTn3poRHKcxlVC+ZE gWZx31x2f6k5aBzXJWdBJckKLhVt50lYhi4AMFGgD21taBQBAS/q2MzigRZe9/18RkET qU4Q== X-Gm-Message-State: AOJu0YwSWPEWiC2I0+5Mz6U5PgkZplvjTdOIoiqta1+LFIjOarkcGWiN 1NXEVStfye77CLwv4MZ0eVuzASI70IWZBSTIOs6fqlowjp2kz3hJOGsX0A== X-Google-Smtp-Source: AGHT+IHw6Pc7T9SB1ktUFSxDMvjhKZ6dmUMpx132QpVlRrcjMcRAYTtftWDKZB/EzvQ/y9Ky7ysllA== X-Received: by 2002:a05:6a00:14d2:b0:702:3e36:b7c4 with SMTP id d2e1a72fcca58-712670f7600mr7569078b3a.5.1723722960909; Thu, 15 Aug 2024 04:56:00 -0700 (PDT) Received: from Thaum. (110-174-164-242.static.tpgi.com.au. [110.174.164.242]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127ae07a5csm867738b3a.54.2024.08.15.04.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 04:56:00 -0700 (PDT) Message-ID: <66bdecd0.620a0220.32f817.27ab@mx.google.com> X-Google-Original-Message-ID: Date: Thu, 15 Aug 2024 21:55:55 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell , Patrick Palka Subject: [PATCH] c++/modules: Fix type lookup in DECL_TEMPLATE_INSTANTIATIONS [PR116364] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- We need to use the DECL_TEMPLATE_INSTANTIATIONS property to find reachable specialisations from a template to ensure that any GM specialisations are properly marked as reachable. Currently the modules code uses the decl when rebuilding this property, but this is not always correct; it appears that for type specialisations we need to use the TREE_TYPE of the decl instead so that the specialisation is correctly found. This patch makes the required adjustments. PR c++/116364 gcc/cp/ChangeLog: * cp-tree.h (get_mergeable_specialization_flags): Adjust signature. * module.cc (trees_out::decl_value): Indicate whether this is a type or decl specialisation. * pt.cc (get_mergeable_specialization_flags): Match against the type of a non-decl specialisation. (add_mergeable_specialization): Use the already calculated spec instead of always adding decl to DECL_TEMPLATE_INSTANTIATIONS. gcc/testsuite/ChangeLog: * g++.dg/modules/tpl-spec-9_a.C: New test. * g++.dg/modules/tpl-spec-9_b.C: New test. * g++.dg/modules/tpl-spec-9_c.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/cp-tree.h | 3 ++- gcc/cp/module.cc | 3 ++- gcc/cp/pt.cc | 8 +++++--- gcc/testsuite/g++.dg/modules/tpl-spec-9_a.C | 12 ++++++++++++ gcc/testsuite/g++.dg/modules/tpl-spec-9_b.C | 5 +++++ gcc/testsuite/g++.dg/modules/tpl-spec-9_c.C | 5 +++++ 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/tpl-spec-9_a.C create mode 100644 gcc/testsuite/g++.dg/modules/tpl-spec-9_b.C create mode 100644 gcc/testsuite/g++.dg/modules/tpl-spec-9_c.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a53fbcb43ec..039c70710a2 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7672,7 +7672,8 @@ extern void walk_specializations (bool, void *), void *); extern tree match_mergeable_specialization (bool is_decl, spec_entry *); -extern unsigned get_mergeable_specialization_flags (tree tmpl, tree spec); +extern unsigned get_mergeable_specialization_flags (bool is_decl, tree tmpl, + tree spec); extern void add_mergeable_specialization (bool is_decl, spec_entry *, tree outer, unsigned); extern tree add_to_template_args (tree, tree); diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index f4d137b13a1..c3218bd5caf 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -7981,7 +7981,8 @@ trees_out::decl_value (tree decl, depset *dep) auto *entry = reinterpret_cast (dep->deps[0]); if (streaming_p ()) - u (get_mergeable_specialization_flags (entry->tmpl, decl)); + u (get_mergeable_specialization_flags (mk & MK_tmpl_decl_mask, + entry->tmpl, decl)); tree_node (entry->tmpl); tree_node (entry->args); } diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 8725a5eeb3f..1c531f456be 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -31559,13 +31559,14 @@ match_mergeable_specialization (bool decl_p, spec_entry *elt) specialization lists of TMPL. */ unsigned -get_mergeable_specialization_flags (tree tmpl, tree decl) +get_mergeable_specialization_flags (bool decl_p, tree tmpl, tree decl) { unsigned flags = 0; + tree spec = decl_p ? decl : TREE_TYPE (decl); for (tree inst = DECL_TEMPLATE_INSTANTIATIONS (tmpl); inst; inst = TREE_CHAIN (inst)) - if (TREE_VALUE (inst) == decl) + if (TREE_VALUE (inst) == spec) { flags |= 1; break; @@ -31623,7 +31624,8 @@ add_mergeable_specialization (bool decl_p, spec_entry *elt, tree decl, if (flags & 1) DECL_TEMPLATE_INSTANTIATIONS (elt->tmpl) - = tree_cons (elt->args, decl, DECL_TEMPLATE_INSTANTIATIONS (elt->tmpl)); + = tree_cons (elt->args, elt->spec, + DECL_TEMPLATE_INSTANTIATIONS (elt->tmpl)); if (flags & 2) { diff --git a/gcc/testsuite/g++.dg/modules/tpl-spec-9_a.C b/gcc/testsuite/g++.dg/modules/tpl-spec-9_a.C new file mode 100644 index 00000000000..d7c02bb279d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/tpl-spec-9_a.C @@ -0,0 +1,12 @@ +// PR c++/116364 +// { dg-additional-options "-fmodules-ts -Wno-global-module" } +// { dg-module-cmi foo:part } + +module; +template struct S {}; +template <> struct S + { static constexpr bool value = true; }; +export module foo:part; + +export template + constexpr bool result = S::value; diff --git a/gcc/testsuite/g++.dg/modules/tpl-spec-9_b.C b/gcc/testsuite/g++.dg/modules/tpl-spec-9_b.C new file mode 100644 index 00000000000..f2ce5c2e90b --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/tpl-spec-9_b.C @@ -0,0 +1,5 @@ +// PR c++/116364 +// { dg-additional-options "-fmodules-ts" } + +export module foo; +export import :part; diff --git a/gcc/testsuite/g++.dg/modules/tpl-spec-9_c.C b/gcc/testsuite/g++.dg/modules/tpl-spec-9_c.C new file mode 100644 index 00000000000..e79224561ca --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/tpl-spec-9_c.C @@ -0,0 +1,5 @@ +// PR c++/116364 +// { dg-additional-options "-fmodules-ts" } + +import foo; +bool x = result;