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 110C93858C54 for ; Wed, 5 Oct 2022 12:55:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 110C93858C54 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=1664974509; 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=AOfPtOXUyLWZZP9P6Tw2zy6A2AYZ73/2XKNSDfm2Wvc=; b=af/VPNR6JxK1INCNC8zLJOxcAKhVJ4VjSNpkA5rwyq8mi4S20548a3dijIWM0UCgcHPQeN /7mrtXjk48u5S8xEGgoUug/OWCO55gRs/5HWeOlTVDCC1wZAh7itJgwXxtL7r/o/ZSSt7K GNkozfIAvmJNR5ma0lHpo4kk7QPe2Oc= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-163-YUCtXJc1MxuhYItVUSbUjA-1; Wed, 05 Oct 2022 08:55:08 -0400 X-MC-Unique: YUCtXJc1MxuhYItVUSbUjA-1 Received: by mail-qv1-f71.google.com with SMTP id dn14-20020a056214094e00b004b1a231394eso3993154qvb.13 for ; Wed, 05 Oct 2022 05:55:08 -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=AOfPtOXUyLWZZP9P6Tw2zy6A2AYZ73/2XKNSDfm2Wvc=; b=IXaTO8AXlm3dV9zbmkKKkO/TLSLMT8LZnDWTTqhvhkTTccCJ0ev8Wib67P0oYiWV7C CJWsVZ3R5ZBBtoGeW1JYctG2diX5jqLmpUEjKNYHa+Znep9MIzDGC4kEM947hkaYS14k dG1MPAJKW1U4SJfeuk5P/I7Dk0DLzqW+crN2RGP4+QXd8Gw0s6t599QXnXON+7/JVuPr C3WxZDcnEXqe8mgOsGsrVryfs/y+7cjED8HZQMS+9Ya/FfUU1f27sP8tqqKir/WOdb+K YVsPhCkTQ1tnsCjs1Rs4c9I3xgq6wXSY7y6UQEIPncMRznbhbuWtdFciz6kN7sa27ZPo 3SDw== X-Gm-Message-State: ACrzQf2bN2kqwjgpQROzPC2ARH06QD2QHifMMUODp2ypratlpan3NIIp oJ2noT+s+VbPyUR/HSl/tR3rEIjEGg9jhaL3kJ58Vj9Fm2W6zB3g2L0SXDGvOlGi+WpsQgfQsIi 7oZ7slI0PAIKK97UfJA== X-Received: by 2002:ac8:5b03:0:b0:35c:db06:fb3f with SMTP id m3-20020ac85b03000000b0035cdb06fb3fmr22667141qtw.523.1664974506874; Wed, 05 Oct 2022 05:55:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Orpq+oaRj4pLjUiqM9kDXzU60XXzMYWXTLNCnzXt4HNURxk7/xE9K7npXWHW9Ns+1ODRSeQ== X-Received: by 2002:ac8:5b03:0:b0:35c:db06:fb3f with SMTP id m3-20020ac85b03000000b0035cdb06fb3fmr22667128qtw.523.1664974506618; Wed, 05 Oct 2022 05:55:06 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id y28-20020a37f61c000000b006af3f3b385csm16099111qkj.98.2022.10.05.05.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 05:55:05 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 5 Oct 2022 08:55:05 -0400 (EDT) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, jason@redhat.com, nathan@acm.org Subject: Re: [PATCH] c++ modules: lazy loading from within template [PR99377] In-Reply-To: <20221004173631.2958133-1-ppalka@redhat.com> 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.5 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 List-Id: 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 void g() { f(); } > +int main() { g(); } This test can be simplified to: import pr99377; template 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.