Commit ea735e02 by Jason Merrill Committed by Jason Merrill

decl2.c (finish_file): Set at_eof to 2 after expanding ctors.

	* decl2.c (finish_file): Set at_eof to 2 after expanding ctors.
	* decl.c (expand_static_init): Make sure we don't add any after
	then.
	* decl.c (cp_finish_decl): Move intelligence about handling
	DECL_COMDAT for variables from here...
	* decl2.c (comdat_linkage): ...to here.
	(maybe_make_one_only): Tweak.
	(import_export_decl): Call comdat_linkage for variables, too.
	(finish_file): Handle template statics properly.

From-SVN: r25920
parent fb835c4d
1999-03-23 Jason Merrill <jason@yorick.cygnus.com>
* decl2.c (finish_file): Set at_eof to 2 after expanding ctors.
* decl.c (expand_static_init): Make sure we don't add any after
then.
* decl.c (cp_finish_decl): Move intelligence about handling
DECL_COMDAT for variables from here...
* decl2.c (comdat_linkage): ...to here.
(maybe_make_one_only): Tweak.
(import_export_decl): Call comdat_linkage for variables, too.
(finish_file): Handle template statics properly.
1999-03-22 Mark Mitchell <mark@codesourcery.com> 1999-03-22 Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (TYPE_PTRMEMFUNC_P): Use TYPE_PTRMEMFUNC_FLAG. * cp-tree.h (TYPE_PTRMEMFUNC_P): Use TYPE_PTRMEMFUNC_FLAG.
......
...@@ -7774,31 +7774,9 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) ...@@ -7774,31 +7774,9 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
else if (TREE_CODE (decl) == VAR_DECL else if (TREE_CODE (decl) == VAR_DECL
&& DECL_LANG_SPECIFIC (decl) && DECL_LANG_SPECIFIC (decl)
&& DECL_COMDAT (decl)) && DECL_COMDAT (decl))
{ /* Set it up again; we might have set DECL_INITIAL since the
/* Dynamically initialized vars go into common. */ last time. */
if (DECL_INITIAL (decl) == NULL_TREE comdat_linkage (decl);
|| DECL_INITIAL (decl) == error_mark_node)
DECL_COMMON (decl) = 1;
else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
{
DECL_COMMON (decl) = 1;
DECL_INITIAL (decl) = error_mark_node;
}
else
{
/* Statically initialized vars are weak or comdat, if
supported. */
if (flag_weak)
make_decl_one_only (decl);
else
{
/* We can't do anything useful; leave vars for explicit
instantiation. */
DECL_EXTERNAL (decl) = 1;
DECL_NOT_REALLY_EXTERN (decl) = 0;
}
}
}
if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
make_decl_rtl (decl, NULL_PTR, toplev); make_decl_rtl (decl, NULL_PTR, toplev);
...@@ -8094,6 +8072,9 @@ expand_static_init (decl, init) ...@@ -8094,6 +8072,9 @@ expand_static_init (decl, init)
{ {
tree oldstatic = value_member (decl, static_aggregates); tree oldstatic = value_member (decl, static_aggregates);
/* If at_eof is 2, we're too late. */
my_friendly_assert (at_eof <= 1, 990323);
if (oldstatic) if (oldstatic)
{ {
if (TREE_PURPOSE (oldstatic) && init != NULL_TREE) if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
......
...@@ -2370,8 +2370,26 @@ comdat_linkage (decl) ...@@ -2370,8 +2370,26 @@ comdat_linkage (decl)
{ {
if (flag_weak) if (flag_weak)
make_decl_one_only (decl); make_decl_one_only (decl);
else else if (TREE_CODE (decl) == FUNCTION_DECL)
TREE_PUBLIC (decl) = 0; TREE_PUBLIC (decl) = 0;
else
{
if (DECL_INITIAL (decl) == 0
|| DECL_INITIAL (decl) == error_mark_node)
DECL_COMMON (decl) = 1;
else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
{
DECL_COMMON (decl) = 1;
DECL_INITIAL (decl) = error_mark_node;
}
else
{
/* We can't do anything useful; leave vars for explicit
instantiation. */
DECL_EXTERNAL (decl) = 1;
DECL_NOT_REALLY_EXTERN (decl) = 0;
}
}
if (DECL_LANG_SPECIFIC (decl)) if (DECL_LANG_SPECIFIC (decl))
DECL_COMDAT (decl) = 1; DECL_COMDAT (decl) = 1;
...@@ -2391,14 +2409,14 @@ maybe_make_one_only (decl) ...@@ -2391,14 +2409,14 @@ maybe_make_one_only (decl)
return; return;
/* We can't set DECL_COMDAT on functions, or finish_file will think /* We can't set DECL_COMDAT on functions, or finish_file will think
we can get away with not emitting them if they aren't used. we can get away with not emitting them if they aren't used. We need
We can't use make_decl_one_only for variables, because their to for variables so that cp_finish_decl will update their linkage,
DECL_INITIAL may not have been set properly yet. */ because their DECL_INITIAL may not have been set properly yet. */
if (TREE_CODE (decl) == FUNCTION_DECL) make_decl_one_only (decl);
make_decl_one_only (decl);
else if (TREE_CODE (decl) == VAR_DECL && DECL_LANG_SPECIFIC (decl))
comdat_linkage (decl); DECL_COMDAT (decl) = 1;
} }
/* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL, /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
...@@ -2730,10 +2748,8 @@ import_export_decl (decl) ...@@ -2730,10 +2748,8 @@ import_export_decl (decl)
/* Templates are allowed to have internal linkage. See /* Templates are allowed to have internal linkage. See
[basic.link]. */ [basic.link]. */
; ;
else if (TREE_CODE (decl) == FUNCTION_DECL)
comdat_linkage (decl);
else else
DECL_COMDAT (decl) = 1; comdat_linkage (decl);
} }
else else
DECL_NOT_REALLY_EXTERN (decl) = 0; DECL_NOT_REALLY_EXTERN (decl) = 0;
...@@ -3344,12 +3360,18 @@ finish_file () ...@@ -3344,12 +3360,18 @@ finish_file ()
/* Done with C language context needs. */ /* Done with C language context needs. */
pop_lang_context (); pop_lang_context ();
/* Let expand_static_init know it's too late for more ctors. */
at_eof = 2;
/* Now write out any static class variables (which may have since /* Now write out any static class variables (which may have since
learned how to be initialized). */ learned how to be initialized). */
while (pending_statics) for (; pending_statics; pending_statics = TREE_CHAIN (pending_statics))
{ {
tree decl = TREE_VALUE (pending_statics); tree decl = TREE_VALUE (pending_statics);
if (TREE_ASM_WRITTEN (decl))
continue;
/* Output DWARF debug information. */ /* Output DWARF debug information. */
#ifdef DWARF_DEBUGGING_INFO #ifdef DWARF_DEBUGGING_INFO
if (write_symbols == DWARF_DEBUG) if (write_symbols == DWARF_DEBUG)
...@@ -3360,11 +3382,15 @@ finish_file () ...@@ -3360,11 +3382,15 @@ finish_file ()
dwarf2out_decl (decl); dwarf2out_decl (decl);
#endif #endif
DECL_DEFER_OUTPUT (decl) = 0; /* We currently handle template statics here. We ought to handle
them the same way we do template functions, i.e. only emit them if
the symbol is needed. */
import_export_decl (decl);
if (DECL_NOT_REALLY_EXTERN (decl) && ! DECL_IN_AGGR_P (decl))
DECL_EXTERNAL (decl) = 0;
rest_of_decl_compilation rest_of_decl_compilation
(decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1); (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
pending_statics = TREE_CHAIN (pending_statics);
} }
this_time = get_run_time (); this_time = get_run_time ();
...@@ -3426,7 +3452,8 @@ finish_file () ...@@ -3426,7 +3452,8 @@ finish_file ()
continue; continue;
if (TREE_ASM_WRITTEN (decl) if (TREE_ASM_WRITTEN (decl)
|| (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl))) || (DECL_SAVED_INSNS (decl) == 0
&& ! DECL_ARTIFICIAL (decl)))
*p = TREE_CHAIN (*p); *p = TREE_CHAIN (*p);
else if (DECL_INITIAL (decl) == 0) else if (DECL_INITIAL (decl) == 0)
p = &TREE_CHAIN (*p); p = &TREE_CHAIN (*p);
...@@ -3475,7 +3502,8 @@ finish_file () ...@@ -3475,7 +3502,8 @@ finish_file ()
} }
/* Now delete from the chain of variables all virtual function tables. /* Now delete from the chain of variables all virtual function tables.
We output them all ourselves, because each will be treated specially. */ We output them all ourselves, because each will be treated
specially. */
walk_vtables ((void (*) PROTO((tree, tree))) 0, walk_vtables ((void (*) PROTO((tree, tree))) 0,
prune_vtable_vardecl); prune_vtable_vardecl);
......
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