Message ID | 20221004173631.2958133-1-ppalka@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 74EEA385828D for <patchwork@sourceware.org>; Tue, 4 Oct 2022 17:38:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74EEA385828D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664905090; bh=m2dtSM9M9Ksn2DM+sAjPus7BtYQMy26HaBuSlS/KYCU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=PPHQnk9ChjP6KseLjmMqaLYxig7SpdgHJrSZiYGApUCur0goAKGNNilI/ynEEmzkB tsoSEXpt0Czw7gnyo2GKlw7AQIKmgPYpq6ltCKC9HeRgl9xX/yUc3tTDtgQl2XvqUJ DBA2zZGG2tV2n/+dgsNqpousv0dE+q+1Izb4iGow= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D28B23858D32 for <gcc-patches@gcc.gnu.org>; Tue, 4 Oct 2022 17:36:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D28B23858D32 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-657-hoFwGyC2ORCfQO0e5H0noA-1; Tue, 04 Oct 2022 13:36:36 -0400 X-MC-Unique: hoFwGyC2ORCfQO0e5H0noA-1 Received: by mail-qk1-f197.google.com with SMTP id bs33-20020a05620a472100b006cef8cfabe2so12199013qkb.12 for <gcc-patches@gcc.gnu.org>; Tue, 04 Oct 2022 10:36:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=m2dtSM9M9Ksn2DM+sAjPus7BtYQMy26HaBuSlS/KYCU=; b=bOvH7uvea1CLDT+r3Jqt8V6ae9vh2HNs3k4taT+l5xI++SuEtDTjYl7KPCEpNV4qw9 gi/r24pbLgimW8iR+PkAco+qX4oM3mhtldqkmYRV3YBrZHlpMBXTxHFjZmPA8AW9zaIe 41/7nURXt+bxvoNFuNUMKwZR4Pcu/SGBIaan3+qNl0jBlB+A2Ur4Q6j0sgstMdgoWv0N Il+eahqW515Mt3TYlUFZ9KpkOGOPLCmZSJXR0pQ/KKUPrPG031d9gFoavFGUtDr9RMeo WBB+ASCCiyD7bEb7bPnCLLGiYz0JV9lMmYeEvq07MlbTm6G8myAIRri0en4CiTgVruep pEdA== X-Gm-Message-State: ACrzQf3O43lUr7ca0lLA+EqnXiRhT/Y3O7jfAPFtnUxMbJRvzK4NYe2Q I1i4hkqxbw3dx1nsxRUR5srypJZrbj36XUtqcsBRNQWRNvgLb89bX21qAnFNozctmY2TUHdkEhk Jomn65a0dJ6su515xr0yznHDEuCwcwWaesCPmhoVwyebEczVxEvRrn18pLOmr9GsQCRk= X-Received: by 2002:a05:6214:2342:b0:473:bcd6:a3b7 with SMTP id hu2-20020a056214234200b00473bcd6a3b7mr20920838qvb.88.1664904994160; Tue, 04 Oct 2022 10:36:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ZWuHcWBnkMDFHqxaqOc7qumXlaHBdI1Szkd5bnWid/qbQjer6DX9WvAHjJx6bRJQ+dk9zMg== X-Received: by 2002:a05:6214:2342:b0:473:bcd6:a3b7 with SMTP id hu2-20020a056214234200b00473bcd6a3b7mr20920808qvb.88.1664904993800; Tue, 04 Oct 2022 10:36:33 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id l18-20020a37f912000000b006ce580c2663sm14717419qkj.35.2022.10.04.10.36.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:36:33 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++ modules: lazy loading from within template [PR99377] Date: Tue, 4 Oct 2022 13:36:31 -0400 Message-Id: <20221004173631.2958133-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.rc2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Patrick Palka via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Patrick Palka <ppalka@redhat.com> Cc: nathan@acm.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
c++ modules: lazy loading from within template [PR99377]
|
|
Commit Message
Patrick Palka
Oct. 4, 2022, 5:36 p.m. UTC
Here when lazily loading the binding for f at parse time from the template g, processing_template_decl is set and thus the call to note_vague_linkage_fn from module_state::read_cluster has no effect, and we never push f onto deferred_fns and end up never emitting its definition. ISTM the behavior of the lazy loading machinery shouldn't be sensitive to whether we're inside a template, and therefore we should probably be clearing processing_template_decl somewhere e.g in lazy_load_binding. This is sufficient to fix the testcase. But it also seems the processing_template_decl test in note_vague_linkage_fn, added by r8-7539-g977bc3ee11383e for PR84973, is perhaps too strong: if the intent is to avoid deferring output for uninstantiated templates, we should make sure that DECL in question is an uninstantiated template by checking e.g. value_dependent_expression_p. This too is sufficient to fix the testcase (since f isn't a template) and survives bootstrap and regtest. Does one or the other approach look like the correct fix for this PR? PR c++/99377 gcc/cp/ChangeLog: * decl2.cc (note_vague_linkage_fn): Relax processing_template_decl test to value_dependent_expression_p. * module.cc (lazy_load_binding): Clear processing_template_decl. gcc/testsuite/ChangeLog: * g++.dg/modules/pr99377-2_a.C: New test. * g++.dg/modules/pr99377-2_b.C: New test. --- gcc/cp/decl2.cc | 2 +- gcc/cp/module.cc | 2 ++ gcc/testsuite/g++.dg/modules/pr99377-2_a.C | 5 +++++ gcc/testsuite/g++.dg/modules/pr99377-2_b.C | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_a.C create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_b.C
Comments
On Tue, 4 Oct 2022, Patrick Palka wrote: > Here when lazily loading the binding for f at parse time from the > template g, processing_template_decl is set and thus the call to > note_vague_linkage_fn from module_state::read_cluster has no effect, > and we never push f onto deferred_fns and end up never emitting its > definition. > > ISTM the behavior of the lazy loading machinery shouldn't be sensitive > to whether we're inside a template, and therefore we should probably be > clearing processing_template_decl somewhere e.g in lazy_load_binding. > This is sufficient to fix the testcase. > > But it also seems the processing_template_decl test in > note_vague_linkage_fn, added by r8-7539-g977bc3ee11383e for PR84973, is > perhaps too strong: if the intent is to avoid deferring output for > uninstantiated templates, we should make sure that DECL in question is > an uninstantiated template by checking e.g. value_dependent_expression_p. > This too is sufficient to fix the testcase (since f isn't a template) > and survives bootstrap and regtest. > > Does one or the other approach look like the correct fix for this PR? > > PR c++/99377 > > gcc/cp/ChangeLog: > > * decl2.cc (note_vague_linkage_fn): Relax processing_template_decl > test to value_dependent_expression_p. > * module.cc (lazy_load_binding): Clear processing_template_decl. > > gcc/testsuite/ChangeLog: > > * g++.dg/modules/pr99377-2_a.C: New test. > * g++.dg/modules/pr99377-2_b.C: New test. > --- > gcc/cp/decl2.cc | 2 +- > gcc/cp/module.cc | 2 ++ > gcc/testsuite/g++.dg/modules/pr99377-2_a.C | 5 +++++ > gcc/testsuite/g++.dg/modules/pr99377-2_b.C | 6 ++++++ > 4 files changed, 14 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_a.C > create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_b.C > > diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc > index 9f18466192f..5af4d17ee3b 100644 > --- a/gcc/cp/decl2.cc > +++ b/gcc/cp/decl2.cc > @@ -876,7 +876,7 @@ check_classfn (tree ctype, tree function, tree template_parms) > void > note_vague_linkage_fn (tree decl) > { > - if (processing_template_decl) > + if (value_dependent_expression_p (decl)) > return; > > DECL_DEFER_OUTPUT (decl) = 1; > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > index 500ac06563a..79cbb346ffa 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -19074,6 +19074,8 @@ lazy_load_binding (unsigned mod, tree ns, tree id, binding_slot *mslot) > > timevar_start (TV_MODULE_IMPORT); > > + 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++; > 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..26e2bccbbbe > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_a.C > @@ -0,0 +1,5 @@ > +// PR c++/99377 > +// { dg-additional-options -fmodules-ts } > +// { dg-module-cmi pr99377 } > +export module pr99377; > +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..69571952c8a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_b.C > @@ -0,0 +1,6 @@ > +// PR c++/99377 > +// { dg-additional-options -fmodules-ts } > +// { dg-do link } > +import pr99377; > +template<class> void g() { f(); } > +int main() { g<int>(); } This test can be simplified to: import pr99377; template<class> void g() { f(); } int main() { f(); } which probably illustrates the bug better: we lazily load f at the point of its first use, which in this case is in the (uninstantiated) template g with processing_template_decl != 0. Thus during lazy loading the call to note_vague_linkage_fn has no effect and we never emit the definition of f.
On 10/4/22 13:36, Patrick Palka wrote: > Here when lazily loading the binding for f at parse time from the > template g, processing_template_decl is set and thus the call to > note_vague_linkage_fn from module_state::read_cluster has no effect, > and we never push f onto deferred_fns and end up never emitting its > definition. > > ISTM the behavior of the lazy loading machinery shouldn't be sensitive > to whether we're inside a template, and therefore we should probably be > clearing processing_template_decl somewhere e.g in lazy_load_binding. > This is sufficient to fix the testcase. yeah, I remember hitting issues with this, but thought I'd got rid of the need to override processing_template_decl. Do you also need to override it in lazy_load_pendings though? that's a lazy loader and my suspicion is it might be susceptible to the same issues. > > But it also seems the processing_template_decl test in > note_vague_linkage_fn, added by r8-7539-g977bc3ee11383e for PR84973, is > perhaps too strong: if the intent is to avoid deferring output for > uninstantiated templates, we should make sure that DECL in question is > an uninstantiated template by checking e.g. value_dependent_expression_p. > This too is sufficient to fix the testcase (since f isn't a template) > and survives bootstrap and regtest. I think this is an orthogonal issue -- can we remove it from this patch? > > Does one or the other approach look like the correct fix for this PR? > > PR c++/99377 > > gcc/cp/ChangeLog: > > * decl2.cc (note_vague_linkage_fn): Relax processing_template_decl > test to value_dependent_expression_p. > * module.cc (lazy_load_binding): Clear processing_template_decl. > > gcc/testsuite/ChangeLog: > > * g++.dg/modules/pr99377-2_a.C: New test. > * g++.dg/modules/pr99377-2_b.C: New test. > --- > gcc/cp/decl2.cc | 2 +- > gcc/cp/module.cc | 2 ++ > gcc/testsuite/g++.dg/modules/pr99377-2_a.C | 5 +++++ > gcc/testsuite/g++.dg/modules/pr99377-2_b.C | 6 ++++++ > 4 files changed, 14 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_a.C > create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_b.C > > diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc > index 9f18466192f..5af4d17ee3b 100644 > --- a/gcc/cp/decl2.cc > +++ b/gcc/cp/decl2.cc > @@ -876,7 +876,7 @@ check_classfn (tree ctype, tree function, tree template_parms) > void > note_vague_linkage_fn (tree decl) > { > - if (processing_template_decl) > + if (value_dependent_expression_p (decl)) > return; > > DECL_DEFER_OUTPUT (decl) = 1; > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > index 500ac06563a..79cbb346ffa 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -19074,6 +19074,8 @@ lazy_load_binding (unsigned mod, tree ns, tree id, binding_slot *mslot) > > timevar_start (TV_MODULE_IMPORT); > > + 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++; > 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..26e2bccbbbe > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_a.C > @@ -0,0 +1,5 @@ > +// PR c++/99377 > +// { dg-additional-options -fmodules-ts } > +// { dg-module-cmi pr99377 } > +export module pr99377; > +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..69571952c8a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_b.C > @@ -0,0 +1,6 @@ > +// PR c++/99377 > +// { dg-additional-options -fmodules-ts } > +// { dg-do link } > +import pr99377; > +template<class> void g() { f(); } > +int main() { g<int>(); }
On Mon, 10 Oct 2022, Nathan Sidwell wrote: > On 10/4/22 13:36, Patrick Palka wrote: > > Here when lazily loading the binding for f at parse time from the > > template g, processing_template_decl is set and thus the call to > > note_vague_linkage_fn from module_state::read_cluster has no effect, > > and we never push f onto deferred_fns and end up never emitting its > > definition. > > > > ISTM the behavior of the lazy loading machinery shouldn't be sensitive > > to whether we're inside a template, and therefore we should probably be > > clearing processing_template_decl somewhere e.g in lazy_load_binding. > > This is sufficient to fix the testcase. > > yeah, I remember hitting issues with this, but thought I'd got rid of the need > to override processing_template_decl. Do you also need to override it in > lazy_load_pendings though? that's a lazy loader and my suspicion is it might > be susceptible to the same issues. Hmm yeah, looks like we need to override it in lazy_load_pendings too: I ran the testsuite with gcc_assert (!processing_template_decl) added to module_state::read_cluster and if we don't also override it in lazy_load_binding then the assert triggers for pr99425-2_b.X. > > > > > But it also seems the processing_template_decl test in > > note_vague_linkage_fn, added by r8-7539-g977bc3ee11383e for PR84973, is > > perhaps too strong: if the intent is to avoid deferring output for > > uninstantiated templates, we should make sure that DECL in question is > > an uninstantiated template by checking e.g. value_dependent_expression_p. > > This too is sufficient to fix the testcase (since f isn't a template) > > and survives bootstrap and regtest. > > I think this is an orthogonal issue -- can we remove it from this patch? Done. -- >8 -- Subject: [PATCH] c++ modules: lazy loading from within template [PR99377] Here when lazily loading the binding for f at parse time from the template g, processing_template_decl is set and thus the call to note_vague_linkage_fn from module_state::read_cluster has no effect, and we never push f onto deferred_fns and end up never emitting its definition. ISTM the behavior of the lazy loading machinery shouldn't be sensitive to whether we're inside a template, and therefore we should be clearing 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. --- gcc/cp/module.cc | 8 ++++++++ gcc/testsuite/g++.dg/modules/pr99377-2_a.C | 5 +++++ gcc/testsuite/g++.dg/modules/pr99377-2_b.C | 6 ++++++ 3 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_a.C create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 94fbee85225..7c48602136c 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -19081,6 +19081,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++; @@ -19129,6 +19133,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..26e2bccbbbe --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_a.C @@ -0,0 +1,5 @@ +// PR c++/99377 +// { dg-additional-options -fmodules-ts } +// { dg-module-cmi pr99377 } +export module pr99377; +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..69571952c8a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_b.C @@ -0,0 +1,6 @@ +// PR c++/99377 +// { dg-additional-options -fmodules-ts } +// { dg-do link } +import pr99377; +template<class> void g() { f(); } +int main() { g<int>(); }
On 10/11/22 10:58, Patrick Palka wrote: > On Mon, 10 Oct 2022, Nathan Sidwell wrote: > >> On 10/4/22 13:36, Patrick Palka wrote: >>> Here when lazily loading the binding for f at parse time from the >>> template g, processing_template_decl is set and thus the call to >>> note_vague_linkage_fn from module_state::read_cluster has no effect, >>> and we never push f onto deferred_fns and end up never emitting its >>> definition. >>> >>> ISTM the behavior of the lazy loading machinery shouldn't be sensitive >>> to whether we're inside a template, and therefore we should probably be >>> clearing processing_template_decl somewhere e.g in lazy_load_binding. >>> This is sufficient to fix the testcase. >> >> yeah, I remember hitting issues with this, but thought I'd got rid of the need >> to override processing_template_decl. Do you also need to override it in >> lazy_load_pendings though? that's a lazy loader and my suspicion is it might >> be susceptible to the same issues. > > Hmm yeah, looks like we need to override it in lazy_load_pendings too: > I ran the testsuite with gcc_assert (!processing_template_decl) added to > module_state::read_cluster and if we don't also override it in > lazy_load_binding then the assert triggers for pr99425-2_b.X. > >> >>> >>> But it also seems the processing_template_decl test in >>> note_vague_linkage_fn, added by r8-7539-g977bc3ee11383e for PR84973, is >>> perhaps too strong: if the intent is to avoid deferring output for >>> uninstantiated templates, we should make sure that DECL in question is >>> an uninstantiated template by checking e.g. value_dependent_expression_p. >>> This too is sufficient to fix the testcase (since f isn't a template) >>> and survives bootstrap and regtest. >> >> I think this is an orthogonal issue -- can we remove it from this patch? > > Done. > > -- >8 -- > > Subject: [PATCH] c++ modules: lazy loading from within template [PR99377] > > Here when lazily loading the binding for f at parse time from the > template g, processing_template_decl is set and thus the call to > note_vague_linkage_fn from module_state::read_cluster has no effect, > and we never push f onto deferred_fns and end up never emitting its > definition. > > ISTM the behavior of the lazy loading machinery shouldn't be sensitive > to whether we're inside a template, and therefore we should be clearing > 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. ok, thanks > > gcc/testsuite/ChangeLog: > > * g++.dg/modules/pr99377-2_a.C: New test. > * g++.dg/modules/pr99377-2_b.C: New test. > --- > gcc/cp/module.cc | 8 ++++++++ > gcc/testsuite/g++.dg/modules/pr99377-2_a.C | 5 +++++ > gcc/testsuite/g++.dg/modules/pr99377-2_b.C | 6 ++++++ > 3 files changed, 19 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_a.C > create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_b.C > > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > index 94fbee85225..7c48602136c 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -19081,6 +19081,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++; > @@ -19129,6 +19133,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..26e2bccbbbe > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_a.C > @@ -0,0 +1,5 @@ > +// PR c++/99377 > +// { dg-additional-options -fmodules-ts } > +// { dg-module-cmi pr99377 } > +export module pr99377; > +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..69571952c8a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_b.C > @@ -0,0 +1,6 @@ > +// PR c++/99377 > +// { dg-additional-options -fmodules-ts } > +// { dg-do link } > +import pr99377; > +template<class> void g() { f(); } > +int main() { g<int>(); }
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 9f18466192f..5af4d17ee3b 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -876,7 +876,7 @@ check_classfn (tree ctype, tree function, tree template_parms) void note_vague_linkage_fn (tree decl) { - if (processing_template_decl) + if (value_dependent_expression_p (decl)) return; DECL_DEFER_OUTPUT (decl) = 1; diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 500ac06563a..79cbb346ffa 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -19074,6 +19074,8 @@ lazy_load_binding (unsigned mod, tree ns, tree id, binding_slot *mslot) timevar_start (TV_MODULE_IMPORT); + 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++; 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..26e2bccbbbe --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_a.C @@ -0,0 +1,5 @@ +// PR c++/99377 +// { dg-additional-options -fmodules-ts } +// { dg-module-cmi pr99377 } +export module pr99377; +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..69571952c8a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99377-2_b.C @@ -0,0 +1,6 @@ +// PR c++/99377 +// { dg-additional-options -fmodules-ts } +// { dg-do link } +import pr99377; +template<class> void g() { f(); } +int main() { g<int>(); }