Commit 5cc90635 by Jason Merrill Committed by Jason Merrill

toplev.c (wrapup_global_declarations): Clarify variable handling.

        * toplev.c (wrapup_global_declarations): Clarify variable handling.
        -fkeep-static-consts doesn't apply to comdats.

cp/
        * decl.c (make_rtl_for_nonlocal_decl): Also defer COMDAT
        variables.
        * decl2.c (maybe_make_one_only): Also mark the decl as needed.

From-SVN: r50802
parent 0f9b56dc
2002-03-15 Jason Merrill <jason@redhat.com>
* toplev.c (wrapup_global_declarations): Clarify variable handling.
-fkeep-static-consts doesn't apply to comdats.
2002-03-14 Richard Henderson <rth@redhat.com> 2002-03-14 Richard Henderson <rth@redhat.com>
* c-decl.c: Include c-pragma.h. * c-decl.c: Include c-pragma.h.
......
2002-03-15 Jason Merrill <jason@redhat.com>
* decl.c (make_rtl_for_nonlocal_decl): Also defer COMDAT
variables.
* decl2.c (maybe_make_one_only): Also mark the decl as needed.
2002-03-14 Richard Henderson <rth@redhat.com> 2002-03-14 Richard Henderson <rth@redhat.com>
* decl.c: Include c-pragma.h. * decl.c: Include c-pragma.h.
......
...@@ -7861,18 +7861,21 @@ make_rtl_for_nonlocal_decl (decl, init, asmspec) ...@@ -7861,18 +7861,21 @@ make_rtl_for_nonlocal_decl (decl, init, asmspec)
DECL_STMT is expanded. */ DECL_STMT is expanded. */
defer_p = DECL_FUNCTION_SCOPE_P (decl) || DECL_VIRTUAL_P (decl); defer_p = DECL_FUNCTION_SCOPE_P (decl) || DECL_VIRTUAL_P (decl);
/* We try to defer namespace-scope static constants so that they are /* We try to defer namespace-scope static constants and template
not emitted into the object file unnecessarily. */ instantiations so that they are not emitted into the object file
if (!DECL_VIRTUAL_P (decl) unnecessarily. */
&& TREE_READONLY (decl) if ((!DECL_VIRTUAL_P (decl)
&& DECL_INITIAL (decl) != NULL_TREE && TREE_READONLY (decl)
&& DECL_INITIAL (decl) != error_mark_node && DECL_INITIAL (decl) != NULL_TREE
&& ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)) && DECL_INITIAL (decl) != error_mark_node
&& toplev && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))
&& !TREE_PUBLIC (decl)) && toplev
{ && !TREE_PUBLIC (decl))
/* Fool with the linkage according to #pragma interface. */ || DECL_COMDAT (decl))
if (!interface_unknown) {
/* Fool with the linkage of static consts according to #pragma
interface. */
if (!interface_unknown && !TREE_PUBLIC (decl))
{ {
TREE_PUBLIC (decl) = 1; TREE_PUBLIC (decl) = 1;
DECL_EXTERNAL (decl) = interface_only; DECL_EXTERNAL (decl) = interface_only;
...@@ -8068,7 +8071,7 @@ cp_finish_decl (decl, init, asmspec_tree, flags) ...@@ -8068,7 +8071,7 @@ cp_finish_decl (decl, init, asmspec_tree, flags)
/* If a name was specified, get the string. */ /* If a name was specified, get the string. */
if (asmspec_tree) if (asmspec_tree)
asmspec = TREE_STRING_POINTER (asmspec_tree); asmspec = TREE_STRING_POINTER (asmspec_tree);
if (init && TREE_CODE (init) == NAMESPACE_DECL) if (init && TREE_CODE (init) == NAMESPACE_DECL)
{ {
......
...@@ -2210,8 +2210,12 @@ maybe_make_one_only (decl) ...@@ -2210,8 +2210,12 @@ maybe_make_one_only (decl)
make_decl_one_only (decl); make_decl_one_only (decl);
if (TREE_CODE (decl) == VAR_DECL && DECL_LANG_SPECIFIC (decl)) if (TREE_CODE (decl) == VAR_DECL)
DECL_COMDAT (decl) = 1; {
DECL_COMDAT (decl) = 1;
/* Mark it needed so we don't forget to emit it. */
TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) = 1;
}
} }
/* Returns the virtual function with which the vtable for TYPE is /* Returns the virtual function with which the vtable for TYPE is
......
// Test that we don't emit unneeded copies of static data member template
// instantiations.
// Disable debug info so we don't get confused by the symbol name there.
// { dg-options "-g0" }
// { dg-final { scan-assembler-not "_ZN1AIiE1tE" } }
template <class T> struct A {
static const T t = 0;
};
template <class T> const T A<T>::t;
int i;
int main ()
{
i = A<int>::t; // Should just use the value
}
...@@ -1935,16 +1935,24 @@ wrapup_global_declarations (vec, len) ...@@ -1935,16 +1935,24 @@ wrapup_global_declarations (vec, len)
to force a constant to be written if and only if it is to force a constant to be written if and only if it is
defined in a main file, as opposed to an include file. */ defined in a main file, as opposed to an include file. */
if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl) if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
&& (((! TREE_READONLY (decl) || TREE_PUBLIC (decl))
&& !DECL_COMDAT (decl))
|| (!optimize
&& flag_keep_static_consts
&& !DECL_ARTIFICIAL (decl))
|| TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
{ {
reconsider = 1; bool needed = 1;
rest_of_decl_compilation (decl, NULL, 1, 1);
if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
/* needed */;
else if (DECL_COMDAT (decl))
needed = 0;
else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
&& (optimize || !flag_keep_static_consts
|| DECL_ARTIFICIAL (decl)))
needed = 0;
if (needed)
{
reconsider = 1;
rest_of_decl_compilation (decl, NULL, 1, 1);
}
} }
if (TREE_CODE (decl) == FUNCTION_DECL if (TREE_CODE (decl) == FUNCTION_DECL
......
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