+2011-05-27 Nathan Froyd <froydnj@codesourcery.com>
+
+ * c-decl.c (c_push_function_context): Copy the current statement
+ list stack.
+ (add_stmt): Check building_stmt_list_p and push_stmt if necessary.
+ (finish_struct): Call building_stmt_list_p instead of checking
+ cur_stmt_list.
+ * c-parser.c (c_parser_postfix_expression): Likewise.
+ * c-typeck.c (c_end_compound_stmt): Likewise.
+ * print-tree.c (print_node) [STATEMENT_LIST]: Don't print TREE_CHAIN.
+ * tree-iterator.c (stmt_list_cache): Change to a VEC.
+ (alloc_stmt_list): Adjust for stmt_list_cache's new type.
+ (free_stmt_list): Likewise.
+ * tree.h (struct tree_statement_list): Include typed_tree instead
+ of tree_common.
+ * tree.c (initialize_tree_contains_struct): Mark TS_STATEMENT_LIST
+ as TS_TYPED instead of TS_COMMON.
+
2011-05-27 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Uros Bizjak <ubizjak@gmail.com>
/* Add T to the statement-tree. Non-side-effect statements need to be
recorded during statement expressions. */
+ if (!building_stmt_list_p ())
+ push_stmt_list ();
append_to_statement_list_force (t, &cur_stmt_list);
return t;
/* If we're inside a function proper, i.e. not file-scope and not still
parsing parameters, then arrange for the size of a variable sized type
to be bound now. */
- if (cur_stmt_list && variably_modified_type_p (t, NULL_TREE))
+ if (building_stmt_list_p () && variably_modified_type_p (t, NULL_TREE))
add_stmt (build_stmt (loc,
DECL_EXPR, build_decl (loc, TYPE_DECL, NULL, t)));
cfun->language = p;
p->base.x_stmt_tree = c_stmt_tree;
+ c_stmt_tree.x_cur_stmt_list
+ = VEC_copy (tree, gc, c_stmt_tree.x_cur_stmt_list);
p->x_break_label = c_break_label;
p->x_cont_label = c_cont_label;
p->x_switch_stack = c_switch_stack;
+2011-05-27 Nathan Froyd <froydnj@codesourcery.com>
+
+ * c-common.h (struct stmt_tree_s) [x_cur_stmt_list]: Change to a VEC.
+ (stmt_list_stack): Define.
+ (cur_stmt_list): Adjust for new type of x_cur_stmt_list.
+ * c-semantics.c (push_stmt_list, pop_stmt_list): Likewise.
+
2011-05-26 Nathan Froyd <froydnj@codesourcery.com>
* c-common.c (warning_candidate_p): Check for BLOCKs.
/* Information about a statement tree. */
struct GTY(()) stmt_tree_s {
- /* The current statement list being collected. */
- tree x_cur_stmt_list;
+ /* A stack of statement lists being collected. */
+ VEC(tree,gc) *x_cur_stmt_list;
/* In C++, Nonzero if we should treat statements as full
expressions. In particular, this variable is no-zero if at the
struct stmt_tree_s x_stmt_tree;
};
+#define stmt_list_stack (current_stmt_tree ()->x_cur_stmt_list)
+
/* When building a statement-tree, this is the current statement list
- being collected. It's TREE_CHAIN is a back-pointer to the previous
- statement list. */
+ being collected. We define it in this convoluted way, rather than
+ using VEC_last, because it must be an lvalue. */
+
+#define cur_stmt_list \
+ (*(VEC_address (tree, stmt_list_stack) \
+ + VEC_length (tree, stmt_list_stack) - 1))
-#define cur_stmt_list (current_stmt_tree ()->x_cur_stmt_list)
+#define building_stmt_list_p() (!VEC_empty (tree, stmt_list_stack))
/* Language-specific hooks. */
{
tree t;
t = alloc_stmt_list ();
- TREE_CHAIN (t) = cur_stmt_list;
- cur_stmt_list = t;
+ VEC_safe_push (tree, gc, stmt_list_stack, t);
return t;
}
tree
pop_stmt_list (tree t)
{
- tree u = cur_stmt_list, chain;
+ tree u = NULL_TREE;
/* Pop statement lists until we reach the target level. The extra
nestings will be due to outstanding cleanups. */
while (1)
{
- chain = TREE_CHAIN (u);
- TREE_CHAIN (u) = NULL_TREE;
- if (chain)
- STATEMENT_LIST_HAS_LABEL (chain) |= STATEMENT_LIST_HAS_LABEL (u);
+ u = VEC_pop (tree, stmt_list_stack);
+ if (!VEC_empty (tree, stmt_list_stack))
+ {
+ tree x = VEC_last (tree, stmt_list_stack);
+ STATEMENT_LIST_HAS_LABEL (x) |= STATEMENT_LIST_HAS_LABEL (u);
+ }
if (t == u)
break;
- u = chain;
}
- cur_stmt_list = chain;
+
+ gcc_assert (u != NULL_TREE);
/* If the statement list is completely empty, just return it. This is
just as good small as build_empty_stmt, with the advantage that
c_parser_consume_token (parser);
brace_loc = c_parser_peek_token (parser)->location;
c_parser_consume_token (parser);
- if (cur_stmt_list == NULL)
+ if (!building_stmt_list_p ())
{
error_at (loc, "braced-group within expression allowed "
"only inside a function");
do the wrong thing for ({ { 1; } }) or ({ 1; { } }). In particular,
STATEMENT_LISTs merge, and thus we can lose track of what statement
was really last. */
- if (cur_stmt_list
+ if (building_stmt_list_p ()
&& STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
&& TREE_CODE (stmt) != BIND_EXPR)
{
+2011-05-27 Nathan Froyd <froydnj@codesourcery.com>
+
+ * cp-tree.h (building_stmt_tree): Delete.
+ * decl.c (save_function_data): Tweak initializer for x_cur_stmt_list.
+ (build_aggr_init_full_exprs): Call building_stmt_list_p
+ instead of building_stmt_tree.
+ (initialize_local_var): Likewise.
+ (finish_function): Likewise.
+ * decl2.c (finish_anon_union): Likewise.
+ * init.c (begin_init_stmts): Likewise.
+ (finish_init_stmts): Likewise.
+ (expand_aggr_init_1): Likewise.
+ * name-lookup.c (do_local_using_decl): Likewise.
+ (do_namespace_alias): Likewise.
+ (do_using_directive): Likewise.
+ (cp_emit_debug_info_for_using): Likewise.
+ * semantics.c (add_stmt): Assert that stmt_list_stack is non-empty.
+
2011-05-27 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/42056
#define same_type_p(TYPE1, TYPE2) \
comptypes ((TYPE1), (TYPE2), COMPARE_STRICT)
-/* Nonzero if we are presently building a statement tree, rather
- than expanding each statement as we encounter it. */
-#define building_stmt_tree() (cur_stmt_list != NULL_TREE)
-
/* Returns nonzero iff NODE is a declaration for the global function
`main'. */
#define DECL_MAIN_P(NODE) \
{
int saved_stmts_are_full_exprs_p = 0;
- if (building_stmt_tree ())
+ if (building_stmt_list_p ())
{
saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
current_stmt_tree ()->stmts_are_full_exprs_p = 1;
}
init = build_aggr_init (decl, init, flags, tf_warning_or_error);
- if (building_stmt_tree ())
+ if (building_stmt_list_p ())
current_stmt_tree ()->stmts_are_full_exprs_p =
saved_stmts_are_full_exprs_p;
return init;
if (cleanup && TREE_CODE (type) != ARRAY_TYPE)
wrap_temporary_cleanups (init, cleanup);
- gcc_assert (building_stmt_tree ());
+ gcc_assert (building_stmt_list_p ());
saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
current_stmt_tree ()->stmts_are_full_exprs_p = 1;
finish_expr_stmt (init);
DECL_SAVED_FUNCTION_DATA (decl) = f;
/* Clear out the bits we don't need. */
- f->base.x_stmt_tree.x_cur_stmt_list = NULL_TREE;
+ f->base.x_stmt_tree.x_cur_stmt_list = NULL;
f->bindings = NULL;
f->x_local_names = NULL;
}
This caused &foo to be of type ptr-to-const-function
which then got a warning when stored in a ptr-to-function variable. */
- gcc_assert (building_stmt_tree ());
+ gcc_assert (building_stmt_list_p ());
/* The current function is being defined, so its DECL_INITIAL should
be set, and unless there's a multiple definition, it should be
error_mark_node. */
}
pushdecl (anon_union_decl);
- if (building_stmt_tree ()
+ if (building_stmt_list_p ()
&& at_function_scope_p ())
add_decl_expr (anon_union_decl);
else if (!processing_template_decl)
static bool
begin_init_stmts (tree *stmt_expr_p, tree *compound_stmt_p)
{
- bool is_global = !building_stmt_tree ();
+ bool is_global = !building_stmt_list_p ();
*stmt_expr_p = begin_stmt_expr ();
*compound_stmt_p = begin_compound_stmt (BCS_NO_SCOPE);
stmt_expr = finish_stmt_expr (stmt_expr, true);
- gcc_assert (!building_stmt_tree () == is_global);
+ gcc_assert (!building_stmt_list_p () == is_global);
return stmt_expr;
}
tree type = TREE_TYPE (exp);
gcc_assert (init != error_mark_node && type != error_mark_node);
- gcc_assert (building_stmt_tree ());
+ gcc_assert (building_stmt_list_p ());
/* Use a function returning the desired type to initialize EXP for us.
If the function is a constructor, and its first argument is
if (decl == NULL_TREE)
return;
- if (building_stmt_tree ()
+ if (building_stmt_list_p ()
&& at_function_scope_p ())
add_decl_expr (decl);
pushdecl (alias);
/* Emit debug info for namespace alias. */
- if (!building_stmt_tree ())
+ if (!building_stmt_list_p ())
(*debug_hooks->global_decl) (alias);
}
gcc_assert (TREE_CODE (name_space) == NAMESPACE_DECL);
- if (building_stmt_tree ())
+ if (building_stmt_list_p ())
add_stmt (build_stmt (input_location, USING_STMT, name_space));
name_space = ORIGINAL_NAMESPACE (name_space);
for (t = OVL_CURRENT (t); t; t = OVL_NEXT (t))
if (TREE_CODE (t) != TEMPLATE_DECL)
{
- if (building_stmt_tree ())
+ if (building_stmt_list_p ())
add_stmt (build_stmt (input_location, USING_STMT, t));
else
(*debug_hooks->imported_module_or_decl) (t, NULL_TREE, context, false);
/* Add T to the statement-tree. Non-side-effect statements need to be
recorded during statement expressions. */
+ gcc_checking_assert (!VEC_empty (tree, stmt_list_stack));
append_to_statement_list_force (t, &cur_stmt_list);
return t;
print_node (file, "stmt", tsi_stmt (i), indent + 4);
}
}
- print_node (file, "chain", TREE_CHAIN (node), indent + 4);
break;
case BLOCK:
/* This is a cache of STATEMENT_LIST nodes. We create and destroy them
fairly often during gimplification. */
-static GTY ((deletable (""))) tree stmt_list_cache;
+static GTY ((deletable (""))) VEC(tree,gc) *stmt_list_cache;
tree
alloc_stmt_list (void)
{
- tree list = stmt_list_cache;
- if (list)
+ tree list;
+ if (!VEC_empty (tree, stmt_list_cache))
{
- stmt_list_cache = TREE_CHAIN (list);
- gcc_assert (stmt_list_cache != list);
- memset (list, 0, sizeof(struct tree_common));
+ list = VEC_pop (tree, stmt_list_cache);
+ memset (list, 0, sizeof(struct tree_base));
TREE_SET_CODE (list, STATEMENT_LIST);
}
else
{
gcc_assert (!STATEMENT_LIST_HEAD (t));
gcc_assert (!STATEMENT_LIST_TAIL (t));
- /* If this triggers, it's a sign that the same list is being freed
- twice. */
- gcc_assert (t != stmt_list_cache || stmt_list_cache == NULL);
- TREE_CHAIN (t) = stmt_list_cache;
- stmt_list_cache = t;
+ VEC_safe_push (tree, gc, stmt_list_cache, t);
}
/* A subroutine of append_to_statement_list{,_force}. T is not NULL. */
case TS_CONSTRUCTOR:
case TS_EXP:
case TS_IDENTIFIER:
+ case TS_STATEMENT_LIST:
MARK_TS_TYPED (code);
break;
case TS_LIST:
case TS_VEC:
case TS_BINFO:
- case TS_STATEMENT_LIST:
case TS_OMP_CLAUSE:
case TS_OPTIMIZATION:
case TS_TARGET_OPTION:
struct GTY(()) tree_statement_list
{
- struct tree_common common;
+ struct tree_typed typed;
struct tree_statement_list_node *head;
struct tree_statement_list_node *tail;
};