aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2009-11-18 10:53:52 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2009-11-18 10:53:52 +0100
commitb25833451bbe9b8a2194598b026cea071f4e9e65 (patch)
treee08b1ed30e6c41061167a50b2e85f7af35d6e70c /gcc/cp
parenta64333b7ea23dfc1d9d512adfbfec1aeeb9e9366 (diff)
downloadgcc-b25833451bbe9b8a2194598b026cea071f4e9e65.zip
gcc-b25833451bbe9b8a2194598b026cea071f4e9e65.tar.gz
gcc-b25833451bbe9b8a2194598b026cea071f4e9e65.tar.bz2
re PR c++/3187 (gcc lays down two copies of constructors)
PR c++/3187 * cgraph.h (struct cgraph_node): Add same_body and same_body_alias fields. (cgraph_same_body_alias, cgraph_remove_same_body_alias): New prototypes. * cgraphunit.c (cgraph_expand_function, cgraph_emit_thunks, cgraph_materialize_all_clones): Handle same_body aliases. * cgraph.c (cgraph_allocate_node): New function. (cgraph_create_node): Use it. (cgraph_node_for_decl, cgraph_node, cgraph_get_node, cgraph_node_for_asm, cgraph_remove_node): Handle same_body aliases. (cgraph_same_body_alias, cgraph_remove_same_body_alias): New functions. * lto-cgraph.c (lto_output_node): Stream out same_body aliases. (input_node): Stream in same_body aliases. * lto-symtab.c (lto_cgraph_replace_node): Clear node pointers for same_body aliases. (lto_symtab_merge_cgraph_nodes_1): Handle same_body aliases. * cp-tree.h (expand_or_defer_fn_1): New prototype. * decl2.c (cp_write_global_declarations): Mark as !DECL_EXTERNAL also all same_body aliases. * semantics.c (expand_or_defer_fn): Move most of the function except registering with cgraph to ... (expand_or_defer_fn_1): ... here. New function. * optimize.c: Include cgraph.h. (maybe_clone_body): If in charge parm is not used and both base and complete clones are created and are not comdat, tell cgraph they have the same body. * Make-lang.in (cp/optimize.o): Depend on $(CGRAPH_H). * g++.dg/abi/mangle26.C: Also match *C2* definition. * g++.dg/abi/mangle27.C: Likewise. * g++.dg/abi/mangle28.C: Likewise. * g++.dg/abi/mangle29.C: Likewise. From-SVN: r154284
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog15
-rw-r--r--gcc/cp/Make-lang.in2
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/decl2.c14
-rw-r--r--gcc/cp/optimize.c56
-rw-r--r--gcc/cp/semantics.c27
6 files changed, 93 insertions, 22 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 17968f5..b3acf8e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,18 @@
+2009-11-18 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/3187
+ * cp-tree.h (expand_or_defer_fn_1): New prototype.
+ * decl2.c (cp_write_global_declarations): Mark as !DECL_EXTERNAL
+ also all same_body aliases.
+ * semantics.c (expand_or_defer_fn): Move most of the function
+ except registering with cgraph to ...
+ (expand_or_defer_fn_1): ... here. New function.
+ * optimize.c: Include cgraph.h.
+ (maybe_clone_body): If in charge parm is not used and both base
+ and complete clones are created and are not comdat, tell cgraph
+ they have the same body.
+ * Make-lang.in (cp/optimize.o): Depend on $(CGRAPH_H).
+
2009-11-17 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/42058
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 861c93d..f5c652e 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -303,7 +303,7 @@ cp/semantics.o: cp/semantics.c $(CXX_TREE_H) $(TM_H) except.h toplev.h \
cp/dump.o: cp/dump.c $(CXX_TREE_H) $(TM_H) $(TREE_DUMP_H)
cp/optimize.o: cp/optimize.c $(CXX_TREE_H) $(TM_H) rtl.h $(INTEGRATE_H) \
insn-config.h input.h $(PARAMS_H) debug.h $(TREE_INLINE_H) $(GIMPLE_H) \
- $(TARGET_H) tree-iterator.h
+ $(TARGET_H) tree-iterator.h $(CGRAPH_H)
cp/mangle.o: cp/mangle.c $(CXX_TREE_H) $(TM_H) toplev.h $(REAL_H) \
gt-cp-mangle.h $(TARGET_H) $(TM_P_H)
cp/parser.o: cp/parser.c $(CXX_TREE_H) $(TM_H) $(DIAGNOSTIC_H) gt-cp-parser.h \
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index a71dc73..3652fe0 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5037,6 +5037,7 @@ extern void finish_eh_cleanup (tree);
extern void emit_associated_thunks (tree);
extern void finish_mem_initializers (tree);
extern tree check_template_template_default_arg (tree);
+extern bool expand_or_defer_fn_1 (tree);
extern void expand_or_defer_fn (tree);
extern void check_accessibility_of_qualified_id (tree, tree, tree);
extern tree finish_qualified_id_expr (tree, tree, bool, bool,
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 7c3f7c05..c0febad 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -3658,7 +3658,19 @@ cp_write_global_declarations (void)
if (DECL_NOT_REALLY_EXTERN (decl)
&& DECL_INITIAL (decl)
&& decl_needed_p (decl))
- DECL_EXTERNAL (decl) = 0;
+ {
+ struct cgraph_node *node = cgraph_get_node (decl), *alias;
+
+ DECL_EXTERNAL (decl) = 0;
+ /* If we mark !DECL_EXTERNAL one of the same body aliases,
+ we need to mark all of them that way. */
+ if (node && node->same_body)
+ {
+ DECL_EXTERNAL (node->decl) = 0;
+ for (alias = node->same_body; alias; alias = alias->next)
+ DECL_EXTERNAL (alias->decl) = 0;
+ }
+ }
/* If we're going to need to write this function out, and
there's already a body for it, create RTL for it now.
diff --git a/gcc/cp/optimize.c b/gcc/cp/optimize.c
index 662bd4a..c691f0b 100644
--- a/gcc/cp/optimize.c
+++ b/gcc/cp/optimize.c
@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-dump.h"
#include "gimple.h"
#include "tree-iterator.h"
+#include "cgraph.h"
/* Prototypes. */
@@ -149,8 +150,10 @@ bool
maybe_clone_body (tree fn)
{
tree clone;
- tree complete_dtor = NULL_TREE;
+ tree fns[3];
bool first = true;
+ bool in_charge_parm_used;
+ int idx;
/* We only clone constructors and destructors. */
if (!DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
@@ -160,25 +163,40 @@ maybe_clone_body (tree fn)
/* Emit the DWARF1 abstract instance. */
(*debug_hooks->deferred_inline_function) (fn);
+ in_charge_parm_used = CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)) != NULL;
+ fns[0] = NULL_TREE;
+ fns[1] = NULL_TREE;
+ fns[2] = NULL_TREE;
+
/* Look for the complete destructor which may be used to build the
delete destructor. */
FOR_EACH_CLONE (clone, fn)
- if (DECL_NAME (clone) == complete_dtor_identifier)
- {
- complete_dtor = clone;
- break;
- }
+ if (DECL_NAME (clone) == complete_dtor_identifier
+ || DECL_NAME (clone) == complete_ctor_identifier)
+ fns[1] = clone;
+ else if (DECL_NAME (clone) == base_dtor_identifier
+ || DECL_NAME (clone) == base_ctor_identifier)
+ fns[0] = clone;
+ else if (DECL_NAME (clone) == deleting_dtor_identifier)
+ fns[2] = clone;
+ else
+ gcc_unreachable ();
/* We know that any clones immediately follow FN in the TYPE_METHODS
list. */
push_to_top_level ();
- FOR_EACH_CLONE (clone, fn)
+ for (idx = 0; idx < 3; idx++)
{
tree parm;
tree clone_parm;
int parmno;
+ bool alias = false;
struct pointer_map_t *decl_map;
+ clone = fns[idx];
+ if (!clone)
+ continue;
+
/* Update CLONE's source position information to match FN's. */
DECL_SOURCE_LOCATION (clone) = DECL_SOURCE_LOCATION (fn);
DECL_DECLARED_INLINE_P (clone) = DECL_DECLARED_INLINE_P (fn);
@@ -223,12 +241,25 @@ maybe_clone_body (tree fn)
/* Start processing the function. */
start_preparsed_function (clone, NULL_TREE, SF_PRE_PARSED);
+ /* Tell cgraph if both ctors or both dtors are known to have
+ the same body. */
+ if (!in_charge_parm_used
+ && fns[0]
+ && idx == 1
+ && !flag_use_repository
+ && DECL_INTERFACE_KNOWN (fns[0])
+ && !DECL_ONE_ONLY (fns[0])
+ && cgraph_same_body_alias (clone, fns[0]))
+ alias = true;
+
/* Build the delete destructor by calling complete destructor
and delete function. */
- if (DECL_NAME (clone) == deleting_dtor_identifier)
- build_delete_destructor_body (clone, complete_dtor);
+ if (idx == 2)
+ build_delete_destructor_body (clone, fns[1]);
+ else if (alias)
+ /* No need to populate body. */ ;
else
- {
+ {
/* Remap the parameters. */
decl_map = pointer_map_create ();
for (parmno = 0,
@@ -291,7 +322,10 @@ maybe_clone_body (tree fn)
/* Now, expand this function into RTL, if appropriate. */
finish_function (0);
BLOCK_ABSTRACT_ORIGIN (DECL_INITIAL (clone)) = DECL_INITIAL (fn);
- expand_or_defer_fn (clone);
+ if (alias)
+ expand_or_defer_fn_1 (clone);
+ else
+ expand_or_defer_fn (clone);
first = false;
}
pop_from_top_level ();
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index c1df24b..7401593 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -3315,8 +3315,8 @@ emit_associated_thunks (tree fn)
/* Generate RTL for FN. */
-void
-expand_or_defer_fn (tree fn)
+bool
+expand_or_defer_fn_1 (tree fn)
{
/* When the parser calls us after finishing the body of a template
function, we don't really want to expand the body. */
@@ -3330,7 +3330,7 @@ expand_or_defer_fn (tree fn)
is not a GC root. */
if (!function_depth)
ggc_collect ();
- return;
+ return false;
}
gcc_assert (DECL_SAVED_TREE (fn));
@@ -3343,7 +3343,7 @@ expand_or_defer_fn (tree fn)
it out, even though we haven't. */
TREE_ASM_WRITTEN (fn) = 1;
DECL_SAVED_TREE (fn) = NULL_TREE;
- return;
+ return false;
}
/* We make a decision about linkage for these functions at the end
@@ -3390,14 +3390,23 @@ expand_or_defer_fn (tree fn)
/* There's no reason to do any of the work here if we're only doing
semantic analysis; this code just generates RTL. */
if (flag_syntax_only)
- return;
+ return false;
- function_depth++;
+ return true;
+}
+
+void
+expand_or_defer_fn (tree fn)
+{
+ if (expand_or_defer_fn_1 (fn))
+ {
+ function_depth++;
- /* Expand or defer, at the whim of the compilation unit manager. */
- cgraph_finalize_function (fn, function_depth > 1);
+ /* Expand or defer, at the whim of the compilation unit manager. */
+ cgraph_finalize_function (fn, function_depth > 1);
- function_depth--;
+ function_depth--;
+ }
}
struct nrv_data