aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.4.0/gcc/cp/optimize.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.4.0/gcc/cp/optimize.c')
-rw-r--r--gcc-4.4.0/gcc/cp/optimize.c167
1 files changed, 114 insertions, 53 deletions
diff --git a/gcc-4.4.0/gcc/cp/optimize.c b/gcc-4.4.0/gcc/cp/optimize.c
index 8c7b9e82c..3a971abc9 100644
--- a/gcc-4.4.0/gcc/cp/optimize.c
+++ b/gcc-4.4.0/gcc/cp/optimize.c
@@ -1,5 +1,5 @@
/* Perform optimizations on tree structure.
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2009
Free Software Foundation, Inc.
Written by Mark Michell (mark@codesourcery.com).
@@ -108,6 +108,43 @@ clone_body (tree clone, tree fn, void *arg_map)
gimple_set_body (clone, new_body);
}
+/* DELETE_DTOR is a delete destructor whose body will be built.
+ COMPLETE_DTOR is the corresponding complete destructor. */
+
+static void
+build_delete_destructor_body (tree delete_dtor, tree complete_dtor)
+{
+ tree call_dtor, call_delete;
+ tree parm = DECL_ARGUMENTS (delete_dtor);
+ tree virtual_size = cxx_sizeof (current_class_type);
+
+ DECL_SAVED_TREE (delete_dtor) = push_stmt_list ();
+
+ /* Call the corresponding complete destructor. */
+ gcc_assert (complete_dtor);
+ call_dtor = build_cxx_call (complete_dtor, 1, &parm);
+ add_stmt (call_dtor);
+
+ add_stmt (build_stmt (LABEL_EXPR, cdtor_label));
+
+ /* Call the delete function. */
+ call_delete = build_op_delete_call (DELETE_EXPR, current_class_ptr,
+ virtual_size,
+ /*global_p=*/false,
+ /*placement=*/NULL_TREE,
+ /*alloc_fn=*/NULL_TREE);
+ add_stmt (call_delete);
+
+ /* Return the address of the object. */
+ if (targetm.cxx.cdtor_returns_this ())
+ {
+ tree val = DECL_ARGUMENTS (delete_dtor);
+ val = build2 (MODIFY_EXPR, TREE_TYPE (val),
+ DECL_RESULT (delete_dtor), val);
+ add_stmt (build_stmt (RETURN_EXPR, val));
+ }
+}
+
/* FN is a function that has a complete body. Clone the body as
necessary. Returns nonzero if there's no longer any need to
process the main body. */
@@ -116,6 +153,7 @@ bool
maybe_clone_body (tree fn)
{
tree clone;
+ tree complete_dtor = NULL_TREE;
bool first = true;
/* We only clone constructors and destructors. */
@@ -126,6 +164,15 @@ maybe_clone_body (tree fn)
/* Emit the DWARF1 abstract instance. */
(*debug_hooks->deferred_inline_function) (fn);
+ /* 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;
+ }
+
/* We know that any clones immediately follow FN in the TYPE_METHODS
list. */
push_to_top_level ();
@@ -173,58 +220,66 @@ maybe_clone_body (tree fn)
/* Start processing the function. */
start_preparsed_function (clone, NULL_TREE, SF_PRE_PARSED);
- /* Remap the parameters. */
- decl_map = pointer_map_create ();
- for (parmno = 0,
- parm = DECL_ARGUMENTS (fn),
- clone_parm = DECL_ARGUMENTS (clone);
- parm;
- ++parmno,
- parm = TREE_CHAIN (parm))
- {
- /* Map the in-charge parameter to an appropriate constant. */
- if (DECL_HAS_IN_CHARGE_PARM_P (fn) && parmno == 1)
- {
- tree in_charge;
- in_charge = in_charge_arg_for_name (DECL_NAME (clone));
- *pointer_map_insert (decl_map, parm) = in_charge;
- }
- else if (DECL_ARTIFICIAL (parm)
- && DECL_NAME (parm) == vtt_parm_identifier)
- {
- /* For a subobject constructor or destructor, the next
- argument is the VTT parameter. Remap the VTT_PARM
- from the CLONE to this parameter. */
- if (DECL_HAS_VTT_PARM_P (clone))
- {
- DECL_ABSTRACT_ORIGIN (clone_parm) = parm;
- *pointer_map_insert (decl_map, parm) = clone_parm;
- clone_parm = TREE_CHAIN (clone_parm);
- }
- /* Otherwise, map the VTT parameter to `NULL'. */
- else
- *pointer_map_insert (decl_map, parm) = null_pointer_node;
- }
- /* Map other parameters to their equivalents in the cloned
- function. */
- else
- {
- *pointer_map_insert (decl_map, parm) = clone_parm;
- clone_parm = TREE_CHAIN (clone_parm);
- }
- }
-
- if (targetm.cxx.cdtor_returns_this ())
- {
- parm = DECL_RESULT (fn);
- clone_parm = DECL_RESULT (clone);
- *pointer_map_insert (decl_map, parm) = clone_parm;
- }
- /* Clone the body. */
- clone_body (clone, fn, decl_map);
-
- /* Clean up. */
- pointer_map_destroy (decl_map);
+ /* 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);
+ else
+ {
+ /* Remap the parameters. */
+ decl_map = pointer_map_create ();
+ for (parmno = 0,
+ parm = DECL_ARGUMENTS (fn),
+ clone_parm = DECL_ARGUMENTS (clone);
+ parm;
+ ++parmno,
+ parm = TREE_CHAIN (parm))
+ {
+ /* Map the in-charge parameter to an appropriate constant. */
+ if (DECL_HAS_IN_CHARGE_PARM_P (fn) && parmno == 1)
+ {
+ tree in_charge;
+ in_charge = in_charge_arg_for_name (DECL_NAME (clone));
+ *pointer_map_insert (decl_map, parm) = in_charge;
+ }
+ else if (DECL_ARTIFICIAL (parm)
+ && DECL_NAME (parm) == vtt_parm_identifier)
+ {
+ /* For a subobject constructor or destructor, the next
+ argument is the VTT parameter. Remap the VTT_PARM
+ from the CLONE to this parameter. */
+ if (DECL_HAS_VTT_PARM_P (clone))
+ {
+ DECL_ABSTRACT_ORIGIN (clone_parm) = parm;
+ *pointer_map_insert (decl_map, parm) = clone_parm;
+ clone_parm = TREE_CHAIN (clone_parm);
+ }
+ /* Otherwise, map the VTT parameter to `NULL'. */
+ else
+ *pointer_map_insert (decl_map, parm) = null_pointer_node;
+ }
+ /* Map other parameters to their equivalents in the cloned
+ function. */
+ else
+ {
+ *pointer_map_insert (decl_map, parm) = clone_parm;
+ clone_parm = TREE_CHAIN (clone_parm);
+ }
+ }
+
+ if (targetm.cxx.cdtor_returns_this ())
+ {
+ parm = DECL_RESULT (fn);
+ clone_parm = DECL_RESULT (clone);
+ *pointer_map_insert (decl_map, parm) = clone_parm;
+ }
+
+ /* Clone the body. */
+ clone_body (clone, fn, decl_map);
+
+ /* Clean up. */
+ pointer_map_destroy (decl_map);
+ }
/* The clone can throw iff the original function can throw. */
cp_function_chain->can_throw = !TREE_NOTHROW (fn);
@@ -232,6 +287,12 @@ 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);
+
+ /* Gimplify the new built deleting destructor. Gcc 4.5 doesn't need
+ this since the gimplification occurs in a later pass. */
+ if (DECL_NAME (clone) == deleting_dtor_identifier)
+ gimplify_function_tree (clone);
+
DECL_SAVED_TREE (clone) = NULL;
expand_or_defer_fn (clone);
first = false;