Commit 9ed9e79a by Mark Mitchell Committed by Mark Mitchell

decl.c (initialize_local_var): Handle static variables here.

	* decl.c (initialize_local_var): Handle static variables here.
	(cp_finish_decl): Tweak handling of function-scope static
	variables.
	* semantics.c (expand_stmt): Handle DECL_STMTs for static
	variables.

From-SVN: r29749
parent 3b62f224
1999-09-30 Mark Mitchell <mark@codesourcery.com> 1999-09-30 Mark Mitchell <mark@codesourcery.com>
* decl.c (initialize_local_var): Handle static variables here.
(cp_finish_decl): Tweak handling of function-scope static
variables.
* semantics.c (expand_stmt): Handle DECL_STMTs for static
variables.
* method.c (emit_thunk): Don't crash when -fsyntax-only. * method.c (emit_thunk): Don't crash when -fsyntax-only.
* cp-tree.h (lang_decl_flags): Add global_ctor_p and * cp-tree.h (lang_decl_flags): Add global_ctor_p and
......
...@@ -7470,9 +7470,11 @@ initialize_local_var (decl, init, flags) ...@@ -7470,9 +7470,11 @@ initialize_local_var (decl, init, flags)
tree init; tree init;
int flags; int flags;
{ {
tree type; tree type = TREE_TYPE (decl);
type = complete_type (TREE_TYPE (decl)); /* If the type is bogus, don't bother initializing the variable. */
if (type == error_mark_node)
return;
if (DECL_SIZE (decl) == NULL_TREE && !TREE_STATIC (decl)) if (DECL_SIZE (decl) == NULL_TREE && !TREE_STATIC (decl))
{ {
...@@ -7481,6 +7483,16 @@ initialize_local_var (decl, init, flags) ...@@ -7481,6 +7483,16 @@ initialize_local_var (decl, init, flags)
TREE_ADDRESSABLE (decl) = TREE_USED (decl); TREE_ADDRESSABLE (decl) = TREE_USED (decl);
} }
/* Local statics are handled differently from ordinary automatic
variables. */
if (TREE_STATIC (decl))
{
if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE
|| TYPE_NEEDS_DESTRUCTOR (type))
expand_static_init (decl, init);
return;
}
if (DECL_SIZE (decl) && type != error_mark_node) if (DECL_SIZE (decl) && type != error_mark_node)
{ {
int already_used; int already_used;
...@@ -7776,13 +7788,6 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) ...@@ -7776,13 +7788,6 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
if (init) if (init)
DECL_INITIAL (decl) = init; DECL_INITIAL (decl) = init;
} }
else if (TREE_STATIC (decl) && type != error_mark_node)
{
/* Cleanups for static variables are handled by `finish_file'. */
if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE
|| TYPE_NEEDS_DESTRUCTOR (type))
expand_static_init (decl, init);
}
else if (TREE_CODE (CP_DECL_CONTEXT (decl)) == FUNCTION_DECL) else if (TREE_CODE (CP_DECL_CONTEXT (decl)) == FUNCTION_DECL)
{ {
/* This is a local declaration. */ /* This is a local declaration. */
...@@ -7808,6 +7813,13 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) ...@@ -7808,6 +7813,13 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
destroy_local_var (decl); destroy_local_var (decl);
} }
} }
else if (TREE_STATIC (decl) && type != error_mark_node)
{
/* Cleanups for static variables are handled by `finish_file'. */
if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE
|| TYPE_NEEDS_DESTRUCTOR (type))
expand_static_init (decl, init);
}
finish_end0: finish_end0:
/* Undo call to `pushclass' that was done in `start_decl' /* Undo call to `pushclass' that was done in `start_decl'
......
...@@ -2274,11 +2274,9 @@ expand_stmt (t) ...@@ -2274,11 +2274,9 @@ expand_stmt (t)
/* If this is a declaration for an automatic local /* If this is a declaration for an automatic local
variable, initialize it. Note that we might also see a variable, initialize it. Note that we might also see a
declaration for a namespace-scope object (declared with declaration for a namespace-scope object (declared with
`extern') or an object with static storage duration `extern'). We don't have to handle the initialization
(declared with `static'). We don't have to handle the of those objects here; they can only be declarations,
initialization of those objects here; the former can rather than definitions. */
never be a definition (only a declaration), and the
latter is handled in finish_file. */
if (TREE_CODE (decl) == VAR_DECL if (TREE_CODE (decl) == VAR_DECL
&& !TREE_STATIC (decl) && !TREE_STATIC (decl)
&& !DECL_EXTERNAL (decl)) && !DECL_EXTERNAL (decl))
...@@ -2290,6 +2288,10 @@ expand_stmt (t) ...@@ -2290,6 +2288,10 @@ expand_stmt (t)
expand_anon_union_decl (decl, NULL_TREE, expand_anon_union_decl (decl, NULL_TREE,
DECL_ANON_UNION_ELEMS (decl)); DECL_ANON_UNION_ELEMS (decl));
} }
else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
rest_of_decl_compilation
(decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
/*top_level=*/0, /*at_end=*/0);
resume_momentary (i); resume_momentary (i);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment