public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [C++ PATCH] Optimize C++ comdat ctors/dtors in classes without virtual bases (PR c++/3187, take 4)
Date: Tue, 01 Dec 2009 15:40:00 -0000	[thread overview]
Message-ID: <20091201153912.GR22813@hs20-bc2-1.build.redhat.com> (raw)
In-Reply-To: <20091201094652.GQ22813@hs20-bc2-1.build.redhat.com>

On Tue, Dec 01, 2009 at 04:46:52AM -0500, Jakub Jelinek wrote:
> Unfortunately, when bootstrapping with extra checking patch (second patch)
> where I wanted to verify that for classes with comdat virtual dtors we
> always emit either both D2 (and D1 alias to it) and D0 dtor, or none of
> them, build in libstdc++ revealed that we emit e.g. in complex_io.cc
> (reduced testcase attached last, cc1plus -O2 cplx.ii) only the
> _ZN1DIi1BIiE1CIiEED2Ev (and _ZN1DIi1BIiE1CIiEED1Ev alias) dtor in
> the _ZN1DIi1BIiE1CIiEED5Ev comdat group, but not _ZN1DIi1BIiE1CIiEED0Ev.
> The class is extern template class, so either the g++ is buggy and emits
> something it never should, because the template is extern, or
> putting the *D0* dtors also in the *D5* comdat group is not a good idea.

Here is the additional patch that allowed the 2 patches to bootstrap.
The problem is with implicitly defined methods in extern template class XXX<NNN>
instantiations.  The synthetized methods don't have
DECL_TEMPLATE_INSTANTIATION set, thus don't go through
instantiate_class_member and thus are emitted whenever something needs them
(and the side with explicit non-extern instantiation doesn't necessarily
define all the functions).  In this light the patch below is an ABI change
(not sure what other compilers do though), as with the patch newly compiled
code with extern template class XXX<NNN> would no longer emit routines
it needs it, instead rely on the CU with
extern template class XXX<NNN>; template class XXX<NNN>;
to emit them.  But as the code emitted by older G++ doesn't guarantee all
the implicitly declared methods are emitted there, mixing new code and old
code could result in undefined references.  The methods are usually inlined,
sure, but e.g. if ipa-inline.c considers them called in cold blocks, it
decides not to inline them.

--- gcc/cp/pt.c.jj	2009-12-01 12:09:10.000000000 +0100
+++ gcc/cp/pt.c	2009-12-01 13:33:39.000000000 +0100
@@ -16055,6 +16055,31 @@ do_type_instantiation (tree t, tree stor
 	if (TREE_CODE (tmp) == FUNCTION_DECL
 	    && DECL_TEMPLATE_INSTANTIATION (tmp))
 	  instantiate_class_member (tmp, extern_p);
+	else if (TREE_CODE (tmp) == FUNCTION_DECL
+		 && DECL_ARTIFICIAL (tmp)
+		 && (DECL_CONSTRUCTOR_P (tmp)
+		     || DECL_DESTRUCTOR_P (tmp)
+		     || DECL_ASSIGNMENT_OPERATOR_P (tmp)))
+	  {
+	    /* Ensure the implicitly declared ctors/dtors/assignment operators
+	       will be either inlined, or extern calls for extern_p,
+	       or defined in the current TU otherwise.  */
+	    DECL_EXTERNAL (tmp) = 1;
+	    if (extern_p)
+	      DECL_NOT_REALLY_EXTERN (tmp) = 0;
+	    else
+	      {
+		mark_definable (tmp);
+		/* Always make artificials weak.  */
+		if (flag_weak)
+		  comdat_linkage (tmp);
+		/* For WIN32 we also want to put explicit instantiations in
+		   linkonce sections.  */
+		else if (TREE_PUBLIC (tmp))
+		  maybe_make_one_only (tmp);
+	      }
+	    DECL_INTERFACE_KNOWN (tmp) = 1;
+	  }
 
     for (tmp = TYPE_FIELDS (t); tmp; tmp = TREE_CHAIN (tmp))
       if (TREE_CODE (tmp) == VAR_DECL && DECL_TEMPLATE_INSTANTIATION (tmp))


	Jakub

  reply	other threads:[~2009-12-01 15:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-30 22:38 [C++ PATCH] Optimize C++ comdat ctors/dtors in classes without virtual bases (PR c++/3187, take 3) Jakub Jelinek
2009-12-01  3:53 ` Jason Merrill
2009-12-01  8:07   ` Jakub Jelinek
2009-12-01 15:39     ` Jason Merrill
2009-12-01  9:52 ` [C++ PATCH] Optimize C++ comdat ctors/dtors in classes without virtual bases (PR c++/3187, take 4) Jakub Jelinek
2009-12-01 15:40   ` Jakub Jelinek [this message]
2009-12-01 16:38     ` Dave Korn
2009-12-01 19:35   ` [C++ PATCH] Optimize C++ comdat ctors/dtors in classes without virtual bases (PR c++/3187, take 5) Jakub Jelinek
2009-12-01 20:14     ` Jason Merrill
2009-12-01 21:03     ` Dave Korn
2009-12-04 18:19       ` Dave Korn
2009-12-04 18:29         ` Jakub Jelinek
2009-12-04 18:46           ` Dave Korn
2009-12-27 13:36     ` H.J. Lu
2009-12-01 21:15 ` [C++ PATCH] Optimize C++ comdat ctors/dtors in classes without virtual bases (PR c++/3187, take 3) Daniel Jacobowitz
2009-12-01 21:20   ` Jakub Jelinek
2009-12-01 21:50     ` Daniel Jacobowitz

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=20091201153912.GR22813@hs20-bc2-1.build.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /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).