+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>
* cp-tree.h (TYPE_PTRMEMFUNC_P): Use TYPE_PTRMEMFUNC_FLAG.
else if (TREE_CODE (decl) == VAR_DECL
&& DECL_LANG_SPECIFIC (decl)
&& DECL_COMDAT (decl))
- {
- /* Dynamically initialized vars go into common. */
- if (DECL_INITIAL (decl) == NULL_TREE
- || 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;
- }
- }
- }
+ /* Set it up again; we might have set DECL_INITIAL since the
+ last time. */
+ comdat_linkage (decl);
if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
make_decl_rtl (decl, NULL_PTR, toplev);
{
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 (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
{
if (flag_weak)
make_decl_one_only (decl);
- else
+ else if (TREE_CODE (decl) == FUNCTION_DECL)
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))
DECL_COMDAT (decl) = 1;
return;
/* 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't use make_decl_one_only for variables, because their
- DECL_INITIAL may not have been set properly yet. */
+ we can get away with not emitting them if they aren't used. We need
+ to for variables so that cp_finish_decl will update their linkage,
+ because their DECL_INITIAL may not have been set properly yet. */
- if (TREE_CODE (decl) == FUNCTION_DECL)
- make_decl_one_only (decl);
- else
- comdat_linkage (decl);
+ make_decl_one_only (decl);
+
+ if (TREE_CODE (decl) == VAR_DECL && DECL_LANG_SPECIFIC (decl))
+ DECL_COMDAT (decl) = 1;
}
/* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
/* Templates are allowed to have internal linkage. See
[basic.link]. */
;
- else if (TREE_CODE (decl) == FUNCTION_DECL)
- comdat_linkage (decl);
else
- DECL_COMDAT (decl) = 1;
+ comdat_linkage (decl);
}
else
DECL_NOT_REALLY_EXTERN (decl) = 0;
/* Done with C language context needs. */
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
learned how to be initialized). */
- while (pending_statics)
+ for (; pending_statics; pending_statics = TREE_CHAIN (pending_statics))
{
tree decl = TREE_VALUE (pending_statics);
+ if (TREE_ASM_WRITTEN (decl))
+ continue;
+
/* Output DWARF debug information. */
#ifdef DWARF_DEBUGGING_INFO
if (write_symbols == DWARF_DEBUG)
dwarf2out_decl (decl);
#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
(decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
-
- pending_statics = TREE_CHAIN (pending_statics);
}
this_time = get_run_time ();
continue;
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);
else if (DECL_INITIAL (decl) == 0)
p = &TREE_CHAIN (*p);
}
/* 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,
prune_vtable_vardecl);