From patchwork Wed May 1 09:59:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1930112 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=IeDDbcDf; 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 4VTsy64fxhz1ymc for ; Wed, 1 May 2024 20:00:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A673C3858CD1 for ; Wed, 1 May 2024 10:00:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 9DD453858CDB for ; Wed, 1 May 2024 10:00:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9DD453858CDB 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 9DD453858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::433 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714557604; cv=none; b=Foj4jw5ToBoN4PuT6mqLBHANcs3hcsPODHmyb2FjFY5kEXb3HqLy4TVBpysDl7DFIoY/SAiEyVQeWa3oiHh3tUX8Oyta/FJskRpvF8knnoOllw6o3R/rzFqplW0xYSQsLP0HJqG3sb+cw3rzNxd0sABHsy9aafBffg/iB8lbZsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714557604; c=relaxed/simple; bh=au+ZWZz8mODWxw3vS9mhbti0KJcJ2n9TMXp2R5CAjPk=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=SShAcrmHTvvxxTNoIUXzNMtpG9L+8mEJJ0RZ4elQA+oKe613u5pukyb2HnoeBIwpMv1jMbLOL7nGE3FMVo6YNxNMo3aIWNrWdQXTBI7WTvw11eDHl9y+q609uQU9ue+wt3SLWW/J60GqiPfNjCxMY0294vGSceBUxCeUKdd80oY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6f4178aec15so1165646b3a.0 for ; Wed, 01 May 2024 03:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714557599; x=1715162399; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=NqCv4uleM65B7H/yZgrXKOIu/2/0BQ+ehSEHcUYLs2g=; b=IeDDbcDf3SLzukyaoRIMA10hUdUhUwFO1wIrWxGEemdzIOoBxewNAVf1ptk75/ZlZY uZfn2EmN4Yk9ZlWjPdmAZP4Gph9fL5KxAbS9qohSnLHVwoL9+TpasLTXWIw/1LbF8X8R 9L7El/7jV8ZC7glkBsR1xpVrGMO2qVomuEnCj4HLIuVDCfwbYdmpFTkuxUX3Mz+00A5/ 3yg7JsxIvWt6ifgpeVjDokpjyTezM9v/IyLVoSwXwBwTr/ogIqw+Y3zmoGGJi+cc6qfn Bapi1FMkjLzlKtorygREqgH2zNF4kD2ohbnV+Eodih+IGdiUKkjDGH4/hq5xjeUaufDV nunQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714557599; x=1715162399; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NqCv4uleM65B7H/yZgrXKOIu/2/0BQ+ehSEHcUYLs2g=; b=hcsPHfAHY6o7Fr0kDWnVSFgoYIFC6SjXXnMpF3Ht+ZG01khD/Po7xlTRZZ98l/zAcX 7YpSxzt0o+EkqDebiae+/3rthKA0oO2qMh1+F2vXgvnO2wUcE7i2ZVntnA0pO5nbiRYb 4YdU5CQytTsLYftzGxjN2JYzzO/0TvopfgpIXDuG2mgclz/iHY6e3WHGjBOOzQKBTC0h 3ec5rKgOBYfuI9AMhe7rXGjvxzdja/SL32gf0zwIUxPSRvZZnKXqWItz6KW9MBronmeJ qRby56VM/EHWBvWD9FrWyAs7hTqWFdxYn3erQiDwgNIBnayZJNSoEwfZhHc3cgGg5AgR Ze9A== X-Gm-Message-State: AOJu0YyljLB/qRqjrp84ygAaIkQ+7mO23C3YPqFhmcY1CJJ29cPEVsaA Xx3imYFdhTxtR+IDZmoRk965a7O3FDNgWpHb8I7MHE78LmdS7S98Ef4Wvw== X-Google-Smtp-Source: AGHT+IEE2HJz1d9uZhqg57SMYC9qNjXYWTRB4/q4dL7g/Rp4TWuQPkhibl6qVPly/pcRFKQAdkSVCQ== X-Received: by 2002:a05:6a00:a18:b0:6f3:ef3d:60f4 with SMTP id p24-20020a056a000a1800b006f3ef3d60f4mr2350370pfh.33.1714557599358; Wed, 01 May 2024 02:59:59 -0700 (PDT) Received: from Thaum. (121-44-11-123.tpgi.com.au. [121.44.11.123]) by smtp.gmail.com with ESMTPSA id ff20-20020a056a002f5400b006eacefd8fabsm22368796pfb.64.2024.05.01.02.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 02:59:58 -0700 (PDT) Message-ID: <6632129e.050a0220.c5fe4.327c@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 1 May 2024 19:59:53 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell , Patrick Palka Subject: [PATCH 1/4] c++/modules: Don't emit unused GMF partial specializations [PR114630] References: <66321257.170a0220.326c5.1f68@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <66321257.170a0220.326c5.1f68@mx.google.com> X-Spam-Status: No, score=-11.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, URIBL_BLACK 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 -- The change in r14-8408 to also emit partial specializations in the global module fragment caused the regression in the linked PR; this patch fixes this by restricting emitted GM partial specializations to those that are actually used. PR c++/114630 gcc/cp/ChangeLog: * module.cc (depset::hash::add_partial_entities): Mark GM specializations as unreached. (depset::hash::find_dependencies): Also reach entities in the DECL_TEMPLATE_SPECIALIZATIONS list. gcc/testsuite/ChangeLog: * g++.dg/modules/partial-3.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 75 +++++++++++++++--------- gcc/testsuite/g++.dg/modules/partial-3.C | 20 +++++++ 2 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/partial-3.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index fac0301d80e..02b0ab3d687 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -13304,14 +13304,22 @@ depset::hash::add_partial_entities (vec *partial_classes) depset *dep = make_dependency (inner, depset::EK_DECL); if (dep->get_entity_kind () == depset::EK_REDIRECT) - /* We should have recorded the template as a partial - specialization. */ - gcc_checking_assert (dep->deps[0]->get_entity_kind () - == depset::EK_PARTIAL); + { + dep = dep->deps[0]; + /* We should have recorded the template as a partial + specialization. */ + gcc_checking_assert (dep->get_entity_kind () + == depset::EK_PARTIAL); + } else /* It was an explicit specialization, not a partial one. */ gcc_checking_assert (dep->get_entity_kind () == depset::EK_SPECIALIZATION); + + /* Only emit GM entities if reached. */ + if (!DECL_LANG_SPECIFIC (inner) + || !DECL_MODULE_PURVIEW_P (inner)) + dep->set_flag_bit (); } } @@ -13632,31 +13640,40 @@ depset::hash::find_dependencies (module_state *module) if (!walker.is_key_order () && TREE_CODE (decl) == TEMPLATE_DECL && !DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl)) - /* Mark all the explicit & partial specializations as - reachable. */ - for (tree cons = DECL_TEMPLATE_INSTANTIATIONS (decl); - cons; cons = TREE_CHAIN (cons)) - { - tree spec = TREE_VALUE (cons); - if (TYPE_P (spec)) - spec = TYPE_NAME (spec); - int use_tpl; - node_template_info (spec, use_tpl); - if (use_tpl & 2) - { - depset *spec_dep = find_dependency (spec); - if (spec_dep->get_entity_kind () == EK_REDIRECT) - spec_dep = spec_dep->deps[0]; - if (spec_dep->is_unreached ()) - { - reached_unreached = true; - spec_dep->clear_flag_bit (); - dump (dumper::DEPEND) - && dump ("Reaching unreached specialization" - " %C:%N", TREE_CODE (spec), spec); - } - } - } + { + /* Mark all the explicit & partial specializations as + reachable. We search both specialization lists as some + constrained partial specializations for class types are + only found in DECL_TEMPLATE_SPECIALIZATIONS. */ + auto mark_reached = [this](tree spec) + { + if (TYPE_P (spec)) + spec = TYPE_NAME (spec); + int use_tpl; + node_template_info (spec, use_tpl); + if (use_tpl & 2) + { + depset *spec_dep = find_dependency (spec); + if (spec_dep->get_entity_kind () == EK_REDIRECT) + spec_dep = spec_dep->deps[0]; + if (spec_dep->is_unreached ()) + { + reached_unreached = true; + spec_dep->clear_flag_bit (); + dump (dumper::DEPEND) + && dump ("Reaching unreached specialization" + " %C:%N", TREE_CODE (spec), spec); + } + } + }; + + for (tree cons = DECL_TEMPLATE_INSTANTIATIONS (decl); + cons; cons = TREE_CHAIN (cons)) + mark_reached (TREE_VALUE (cons)); + for (tree cons = DECL_TEMPLATE_SPECIALIZATIONS (decl); + cons; cons = TREE_CHAIN (cons)) + mark_reached (TREE_VALUE (cons)); + } dump.outdent (); current = NULL; diff --git a/gcc/testsuite/g++.dg/modules/partial-3.C b/gcc/testsuite/g++.dg/modules/partial-3.C new file mode 100644 index 00000000000..0d498dad1bd --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/partial-3.C @@ -0,0 +1,20 @@ +// PR c++/114630 +// { dg-additional-options "-fmodules-ts -std=c++20 -Wno-global-module -fdump-lang-module" } +// { dg-module-cmi M } + +module; + +template struct S {}; + +template struct S {}; +template requires (sizeof(T) == 4) struct S {}; + +template int V = 0; + +template int V = 1; +template requires (sizeof(T) == 4) int V = 2; + +export module M; + +// The whole GMF should be discarded here +// { dg-final { scan-lang-dump "Wrote 0 clusters" module } }