This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[basic-improvements] C++ PATCH to build_vec_init
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 25 Nov 2002 18:09:32 -0500
- Subject: [basic-improvements] C++ PATCH to build_vec_init
A minor simplification to use 'for' rather than both 'if' and 'do/while'.
The 'if' was a recent addition for correctness when some elements have
explicit initializers.
Mark: I'm unclear on the purpose of clearing stmts_are_full_exprs_p in
build_vec_init. Removing that code doesn't seem to break anything. Why is
it there?
Tested i686-pc-linux-gnu.
2002-11-25 Jason Merrill <jason@redhat.com>
* init.c (build_vec_init): Use a FOR_STMT instead of an IF_STMT
and a DO_STMT.
*** init.c.~1~ 2002-10-29 13:03:11.000000000 -0500
--- init.c 2002-11-24 13:58:45.000000000 -0500
*************** build_new_1 (exp)
*** 2445,2451 ****
things; in particular, it would make it difficult to bail out
if the allocation function returns null. Er, no, it wouldn't;
we just don't run the constructor. The standard says it's
! unspecified whether or not the args are evaluated. */
if (cleanup)
{
--- 2445,2454 ----
things; in particular, it would make it difficult to bail out
if the allocation function returns null. Er, no, it wouldn't;
we just don't run the constructor. The standard says it's
! unspecified whether or not the args are evaluated.
!
! FIXME FIXME FIXME inline invisible refs as refs. That way we
! can preevaluate value parameters. */
if (cleanup)
{
*************** build_vec_init (base, init, from_array)
*** 2753,2762 ****
T* rval = t1;
ptrdiff_t iterator = maxindex;
try {
! do {
... initialize *t1 ...
++t1;
! } while (--iterator != -1);
} catch (...) {
... destroy elements that were constructed ...
}
--- 2756,2765 ----
T* rval = t1;
ptrdiff_t iterator = maxindex;
try {
! for (; iterator != -1; --iterator) {
... initialize *t1 ...
++t1;
! }
} catch (...) {
... destroy elements that were constructed ...
}
*************** build_vec_init (base, init, from_array)
*** 2856,2874 ****
{
/* If the ITERATOR is equal to -1, then we don't have to loop;
we've already initialized all the elements. */
! tree if_stmt;
! tree do_stmt;
! tree do_body;
tree elt_init;
! if_stmt = begin_if_stmt ();
! finish_if_stmt_cond (build (NE_EXPR, boolean_type_node,
! iterator, integer_minus_one_node),
! if_stmt);
/* Otherwise, loop through the elements. */
! do_stmt = begin_do_stmt ();
! do_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,
--- 2860,2879 ----
{
/* If the ITERATOR is equal to -1, then we don't have to loop;
we've already initialized all the elements. */
! tree for_stmt;
! tree for_body;
tree elt_init;
! for_stmt = begin_for_stmt ();
! finish_for_init_stmt (for_stmt);
! finish_for_cond (build (NE_EXPR, boolean_type_node,
! iterator, integer_minus_one_node),
! for_stmt);
! finish_for_expr (build_unary_op (PREDECREMENT_EXPR, iterator, 0),
! for_stmt);
/* 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,
*************** build_vec_init (base, init, from_array)
*** 2933,2947 ****
if (base2)
finish_expr_stmt (build_unary_op (PREINCREMENT_EXPR, base2, 0));
! finish_compound_stmt (/*has_no_scope=*/1, do_body);
! finish_do_body (do_stmt);
! finish_do_stmt (build (NE_EXPR, boolean_type_node,
! build_unary_op (PREDECREMENT_EXPR, iterator, 0),
! integer_minus_one_node),
! do_stmt);
!
! finish_then_clause (if_stmt);
! finish_if_stmt ();
}
/* Make sure to cleanup any partially constructed elements. */
--- 2938,2945 ----
if (base2)
finish_expr_stmt (build_unary_op (PREINCREMENT_EXPR, base2, 0));
! finish_compound_stmt (/*has_no_scope=*/1, for_body);
! finish_for_stmt (for_stmt);
}
/* Make sure to cleanup any partially constructed elements. */