public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathaniel Shead <nathanieloshead@gmail.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org, Nathan Sidwell <nathan@acm.org>
Subject: Re: [PATCH] c++: Keep DECL_SAVED_TREE of destructor instantiations in modules [PR104040]
Date: Thu, 4 Apr 2024 22:27:56 +1100	[thread overview]
Message-ID: <660e8ec1.170a0220.2a0c4.3501@mx.google.com> (raw)
In-Reply-To: <6ea38b8a-4146-4c02-b28a-80f1de178e01@redhat.com>

On Wed, Apr 03, 2024 at 11:18:01AM -0400, Jason Merrill wrote:
> On 4/2/24 20:57, Nathaniel Shead wrote:
> > On Tue, Apr 02, 2024 at 01:18:17PM -0400, Jason Merrill wrote:
> > > On 3/28/24 23:21, Nathaniel Shead wrote:
> > > > -	  && !(modules_p () && DECL_DECLARED_INLINE_P (fn)))
> > > > +	  && !(modules_p ()
> > > > +	       && (DECL_DECLARED_INLINE_P (fn)
> > > > +		   || DECL_TEMPLATE_INSTANTIATION (fn))))
> > > 
> > > How about using vague_linkage_p?
> > > 
> > 
> > Right, of course.  How about this?
> > Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
> > 
> > -- >8 --
> > 
> > A template instantiation still needs to have its DECL_SAVED_TREE so that
> > its definition is emitted into the CMI. This way it can be emitted in
> > the object file of any importers that use it, in case it doesn't end up
> > getting emitted in this TU.
> > 
> > 	PR c++/104040
> > 
> > gcc/cp/ChangeLog:
> > 
> > 	* semantics.cc (expand_or_defer_fn_1): Keep DECL_SAVED_TREE for
> > 	all vague linkage functions.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > 	* g++.dg/modules/pr104040_a.C: New test.
> > 	* g++.dg/modules/pr104040_b.C: New test.
> > 
> > Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> > Reviewed-by: Jason Merrill <jason@redhat.com>
> > ---
> >   gcc/cp/semantics.cc                       |  5 +++--
> >   gcc/testsuite/g++.dg/modules/pr104040_a.C | 14 ++++++++++++++
> >   gcc/testsuite/g++.dg/modules/pr104040_b.C |  8 ++++++++
> >   3 files changed, 25 insertions(+), 2 deletions(-)
> >   create mode 100644 gcc/testsuite/g++.dg/modules/pr104040_a.C
> >   create mode 100644 gcc/testsuite/g++.dg/modules/pr104040_b.C
> > 
> > diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> > index adb1ba48d29..03800a20b26 100644
> > --- a/gcc/cp/semantics.cc
> > +++ b/gcc/cp/semantics.cc
> > @@ -5033,9 +5033,10 @@ expand_or_defer_fn_1 (tree fn)
> >         /* We don't want to process FN again, so pretend we've written
> >   	 it out, even though we haven't.  */
> >         TREE_ASM_WRITTEN (fn) = 1;
> > -      /* If this is a constexpr function, keep DECL_SAVED_TREE.  */
> > +      /* If this is a constexpr function, or the body might need to be
> > +	 exported from a module CMI, keep DECL_SAVED_TREE.  */
> >         if (!DECL_DECLARED_CONSTEXPR_P (fn)
> > -	  && !(modules_p () && DECL_DECLARED_INLINE_P (fn)))
> > +	  && !(modules_p () && vague_linkage_p (fn)))
> 
> Also, how about module_maybe_has_cmi_p?  OK with that change.
> 
> Jason
> 

Using 'module_maybe_has_cmi_p' doesn't seem to work.  This is for two
reasons, one of them fixable and one of them not (easily):

- It seems that header modules don't count for 'module_maybe_has_cmi_p';
  I didn't notice this initially, and maybe they should for the
  no-linkage decls too?  But even accounting for this,

- For some reason only clearing it if the module might have a CMI causes
  crashes in importers for some testcases.  I'm not 100% sure why yet,
  but I suspect it might be some duplicate-decls thing where the type
  inconsistently has DECL_SAVED_TREE applied, since this is also called
  on streamed-in declarations.

Out of interest, what was the reason that it was cleared at all in the
first place?  I wasn't able to find anything with git blame; is it just
for performance reasons in avoiding excess lowering later?

  reply	other threads:[~2024-04-04 11:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29  3:21 Nathaniel Shead
2024-03-29 12:33 ` Patrick Palka
2024-04-02 17:18 ` Jason Merrill
2024-04-03  0:57   ` Nathaniel Shead
2024-04-03 15:18     ` Jason Merrill
2024-04-04 11:27       ` Nathaniel Shead [this message]
2024-04-09  3:17         ` Jason Merrill
2024-04-09 13:36           ` Nathaniel Shead
2024-04-09 14:28             ` Jason Merrill
2024-04-10  1:42               ` Nathaniel Shead

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=660e8ec1.170a0220.2a0c4.3501@mx.google.com \
    --to=nathanieloshead@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=nathan@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).