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: 89226 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03480385843B for ; Wed, 1 May 2024 10:00:40 +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+patchwork=sourceware.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 } } From patchwork Wed May 1 10:00:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 89227 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 96937385E836 for ; Wed, 1 May 2024 10:01:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id B4A85385841D for ; Wed, 1 May 2024 10:00:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4A85385841D 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 B4A85385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714557632; cv=none; b=DUgyRDTMaMkYd0G0uQv9+nie/RJRJrn06buYBhp340pKQHfMrWKnXdieTGb4bCAG9dTe3jMGnaQ8kx7XWyXqin77+T/bJGUne1Jy5xr2r4w7UKqwGqrRyEsiBNDfoCUydmc9A9nKE3bBXSVXwqf7e9HwtxwKUtdPp+eoh+pMfEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714557632; c=relaxed/simple; bh=0vQqCqr/l2iT21vc4cwTmhv2H0x7YOyEhk1bZyd2hTU=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=OJ56iqjpk8cojEfx2CPLUMcp6sM4iKvhwiPjeJeVkCH0os7XDo6szi/4iFg+yN/t3izfwKEQT8HCt6ApU+vv+WCnjQR2CtxiE6OfebNtnU5HMB8NswKK7Tl/ik1KjozoqKhWWurfY9LjSXx8ncG4HaCpz6ayOzvdOz1CMBy14YQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6ecff9df447so6398606b3a.1 for ; Wed, 01 May 2024 03:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714557628; x=1715162428; 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=QUbUan5DwZN8wf7x1njhQaDcUbLQJviRb1oYFPeKdtM=; b=b8hsn7K9CtnEEuInSLQoI4MGUtPFNuwu6rrh3kCZwabKP2ebR07sbBJ/wV1YDB87e4 Ued43DwEIB45Lobt6cC06ouuRwCGfMGqOnipl6OhQ4sC3PelX2Dp3qbg1A6zJ706/6FZ y5LOOr9yXE3mW53/jMSHiU49Ju5aZ9wi3m/Evmw7Pk+W366Yl5+DTKuThSE4dGUoRyB1 Hak5PPNSEt/ZRg3tFBnvZMTDW8mIUiRddYK1PKVvZkRmA8Ts0qmtBD71QnAO5DsUNDHn h1hJSmmBLhIvseGVS6ey041FvusRp6ZM3QmFOPf8dOkz7NQTRUm8ymi0eRZSsuBp4fos s0KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714557628; x=1715162428; 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=QUbUan5DwZN8wf7x1njhQaDcUbLQJviRb1oYFPeKdtM=; b=azjU7/oQWbT9pGebB41nwv1QWU700t0+aKr0fUDUWPQjEV/dVq5Z1QJcovaIzc7mBs EsmRM0Fqw3PkDA++ZNFsyOIn2siJS6vx/hKoRnfJPAwE10cNnZnUmBxjUnTYdQi0PxWC 2ad/DTQ/HudNRNWzFJwI99xvLeBXrNiDFPGuZcAXHMMs9filufFBmdd4fnmCRVLEsA6u cl88+0KbJo4i0c1i4rH06H9Lsjr/66wU6QtLdMrfunNXrjX4euZPBaWgDpNe1tnmRZ8c 6YKKba1k9P+RgcLMtBH0ESmvCpeoplzpoIO1pEBqZCEa6kfKF1IvBSUVXhWYqXvxzpBV j/sA== X-Gm-Message-State: AOJu0YzGr8gTSPg9iBhT51ityZLidGXlLiw3VxNvQWpufgyUspsUYKlf CgPOmxd6Zucs+gYk3ESjustc574Z4eTGFICtA9eCWTzF7Fwle/dbk4FXgg== X-Google-Smtp-Source: AGHT+IHETWWIRliYc+tBoaUD/F3TFutc23iJqbHgCli4cgM7RzGUFKOgikrh/onXYfK4KIcasMM/Ww== X-Received: by 2002:a05:6a00:3923:b0:6ed:21bc:ed8c with SMTP id fh35-20020a056a00392300b006ed21bced8cmr2140826pfb.18.1714557627566; Wed, 01 May 2024 03:00:27 -0700 (PDT) Received: from Thaum. (121-44-11-123.tpgi.com.au. [121.44.11.123]) by smtp.gmail.com with ESMTPSA id ei9-20020a056a0080c900b006f33c0aee44sm14689312pfb.91.2024.05.01.03.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 03:00:27 -0700 (PDT) Message-ID: <663212bb.050a0220.9a96f.94c6@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 1 May 2024 20:00:22 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell , Patrick Palka Subject: [PATCH 2/4] c++/modules: Track module purview for deferred instantiations [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.9 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 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+patchwork=sourceware.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- When calling instantiate_pending_templates at end of parsing, any new functions that are instantiated from this point have their module purview set based on the current value of module_kind. This is unideal, however, as the modules code will then treat these instantiations as reachable and cause large swathes of the GMF to be emitted into the module CMI, despite no code in the actual module purview referencing it. This patch fixes this by also remembering the value of module_kind when the instantiation was deferred, and restoring it when doing this deferred instantiation. That way newly instantiated declarations appropriately get a DECL_MODULE_PURVIEW_P appropriate for where the instantiation was required, meaning that GMF entities won't be counted as reachable unless referenced by an actually reachable entity. Note that purviewness and attachment etc. is generally only determined by the base template: this is purely for determining whether a specialisation was declared in the module purview and hence whether it should be streamed out. See the comment on 'set_instantiating_module'. PR c++/114630 PR c++/114795 gcc/cp/ChangeLog: * cp-tree.h (struct tinst_level): Add field for tracking module_kind. * pt.cc (push_tinst_level_loc): Cache module_kind in new_level. (reopen_tinst_level): Restore module_kind from level. (instantiate_pending_templates): Save and restore module_kind so it isn't affected by reopen_tinst_level. gcc/testsuite/ChangeLog: * g++.dg/modules/gmf-3.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/cp-tree.h | 3 +++ gcc/cp/pt.cc | 4 ++++ gcc/testsuite/g++.dg/modules/gmf-3.C | 13 +++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/gmf-3.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1938ada0268..0e619120ccc 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6626,6 +6626,9 @@ struct GTY((chain_next ("%h.next"))) tinst_level { /* The location where the template is instantiated. */ location_t locus; + /* The module kind where the template is instantiated. */ + unsigned module_kind; + /* errorcount + sorrycount when we pushed this level. */ unsigned short errors; diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1c3eef60c06..401aa92bc3e 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -11277,6 +11277,7 @@ push_tinst_level_loc (tree tldcl, tree targs, location_t loc) new_level->tldcl = tldcl; new_level->targs = targs; new_level->locus = loc; + new_level->module_kind = module_kind; new_level->errors = errorcount + sorrycount; new_level->next = NULL; new_level->refcount = 0; @@ -11345,6 +11346,7 @@ reopen_tinst_level (struct tinst_level *level) for (t = level; t; t = t->next) ++tinst_depth; + module_kind = level->module_kind; set_refcount_ptr (current_tinst_level, level); pop_tinst_level (); if (current_tinst_level) @@ -27442,6 +27444,7 @@ instantiate_pending_templates (int retries) { int reconsider; location_t saved_loc = input_location; + unsigned saved_module_kind = module_kind; /* Instantiating templates may trigger vtable generation. This in turn may require further template instantiations. We place a limit here @@ -27532,6 +27535,7 @@ instantiate_pending_templates (int retries) while (reconsider); input_location = saved_loc; + module_kind = saved_module_kind; } /* Substitute ARGVEC into T, which is a list of initializers for diff --git a/gcc/testsuite/g++.dg/modules/gmf-3.C b/gcc/testsuite/g++.dg/modules/gmf-3.C new file mode 100644 index 00000000000..e52ae904ea9 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/gmf-3.C @@ -0,0 +1,13 @@ +// PR c++/114630 +// { dg-additional-options "-fmodules-ts -Wno-global-module -fdump-lang-module" } +// { dg-module-cmi M } + +module; +template struct allocator { + allocator() {} +}; +template class allocator; +export module M; + +// The whole GMF should be discarded here +// { dg-final { scan-lang-dump "Wrote 0 clusters" module } } From patchwork Wed May 1 10:00:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 89228 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C283F384AB5D for ; Wed, 1 May 2024 10:01:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 85FCB384AB50 for ; Wed, 1 May 2024 10:01:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85FCB384AB50 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 85FCB384AB50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714557669; cv=none; b=MNDSjZtGxIZH1FvoHzU7wtrENwL2mdSeMqChFBZDRGGmesRArqMBFkHGXsXtziAcbjA1FAIyhe/hOi1o/TVY2vMfTfsUauLBVXo/JSBM9Q4ADzLyrolgoIlf7vFmh0FSZ23NY6quwLc7M/VmkHdfF3qViJa0IyRnf8Ws8qYW/yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714557669; c=relaxed/simple; bh=vwfwpiQNq4St3094y5rRoVlGCCZhnDEBvb1FyYAQZFE=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=Fp2bboJteFWq/uCkbhgyXTMHRBUf5eXH7NLrEoR0RbwLttSg319t7pdVmBifUdm4IBfdsdF5O9VClAysfAttEy1KgzIJJZ4CEYaEdDI3cAWFCSm3uE9Ym0vgoKau0NODwiGomBc05dkT9IqCWf0ZlatV7u+M/uVgKalhLUSRPBE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6f3f6aa1437so3127980b3a.3 for ; Wed, 01 May 2024 03:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714557664; x=1715162464; 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=jI1VBS2OtccXZCkNsDrgKDXXyIut16ebb06a3ZcwsdQ=; b=ABjYNbN9IW1GxVRi69P0YhQ1X8f3rl2YhxgDBR/PM3hYkR14hSFNkDq+7239pFzD6s JjeX6h/S2GRdv3R6HNcsiGQKGgQsITNa7eaNRLnX/1zIrRjyzdLq/QgGy53HwCkBWSyC Z8PBqboQvUY7W8LKFzyMvqIKsxSMhsyumulQVH5KdoBXKAY+6poMZMSLw0hifPXQMEnS eWYKySuUCaobWQYvSGjmq7xQgr2sO+VQPYuI2UcSVvKf1LNWk0SODhgYjooKVp6l5qAn 36IHiA/wsD1vKwB/a8nvXB+1GH6/2ORJ6cpHCz9xrmtuoYsclnqLGfGUUFgv2KFhN0J5 dtGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714557664; x=1715162464; 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=jI1VBS2OtccXZCkNsDrgKDXXyIut16ebb06a3ZcwsdQ=; b=T+j/zghMxda9vnirx1h7I2i81/cevPbYSeyA5O3ET0/klxmJ2haFBVRaa99K5HRzgp 0NWyo9uSxf9iQU051mvcKRcrn6IWoKLRiPRkE/XooEXR1P/jAogIDKJ0jWv5azfBKBXs a+Qt/h3KgZiuPLa4ROa3v/jJ058szv53UWkrB40cVhcacXrtUPqWrVmBC4l5awBmEHnZ STsvH6Ch8nWK1xe0EYgo6/fCC13zfddEeVxuksZewxmr75cKWrDOC/ODE7VdbMegoTCE TN8crh3c6GZDNoRJxZXK/WVlRmVXXOsMk6OGkezVRWcOiCFOnVPC4bs7+entKPMVZuHp 3Ang== X-Gm-Message-State: AOJu0YwmIAZYPftr/unJNMIHv8LQphJgRrlrYJB8lBqvWJD8H/t7MB0i XZ6HgO1WPrO6GqQK2x7eLu3cuej7iXKDY9GdYgv6M8Hu8gbkxgcZq5VYdQ== X-Google-Smtp-Source: AGHT+IEvW3qTv/W6Zsnge+zSSzH+66c8VNIQ69QqwrUc75lUG+fJUnm/yTxpE3jtHEPxM+fL8/S4Pw== X-Received: by 2002:a05:6a00:2eaa:b0:6ea:7b29:3ab7 with SMTP id fd42-20020a056a002eaa00b006ea7b293ab7mr2373296pfb.23.1714557664486; Wed, 01 May 2024 03:01:04 -0700 (PDT) Received: from Thaum. (121-44-11-123.tpgi.com.au. [121.44.11.123]) by smtp.gmail.com with ESMTPSA id ge3-20020a056a00838300b006ecfc3a5f2dsm22309047pfb.46.2024.05.01.03.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 03:01:04 -0700 (PDT) Message-ID: <663212e0.050a0220.566c4.2dff@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 1 May 2024 20:00:59 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell , Patrick Palka Subject: [PATCH 3/4] c++/modules: Also track module purview from deferred vtable instantiation [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.9 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 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+patchwork=sourceware.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- Similarly to in the previous commit, templated virtual functions are sometimes not instantiated until after parsing has completed. This means that any new declarations they instantiate are incorrectly marked as being in the module purview, causing them to not be discarded from the GMF. PR c++/114630 PR c++/114795 gcc/cp/ChangeLog: * decl2.cc (mark_vtable_entries): Set module purview of deferred instantiations from the function decl. (c_parse_final_cleanups): Save and restore module_kind. gcc/testsuite/ChangeLog: * g++.dg/modules/gmf-4.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/decl2.cc | 11 +++++++++-- gcc/testsuite/g++.dg/modules/gmf-4.C | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/gmf-4.C diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 806a2a4bc69..0115a6b1cc9 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -2210,6 +2210,11 @@ mark_vtable_entries (tree decl, vec &consteval_vtables) location, as we're called from c_parse_final_cleanups, which takes care of that. */ input_location = DECL_SOURCE_LOCATION (fn); + /* Similarly, any deferred instantiations should have the same + module purview as this function. */ + module_kind &= ~MK_PURVIEW; + if (DECL_LANG_SPECIFIC (fn) && DECL_MODULE_PURVIEW_P (fn)) + module_kind |= MK_PURVIEW; mark_used (fn); } } @@ -5085,6 +5090,7 @@ c_parse_final_cleanups (void) tree decl; locus_at_end_of_parsing = input_location; + unsigned module_kind_at_end_of_parsing = module_kind; /* We're done parsing. */ at_eof = 1; @@ -5177,9 +5183,10 @@ c_parse_final_cleanups (void) reconsider = true; keyed_classes->unordered_remove (i); } - /* The input_location may have been changed during marking of - vtable entries. */ + /* The input_location and module_kind may have been changed + during marking of vtable entries. */ input_location = locus_at_end_of_parsing; + module_kind = module_kind_at_end_of_parsing; /* Write out needed type info variables. We have to be careful looping through unemitted decls, because emit_tinfo_decl may diff --git a/gcc/testsuite/g++.dg/modules/gmf-4.C b/gcc/testsuite/g++.dg/modules/gmf-4.C new file mode 100644 index 00000000000..c95bc782cea --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/gmf-4.C @@ -0,0 +1,27 @@ +// PR c++/114630 +// { dg-additional-options "-fmodules-ts -Wno-global-module -fdump-lang-module" } +// { dg-module-cmi M } + +// Deferred instantiation of GM virtual functions should not place +// newly discovered declarations in the module purview + +module; + +template +void go() { + extern T fn_decl(); +} + +template +struct S { + virtual void f() { + go(); + } +}; + +S s; + +export module M; + +// The whole GMF should be discarded here +// { dg-final { scan-lang-dump "Wrote 0 clusters" module } } From patchwork Wed May 1 10:01:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 89229 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D63EF385ED7A for ; Wed, 1 May 2024 10:02:21 +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 EF963384AB4E for ; Wed, 1 May 2024 10:01:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF963384AB4E 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 EF963384AB4E 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=1714557697; cv=none; b=RCeaKNjvTctU+Jm7ev9913VxQhS/sqYmQURl8aZa5aqP9yKHWfSeqzHB5OA9xYfKuePVKI93y4PQ/KPBQ8VSQrFKd+LkNvpnYNUG8XmfMtXlqcV1sil6N4V5+Si7xuMBRNUg6F96rFPAsYvQhQYvVPGM9EIDsYslX68wZRQAf54= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714557697; c=relaxed/simple; bh=+147HyMVZioO99NDgu86wR/d0yhTiKbDyUtuyAXfLW0=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=xf3vGnhNeJk7tNMVJwinZBmrx6oiMy0v7dAus0T9Y9FPWvxEZ0/SpK58EF5ofAL+CpmnpxUo1MDaDbY7NKg7QNwq6Jju4BcAgSz8Z+nFTggd0lo9iNxI5NHV3+faOzb4Jo+8H4YjJTqvME5XNEhye1ZJTre7kriUwCG0295FlSg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6ecff9df447so6399241b3a.1 for ; Wed, 01 May 2024 03:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714557695; x=1715162495; 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=d2AycY8Yl6THFUfRa4smnXUAtFBkc6BF0vNfeyj119w=; b=lrx7T8J4b92kaN2hCwmVPrg7N3Jt8gnNyy+jbT+XKOAMjCFn16b9RoQrTQVOOz/JDZ d8MKbfxq+9sASTIDmEHvNOzaTkE+YOOe352sc86MzwqRJ2IROiocoQRQR/zfUpYxWdl8 Gr/jpdX+uZbUkchwzGWP0jqA8xlyBgJw0BF75zXnHX1G+jqiwDlEw08+Ft6MT5PZevcp nXf8nI/rvqRGlQ6r9XoRwAVjMrccSwdf0AKxhGjUIvneuaW6mU6VZtvBXJYp40xi0USw AHgoC2neNFXk/QcGaKPyXNAXxqwz/imSbeid/8efFDIhFIUizMv9cpzVqqY2kOmrKCOg MZPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714557695; x=1715162495; 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=d2AycY8Yl6THFUfRa4smnXUAtFBkc6BF0vNfeyj119w=; b=VYTTm8s1yVE3/FHvVH8e/qo4jwixdVD+S9VRlpnk67Xx5vgbds+8dd8jywpeVAf5z6 n0gjNJckLneNoGJvbcep2iYe+vJG3tnwUu/EqX5THZ9zoc9rJ7IrMh8nerOxcoa6VuiA /NMNxyuGjY8ryecMRrLXWRvGUCDVoZgzz3wO3LYQXgJUH3tlGwUy2ZI45miJTq48cIBc X5dIxJozVQdSFFF/9Mw8imTh9g8yJbuwDEZDn3GW0pDDG9n4neZNEaSpl4sOqpsiFl4F m04KqejxNvkzpI6Y3nS4615sJAbkuHttZkACEH1h8CCw2nMRr264Cy5qj+N5XWUqn37t O6Pg== X-Gm-Message-State: AOJu0YxwoMytZfjXMCNbu7qJND2uvM0bjy4KXU9Xa+xvdrxXNAKW4qJz nFcaDoxMx392f1pTYVvmMKxAsfAD2DZQiWvrclpCh9tfM471cIcGrGeVXA== X-Google-Smtp-Source: AGHT+IEjlzT/TMJLUAnYK32PQ+LO0Xkjru7ldpg+v5YjKKwgMga+wv0WKmG/9UZsxvkvnu6EjuD02g== X-Received: by 2002:a05:6a00:3923:b0:6ed:21bc:ed8c with SMTP id fh35-20020a056a00392300b006ed21bced8cmr2144268pfb.18.1714557694863; Wed, 01 May 2024 03:01:34 -0700 (PDT) Received: from Thaum. (121-44-11-123.tpgi.com.au. [121.44.11.123]) by smtp.gmail.com with ESMTPSA id gm15-20020a056a00640f00b006f416953eeesm2425502pfb.101.2024.05.01.03.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 03:01:34 -0700 (PDT) Message-ID: <663212fe.050a0220.da6fc.9353@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 1 May 2024 20:01:29 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell , Patrick Palka Subject: [PATCH 4/4] c++: Add new xtreme-header testcase for GMF discarding 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.9 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 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+patchwork=sourceware.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? Another thought would be to replace xtreme-header.h with so that we don't need to keep it up-to-date in the future. But this patch just does the obviously correct thing. -- >8 -- This new testcase helps verify that the issues discovered in PR114630 with GMF entries being inappropriately emitted into the module CMI don't regress, at least for the kinds of code used in the standard library headers. This also updates the base xtreme-header.h file to include new header files that are now available. gcc/testsuite/ChangeLog: * g++.dg/modules/xtreme-header.h: Update. * g++.dg/modules/xtreme-header-8.C: New test. Signed-off-by: Nathaniel Shead --- .../g++.dg/modules/xtreme-header-8.C | 9 +++++++ gcc/testsuite/g++.dg/modules/xtreme-header.h | 24 ++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/xtreme-header-8.C diff --git a/gcc/testsuite/g++.dg/modules/xtreme-header-8.C b/gcc/testsuite/g++.dg/modules/xtreme-header-8.C new file mode 100644 index 00000000000..b0d0ae87534 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/xtreme-header-8.C @@ -0,0 +1,9 @@ +// { dg-additional-options "-fmodules-ts -fdump-lang-module" } +// { dg-module-cmi empty } + +module; +#include "xtreme-header.h" +export module empty; + +// The whole GMF should be discarded here +// { dg-final { scan-lang-dump "Wrote 0 clusters" module } } diff --git a/gcc/testsuite/g++.dg/modules/xtreme-header.h b/gcc/testsuite/g++.dg/modules/xtreme-header.h index 3147aaf00f4..8d95218755a 100644 --- a/gcc/testsuite/g++.dg/modules/xtreme-header.h +++ b/gcc/testsuite/g++.dg/modules/xtreme-header.h @@ -89,7 +89,6 @@ // C++20 #if __cplusplus > 201703 -#if 1 #include #include #include @@ -98,6 +97,7 @@ #if __cpp_coroutines #include #endif +#include #include #include #include @@ -106,24 +106,32 @@ #include #include #include -#if 0 -// Unimplemented -#include -#endif -#endif #endif // C++23 #if __cplusplus > 202002L #include +#include +#include #include #include +#include #if 0 // Unimplemented #include #include -#include #include -#include +#endif +#endif + +// C++26 +#if __cplusplus > 202302L +#if 0 +// Unimplemented +#include +#include +#include +#include +#include #endif #endif