From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 3573F3858C2D for ; Tue, 11 Oct 2022 14:58:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3573F3858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665500322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LtAMqqvx7NrhKZDvMlD748ITamkgK02WDacyWhz3wk0=; b=btZ27SD8tMLWNl0hLIu0oDtgrBmtrj1HcsGUmY0YKuxiXwnXmq1DU/NC+NVtp1FGsspkdS IneYte+M6oulbWSLlqKVSNGYmR7b0E2TAFVm5EufWt7wl9QlHH3HHXPYn94NlhUL9H+Gsi 7bS5tlyTMzDsH+HcWcxFs+zv9EP5E30= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-310-wK_QNiL8OJiYXjTwPSa-1Q-1; Tue, 11 Oct 2022 10:58:23 -0400 X-MC-Unique: wK_QNiL8OJiYXjTwPSa-1Q-1 Received: by mail-qk1-f200.google.com with SMTP id j13-20020a05620a410d00b006e08208eb31so11782190qko.3 for ; Tue, 11 Oct 2022 07:58:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LtAMqqvx7NrhKZDvMlD748ITamkgK02WDacyWhz3wk0=; b=R8nFJwO1kzN+ttwWPsYGDn+47LF5V3c/CmevpNji7JU7mpkJeRaEn5P4b0gL0oN3tv JR8dscSg5xNx7Ksd23G4u1R/hc7A/0SRntA7D587c5YFgE9wiil1sssqpU3BcnTOue4T lV/UdqGG5R88Rn2liSuPNf6GnUrxGaxQhuuLJ1xUiqW0Gy/h/ySPZ3Xnnd5bRpRdAmo4 8fu+88j8PSviuNMhyPDEFkUgB1Ng8QUtBcezMnNikMlToEpWssT9/FYPv+NeVQngwD8v xI1BWZDH3KG5NGtpF6uHc9dTOOrZbqtkY4oe8NtZMEJSxGwzZC/k2O4VVRZXqyGTOw7x VMeg== X-Gm-Message-State: ACrzQf1py+hl70TQ1zqBBgmhI+BEb7wfCXcZTwAHNr8pDayiTuRSKkvO H2isMuvUF2ECrfcGpJneb3ilUe59MPm+SOVNirJ88DUD3QK7Qco+kzYPIKuUqoLMKiogrOQd7aZ bIQS1fSIUUh9d5NPkDw== X-Received: by 2002:a05:622a:d0:b0:391:e5af:12b with SMTP id p16-20020a05622a00d000b00391e5af012bmr19767498qtw.408.1665500300508; Tue, 11 Oct 2022 07:58:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7l3IwM4B5rbBL7FPgPUOTc2fIv4MB8eiU5sYV0lJ8O3YqxFC3EdbSY8PXWj5AtMdu+c8xjxQ== X-Received: by 2002:a05:622a:d0:b0:391:e5af:12b with SMTP id p16-20020a05622a00d000b00391e5af012bmr19767481qtw.408.1665500300259; Tue, 11 Oct 2022 07:58:20 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id ca6-20020a05622a1f0600b003994bbe91bdsm5976980qtb.60.2022.10.11.07.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 07:58:18 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Tue, 11 Oct 2022 10:58:18 -0400 (EDT) To: Nathan Sidwell cc: Patrick Palka , gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] c++ modules: lazy loading from within template [PR99377] In-Reply-To: Message-ID: References: <20221004173631.2958133-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-14.1 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_NONE,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 List-Id: 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 void g() { f(); } +int main() { g(); } -- 2.38.0.15.gbbe21b64a0