From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id BBE8E3858D28; Tue, 11 Oct 2022 19:02:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBE8E3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665514978; bh=aDMRfJGFmU3o7RYU4+3Wkm9gqF2RH2zc54Otfj1Lhww=; h=From:To:Subject:Date:From; b=A7rFxlEpKc8CiSchPtMGjsQAZq87ShOnRZQTOTBSx0eTV8vxVU6xsH1evV8tMgsPA AhRWRpm+42J3u8Gbm21eq0LsL0K9ixomxvipp67/zhWnlpHyOiW51vugkQy9v0Wc6P ALxnyYU1ANzBoB/I6Z+Aw0subDoMgti9lltV9Vpw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3235] c++ modules: lazy loading from within template [PR99377] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 637e3668fdc17c4e226538fb14f9fab225433d01 X-Git-Newrev: 2ceb4d531a303f3e70d8bb218c8759e6c0688f62 Message-Id: <20221011190258.BBE8E3858D28@sourceware.org> Date: Tue, 11 Oct 2022 19:02:58 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2ceb4d531a303f3e70d8bb218c8759e6c0688f62 commit r13-3235-g2ceb4d531a303f3e70d8bb218c8759e6c0688f62 Author: Patrick Palka Date: Tue Oct 11 15:02:01 2022 -0400 c++ modules: lazy loading from within template [PR99377] Here when lazily loading the binding for f due to its first use from the template g, processing_template_decl is set which causes the call to note_vague_linkage_fn from module_state::read_cluster to have no effect, and thus we never push f onto deferred_fns and end up never emitting its definition despite needing it. The behavior of the lazy loading machinery shouldn't be sensitive to whether we're inside a template, so to that end this patch makes us clear processing_template_decl in the entrypoints lazy_load_binding and lazy_load_pendings. PR c++/99377 gcc/cp/ChangeLog: * module.cc (lazy_load_binding): Clear processing_template_decl. (lazy_load_pendings): Likewise. gcc/testsuite/ChangeLog: * g++.dg/modules/pr99377-2_a.C: New test. * g++.dg/modules/pr99377-2_b.C: New test. Diff: --- gcc/cp/module.cc | 8 ++++++++ gcc/testsuite/g++.dg/modules/pr99377-2_a.C | 6 ++++++ gcc/testsuite/g++.dg/modules/pr99377-2_b.C | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 4d27cebd22c..7ffeefa7c1f 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -19083,6 +19083,10 @@ lazy_load_binding (unsigned mod, tree ns, tree id, binding_slot *mslot) timevar_start (TV_MODULE_IMPORT); + /* Make sure lazy loading from a template context behaves as if + from a non-template context. */ + processing_template_decl_sentinel ptds; + /* Stop GC happening, even in outermost loads (because our caller could well be building up a lookup set). */ function_depth++; @@ -19131,6 +19135,10 @@ lazy_load_binding (unsigned mod, tree ns, tree id, binding_slot *mslot) void lazy_load_pendings (tree decl) { + /* Make sure lazy loading from a template context behaves as if + from a non-template context. */ + processing_template_decl_sentinel ptds; + tree key_decl; pending_key key; key.ns = find_pending_key (decl, &key_decl); diff --git a/gcc/testsuite/g++.dg/modules/pr99377-2_a.C b/gcc/testsuite/g++.dg/modules/pr99377-2_a.C new file mode 100644 index 00000000000..98d18546d19 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_a.C @@ -0,0 +1,6 @@ +// PR c++/99377 +// { dg-additional-options -fmodules-ts } +// { dg-module-cmi pr99377_2 } +export module pr99377_2; + +export inline void f() { } diff --git a/gcc/testsuite/g++.dg/modules/pr99377-2_b.C b/gcc/testsuite/g++.dg/modules/pr99377-2_b.C new file mode 100644 index 00000000000..1d5d79c788c --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_b.C @@ -0,0 +1,8 @@ +// PR c++/99377 +// { dg-additional-options -fmodules-ts } +// { dg-do link } +import pr99377_2; + +template void g() { f(); } + +int main() { f(); }