This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH]: Clean up init.c
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Mark Mitchell <mitchell at codesourcery dot com>
- Date: Sat, 26 Jul 2003 20:13:20 +0100
- Subject: [C++ PATCH]: Clean up init.c
- Organization: Codesourcery LLC
I've installed the attached patch which removes some unreachable code.
One of the things begin_global_stmt_expr is begin building a stmt
tree, therefore all of the later tests for that mode succeed. That code
is a remnant when we still did some things in statement at a time mode.
booted & tested on i686-pc-linux-gnu.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2003-07-26 Nathan Sidwell <nathan@codesourcery.com>
* cp-tree.h (begin_init_stmts, finish_init_stmts): Remove.
(begin_global_stmt_expr, finish_global_stmt_expr): Remove.
* init.c (begin_init_stmts): Make static. Return is_global
value. Always call begin_stmt_expr.
(finish_init_stmts): Make static. Add is_global parm. Always
building a stmt tree.
(build_aggr_init): Adjust begin_init_stmts, finish_init_stmts calls.
(build_vec_init): Likewise. Always building a stmt tree.
(expand_default_init): Always building a stmt tree.
(get_temp_regvar): Likewise.
* semantics.c (begin_global_stmt_expr,
finish_global_stmt_expr): Remove.
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.890
diff -c -3 -p -r1.890 cp-tree.h
*** cp/cp-tree.h 25 Jul 2003 16:52:46 -0000 1.890
--- cp/cp-tree.h 26 Jul 2003 17:37:02 -0000
*************** extern void push_base_cleanups (void);
*** 3891,3898 ****
extern tree build_vbase_delete (tree, tree);
extern tree build_vec_delete (tree, tree, special_function_kind, int);
extern tree create_temporary_var (tree);
- extern void begin_init_stmts (tree *, tree *);
- extern tree finish_init_stmts (tree, tree);
extern void initialize_vtbl_ptrs (tree);
extern tree build_java_class_ref (tree);
--- 3891,3896 ----
*************** extern tree do_poplevel
*** 4178,4185 ****
extern void finish_mem_initializers (tree);
extern void setup_vtbl_ptr (tree, tree);
extern void clear_out_block (void);
- extern tree begin_global_stmt_expr (void);
- extern tree finish_global_stmt_expr (tree);
extern tree check_template_template_default_arg (tree);
extern void expand_or_defer_fn (tree);
extern void check_accessibility_of_qualified_id (tree, tree, tree);
--- 4176,4181 ----
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.334
diff -c -3 -p -r1.334 init.c
*** cp/init.c 25 Jul 2003 16:52:46 -0000 1.334
--- cp/init.c 26 Jul 2003 17:37:39 -0000
*************** Boston, MA 02111-1307, USA. */
*** 35,40 ****
--- 35,42 ----
#include "except.h"
#include "toplev.h"
+ static bool begin_init_stmts (tree *, tree *);
+ static tree finish_init_stmts (bool, tree, tree);
static void construct_virtual_base (tree, tree);
static void expand_aggr_init_1 (tree, tree, tree, tree, int);
static void expand_default_init (tree, tree, tree, tree, int);
*************** static tree build_vtbl_address (tree);
*** 64,103 ****
pass them back to finish_init_stmts when the expression is
complete. */
! void
begin_init_stmts (tree *stmt_expr_p, tree *compound_stmt_p)
{
! if (building_stmt_tree ())
! *stmt_expr_p = begin_stmt_expr ();
! else
! *stmt_expr_p = begin_global_stmt_expr ();
! if (building_stmt_tree ())
! *compound_stmt_p = begin_compound_stmt (/*has_no_scope=*/1);
}
/* Finish out the statement-expression begun by the previous call to
begin_init_stmts. Returns the statement-expression itself. */
! tree
! finish_init_stmts (tree stmt_expr, tree compound_stmt)
{
! if (building_stmt_tree ())
! finish_compound_stmt (/*has_no_scope=*/1, compound_stmt);
!
! if (building_stmt_tree ())
! {
! stmt_expr = finish_stmt_expr (stmt_expr);
! STMT_EXPR_NO_SCOPE (stmt_expr) = true;
! }
! else
! stmt_expr = finish_global_stmt_expr (stmt_expr);
! /* To avoid spurious warnings about unused values, we set
! TREE_USED. */
! if (stmt_expr)
! TREE_USED (stmt_expr) = 1;
return stmt_expr;
}
--- 66,96 ----
pass them back to finish_init_stmts when the expression is
complete. */
! static bool
begin_init_stmts (tree *stmt_expr_p, tree *compound_stmt_p)
{
! bool is_global = !building_stmt_tree ();
! *stmt_expr_p = begin_stmt_expr ();
! *compound_stmt_p = begin_compound_stmt (/*has_no_scope=*/1);
!
! return is_global;
}
/* Finish out the statement-expression begun by the previous call to
begin_init_stmts. Returns the statement-expression itself. */
! static tree
! finish_init_stmts (bool is_global, tree stmt_expr, tree compound_stmt)
{
! finish_compound_stmt (/*has_no_scope=*/1, compound_stmt);
! stmt_expr = finish_stmt_expr (stmt_expr);
! STMT_EXPR_NO_SCOPE (stmt_expr) = true;
! TREE_USED (stmt_expr) = 1;
+ my_friendly_assert (!building_stmt_tree () == is_global, 20030726);
+
return stmt_expr;
}
*************** build_aggr_init (tree exp, tree init, in
*** 1045,1050 ****
--- 1038,1044 ----
tree type = TREE_TYPE (exp);
int was_const = TREE_READONLY (exp);
int was_volatile = TREE_THIS_VOLATILE (exp);
+ int is_global;
if (init == error_mark_node)
return error_mark_node;
*************** build_aggr_init (tree exp, tree init, in
*** 1098,1109 ****
TREE_USED (exp) = 1;
TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type);
! begin_init_stmts (&stmt_expr, &compound_stmt);
destroy_temps = stmts_are_full_exprs_p ();
current_stmt_tree ()->stmts_are_full_exprs_p = 0;
expand_aggr_init_1 (TYPE_BINFO (type), exp, exp,
init, LOOKUP_NORMAL|flags);
! stmt_expr = finish_init_stmts (stmt_expr, compound_stmt);
current_stmt_tree ()->stmts_are_full_exprs_p = destroy_temps;
TREE_TYPE (exp) = type;
TREE_READONLY (exp) = was_const;
--- 1092,1103 ----
TREE_USED (exp) = 1;
TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type);
! is_global = begin_init_stmts (&stmt_expr, &compound_stmt);
destroy_temps = stmts_are_full_exprs_p ();
current_stmt_tree ()->stmts_are_full_exprs_p = 0;
expand_aggr_init_1 (TYPE_BINFO (type), exp, exp,
init, LOOKUP_NORMAL|flags);
! stmt_expr = finish_init_stmts (is_global, stmt_expr, compound_stmt);
current_stmt_tree ()->stmts_are_full_exprs_p = destroy_temps;
TREE_TYPE (exp) = type;
TREE_READONLY (exp) = was_const;
*************** expand_default_init (tree binfo, tree tr
*** 1200,1211 ****
rval = build_special_member_call (exp, ctor_name, parms, binfo, flags);
if (TREE_SIDE_EFFECTS (rval))
! {
! if (building_stmt_tree ())
! finish_expr_stmt (rval);
! else
! genrtl_expr_stmt (rval);
! }
}
/* This function is responsible for initializing EXP with INIT
--- 1194,1200 ----
rval = build_special_member_call (exp, ctor_name, parms, binfo, flags);
if (TREE_SIDE_EFFECTS (rval))
! finish_expr_stmt (rval);
}
/* This function is responsible for initializing EXP with INIT
*************** get_temp_regvar (tree type, tree init)
*** 2377,2386 ****
tree decl;
decl = create_temporary_var (type);
! if (building_stmt_tree ())
! add_decl_stmt (decl);
! else
! SET_DECL_RTL (decl, assign_temp (type, 2, 0, 1));
finish_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
return decl;
--- 2366,2373 ----
tree decl;
decl = create_temporary_var (type);
! add_decl_stmt (decl);
!
finish_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
return decl;
*************** build_vec_init (tree base, tree maxindex
*** 2422,2428 ****
tree try_block = NULL_TREE;
tree try_body = NULL_TREE;
int num_initialized_elts = 0;
!
if (TYPE_DOMAIN (atype))
maxindex = array_type_nelts (atype);
--- 2409,2416 ----
tree try_block = NULL_TREE;
tree try_body = NULL_TREE;
int num_initialized_elts = 0;
! bool is_global;
!
if (TYPE_DOMAIN (atype))
maxindex = array_type_nelts (atype);
*************** build_vec_init (tree base, tree maxindex
*** 2483,2489 ****
of whatever cleverness the back-end has for dealing with copies
of blocks of memory. */
! begin_init_stmts (&stmt_expr, &compound_stmt);
destroy_temps = stmts_are_full_exprs_p ();
current_stmt_tree ()->stmts_are_full_exprs_p = 0;
rval = get_temp_regvar (ptype, base);
--- 2471,2477 ----
of whatever cleverness the back-end has for dealing with copies
of blocks of memory. */
! is_global = begin_init_stmts (&stmt_expr, &compound_stmt);
destroy_temps = stmts_are_full_exprs_p ();
current_stmt_tree ()->stmts_are_full_exprs_p = 0;
rval = get_temp_regvar (ptype, base);
*************** build_vec_init (tree base, tree maxindex
*** 2578,2597 ****
/* Otherwise, loop through the elements. */
for_body = begin_compound_stmt (/*has_no_scope=*/1);
- /* When we're not building a statement-tree, things are a little
- complicated. If, when we recursively call build_aggr_init,
- an expression containing a TARGET_EXPR is expanded, then it
- may get a cleanup. Then, the result of that expression is
- passed to finish_expr_stmt, which will call
- expand_start_target_temps/expand_end_target_temps. However,
- the latter call will not cause the cleanup to run because
- that block will still be on the block stack. So, we call
- expand_start_target_temps here manually; the corresponding
- call to expand_end_target_temps below will cause the cleanup
- to be performed. */
- if (!building_stmt_tree ())
- expand_start_target_temps ();
-
if (from_array)
{
tree to = build1 (INDIRECT_REF, type, base);
--- 2566,2571 ----
*************** build_vec_init (tree base, tree maxindex
*** 2623,2641 ****
elt_init = build_aggr_init (build1 (INDIRECT_REF, type, base),
init, 0);
! /* The initialization of each array element is a
! full-expression, as per core issue 124. */
! if (!building_stmt_tree ())
! {
! genrtl_expr_stmt (elt_init);
! expand_end_target_temps ();
! }
! else
! {
! current_stmt_tree ()->stmts_are_full_exprs_p = 1;
! finish_expr_stmt (elt_init);
! current_stmt_tree ()->stmts_are_full_exprs_p = 0;
! }
finish_expr_stmt (build_unary_op (PREINCREMENT_EXPR, base, 0));
if (base2)
--- 2597,2605 ----
elt_init = build_aggr_init (build1 (INDIRECT_REF, type, base),
init, 0);
! current_stmt_tree ()->stmts_are_full_exprs_p = 1;
! finish_expr_stmt (elt_init);
! current_stmt_tree ()->stmts_are_full_exprs_p = 0;
finish_expr_stmt (build_unary_op (PREINCREMENT_EXPR, base, 0));
if (base2)
*************** build_vec_init (tree base, tree maxindex
*** 2674,2680 ****
first element in the array. */
finish_expr_stmt (rval);
! stmt_expr = finish_init_stmts (stmt_expr, compound_stmt);
current_stmt_tree ()->stmts_are_full_exprs_p = destroy_temps;
return stmt_expr;
}
--- 2638,2644 ----
first element in the array. */
finish_expr_stmt (rval);
! stmt_expr = finish_init_stmts (is_global, stmt_expr, compound_stmt);
current_stmt_tree ()->stmts_are_full_exprs_p = destroy_temps;
return stmt_expr;
}
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.335
diff -c -3 -p -r1.335 semantics.c
*** cp/semantics.c 25 Jul 2003 16:45:34 -0000 1.335
--- cp/semantics.c 26 Jul 2003 17:38:10 -0000
*************** begin_stmt_expr (void)
*** 1425,1459 ****
return last_tree;
}
- /* Used when beginning a statement-expression outside function scope.
- For example, when handling a file-scope initializer, we use this
- function. */
-
- tree
- begin_global_stmt_expr (void)
- {
- if (! cfun && !last_tree)
- begin_stmt_tree (&scope_chain->x_saved_tree);
-
- keep_next_level (1);
-
- return last_tree ? last_tree : expand_start_stmt_expr(/*has_scope=*/1);
- }
-
- /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
-
- tree
- finish_global_stmt_expr (tree stmt_expr)
- {
- stmt_expr = expand_end_stmt_expr (stmt_expr);
-
- if (! cfun
- && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
- finish_stmt_tree (&scope_chain->x_saved_tree);
-
- return stmt_expr;
- }
-
/* Finish a statement-expression. RTL_EXPR should be the value
returned by the previous begin_stmt_expr; EXPR is the
statement-expression. Returns an expression representing the
--- 1425,1430 ----