aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/rtti.c
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2004-07-29 17:59:31 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2004-07-29 17:59:31 +0000
commit4684cd27fc05d4b4b14401c639fe4427a3bbbe3e (patch)
treebd18935ca8aaabc7e84771ece8e457e583cfbf6c /gcc/cp/rtti.c
parentb4042a039f664fe6e2cedc49cb74a65c159756fe (diff)
downloadgcc-4684cd27fc05d4b4b14401c639fe4427a3bbbe3e.zip
gcc-4684cd27fc05d4b4b14401c639fe4427a3bbbe3e.tar.gz
gcc-4684cd27fc05d4b4b14401c639fe4427a3bbbe3e.tar.bz2
c-common.h (lang_post_pch_load): New variable.
* c-common.h (lang_post_pch_load): New variable. * c-pch.c (lang_post_pch_load): Define it. (c_common_read_pch): Use it. * cgraphunit.c (record_call_1): Give the front end a chance to record additional needed entities when a variable is marked as needed. * tlink.c (recompile_files): Robustify. (scan_linker_output): If a symbol is assigned to a file, but after recompilation is not present there, issue an error message. * cp-tree.h (IDENTIFIER_REPO_CHOSEN): Define. (lang_decl_flags): Narrow the width of "languages". Add repo_available_p. (DECL_NEEDED_P): Remove. (FOR_EACH_CLONE): New macro. (DECL_REPO_AVAILABLE_P): Likewise. (DECL_TINFO_P): Likewise. (set_linkage_according_to_type): Declare. (import_export_vtable): Remove. (import_export_tinfo): Likewise. (mark_needed): New function. (decl_needed_p): Likewise. (note_vauge_linkage_fn): Likewise. (init_repo): Change prototype. (repo_template_used): Remove. (repo_template_instantiated): Likewise. (repo_emit_p): New function. (repo_export_class_p): Likewise. (no_linkage_check): Change prototype. * class.c (set_linkage_according_to_type): New function. (build_vtable): Use it. Do not call import_export_vtable. Set DECL_IGNORED_P if appropriate. * decl.c (duplicate_decls): Preserve DECL_REPO_AVAILABLE_P. (make_rtL_for_nonlocal_decls): Check for template instantiations explicitly. (grokfndecl): Adjust call to no_linkage_check. (set_linkage_for_static_data_member): New function. (grokvardecl): Use it. Adjust call to no_linkage_check. (grokdeclarator): Use set_linkage_for_static_data_member. * decl2.c (note_vague_linkage_fn): New function. (note_vague_linkage_var): Likewise. (finish_static_data_member_decl): Use it. (import_export_vtable): Remove. (import_export_class): Use repo_export_class_p. (var_finalized_p): Simplify. (maybe_emit_vtables): Simplify. (mark_needed): New function. (decl_needed_p): Likewise. (import_export_decl): Add documentation and consistency checks. Use repo_emit_p. Handle virtual tables and RTTI information here. (import_export_tinfo): Remove. (write_out_vars): Call import_export_decl. (cxx_callgraph_analyze_expr): Ensure that all vtables are emitted whenever one is. (finish_file): Use decl_needed_p. Do not call import_export_decl for undefined static data members. Do not warn about undefined inlines when using a repository. (mark_used): Use note_vague_linkage_fn. Always defer template instantiations. * lex.c (cxx_init): Adjust call to init_repo. Always set flag_unit_at_a-time. * method.c (synthesize_method): Remove unncessary import_export_decl call. (implicitly_declare_fn): Use set_linkage_according_to_type. * optimize.c (maybe_clone_body): Use FOR_EACH_CLONE. * pt.c (instantiate_class_template): Don't redundantly add classes to keyed_classes. Don't call repo_template_used. (tsubst_decl): Set DECL_INTERFACE_KNOWN for instantiations of templates with internal linkage. (check_instantiated_args): Adjust call to no_linkage_check. (instantiate_template): Use FOR_EACH_CLONE. (mark_definable): New function. (mark_decl_instantiated): Use it. (do_decl_instantiation): Adjust tests for explicit instantiation after "extern template". (instantiate_class_member): Do not use repo_template_instantiated. (do_type_instantiation): Simplify. (instantiate_decl): Use mark_definable. Check repo_emit_p. Simplify. * repo.c (repo_get_id): Remove. (original_repo): Remove. (IDENTIFIER_REPO_USED): Remove. (IDENTIFIER_REPO_CHOSEN): Remove. Remove all #if 0'd code. (repo_template_used): Remove. (repo_template_instantiated): Remove. (temporary_obstack_initialized_p): New variable. (init_repo): Register with lang_post_pch_load. Avoid creating identifiers unnecessarily. Don't use original_repo. Close the file here. (reopen_repo_file_for_write): Not here. (finish_repo): Always write out a new repository file. (repo_emit_p): New function. (repo_export_class_p): Likewise. * rtti.c (get_tinfo_decl): Use set_linkage_according_to_type. (involves_incomplete_p): New function. (tinfo_base_init): Use it. (ptr_initializer): Remove non_public_ptr parameter. (ptm_initializer): Likewise. (get_pseudo_ti_init): Likewise. (unemitted_tinfo_decl_p): Remove. (emit_tinfo_decl): Use import_export_decl. * semantics.c (expand_body): Move updates of static_ctors and static_dtors to ... (expand_or_defer_fn): ... here. * tree.c (no_linkage_check): Add relaxed_p parameter. * g++.dg/abi/inline1.C: New test. * g++.dg/abi/local1-a.cc: Likewise. * g++.dg/abi/local1.C: Likewise. * g++.dg/abi/mangle11.C: Tweak location of warnings. * g++.dg/abi/mangle12.C: Likewise. * g++.dg/abi/mangle17.C: Likewise. * g++.dg/abi/mangle20-2.C: Likewise. * g++.dg/opt/interface1.C: Likewise. * g++.dg/opt/interface1.h: Likewise. * g++.dg/opt/interface1-a.cc: New test. * g++.dg/parse/repo1.C: New test. * g++.dg/template/repo1.C: Likewise. * g++.dg/warn/Winline-1.C: Likewise. * lib/gcc-dg.exp (gcc-dg-test-1): Fix -frepo handling. From-SVN: r85309
Diffstat (limited to 'gcc/cp/rtti.c')
-rw-r--r--gcc/cp/rtti.c192
1 files changed, 103 insertions, 89 deletions
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index c6c9fc6..83e24c4 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -89,18 +89,15 @@ static int qualifier_flags (tree);
static bool target_incomplete_p (tree);
static tree tinfo_base_init (tree, tree);
static tree generic_initializer (tree, tree);
-static tree ptr_initializer (tree, tree, bool *);
-static tree ptm_initializer (tree, tree, bool *);
static tree dfs_class_hint_mark (tree, void *);
static tree dfs_class_hint_unmark (tree, void *);
static int class_hint_flags (tree);
static tree class_initializer (tree, tree, tree);
static tree create_pseudo_type_info (const char *, int, ...);
-static tree get_pseudo_ti_init (tree, tree, bool *);
+static tree get_pseudo_ti_init (tree, tree);
static tree get_pseudo_ti_desc (tree);
static void create_tinfo_types (void);
static bool typeinfo_in_lib_p (tree);
-static bool unemitted_tinfo_decl_p (tree);
static int doing_runtime = 0;
@@ -348,14 +345,16 @@ get_tinfo_decl (tree type)
tree var_desc = get_pseudo_ti_desc (type);
d = build_lang_decl (VAR_DECL, name, TINFO_PSEUDO_TYPE (var_desc));
-
+ SET_DECL_ASSEMBLER_NAME (d, name);
+ DECL_TINFO_P (d) = 1;
DECL_ARTIFICIAL (d) = 1;
TREE_READONLY (d) = 1;
TREE_STATIC (d) = 1;
+ /* Mark the variable as undefined -- but remember that we can
+ define it later if we need to do so. */
DECL_EXTERNAL (d) = 1;
- DECL_COMDAT (d) = 1;
- TREE_PUBLIC (d) = 1;
- SET_DECL_ASSEMBLER_NAME (d, name);
+ DECL_NOT_REALLY_EXTERN (d) = 1;
+ set_linkage_according_to_type (type, d);
pushdecl_top_level_and_finish (d, NULL_TREE);
@@ -732,6 +731,38 @@ target_incomplete_p (tree type)
return !COMPLETE_OR_VOID_TYPE_P (type);
}
+/* Returns true if TYPE involves an incomplete class type; in that
+ case, typeinfo variables for TYPE should be emitted with internal
+ linkage. */
+
+static bool
+involves_incomplete_p (tree type)
+{
+ switch (TREE_CODE (type))
+ {
+ case POINTER_TYPE:
+ return target_incomplete_p (TREE_TYPE (type));
+
+ case OFFSET_TYPE:
+ ptrmem:
+ return
+ (target_incomplete_p (TYPE_PTRMEM_POINTED_TO_TYPE (type))
+ || !COMPLETE_TYPE_P (TYPE_PTRMEM_CLASS_TYPE (type)));
+
+ case RECORD_TYPE:
+ if (TYPE_PTRMEMFUNC_P (type))
+ goto ptrmem;
+ /* Fall through. */
+ case UNION_TYPE:
+ if (!COMPLETE_TYPE_P (type))
+ return true;
+
+ default:
+ /* All other types do not involve incomplete class types. */
+ return false;
+ }
+}
+
/* Return a CONSTRUCTOR for the common part of the type_info objects. This
is the vtable pointer and NTBS name. The NTBS name is emitted as a
comdat const char array, so it becomes a unique key for the type. Generate
@@ -754,20 +785,32 @@ tinfo_base_init (tree desc, tree target)
NULL_TREE);
tree name_string = tinfo_name (target);
+ /* Determine the name of the variable -- and remember with which
+ type it is associated. */
name_name = mangle_typeinfo_string_for_type (target);
+ TREE_TYPE (name_name) = target;
+
name_decl = build_lang_decl (VAR_DECL, name_name, name_type);
DECL_ARTIFICIAL (name_decl) = 1;
TREE_READONLY (name_decl) = 1;
TREE_STATIC (name_decl) = 1;
DECL_EXTERNAL (name_decl) = 0;
- TREE_PUBLIC (name_decl) = 1;
+ DECL_TINFO_P (name_decl) = 1;
if (CLASS_TYPE_P (target))
{
DECL_VISIBILITY (name_decl) = CLASSTYPE_VISIBILITY (target);
- DECL_VISIBILITY_SPECIFIED (name_decl) = CLASSTYPE_VISIBILITY_SPECIFIED (target);
+ DECL_VISIBILITY_SPECIFIED (name_decl)
+ = CLASSTYPE_VISIBILITY_SPECIFIED (target);
}
- import_export_tinfo (name_decl, target, typeinfo_in_lib_p (target));
+ if (involves_incomplete_p (target))
+ {
+ TREE_PUBLIC (name_decl) = 0;
+ DECL_INTERFACE_KNOWN (name_decl) = 1;
+ }
+ else
+ set_linkage_according_to_type (target, name_decl);
+ import_export_decl (name_decl);
/* External name of the string containing the type's name has a
special name. */
SET_DECL_ASSEMBLER_NAME (name_decl,
@@ -843,7 +886,7 @@ generic_initializer (tree desc, tree target)
which adds target type and qualifier flags members to the type_info base. */
static tree
-ptr_initializer (tree desc, tree target, bool *non_public_ptr)
+ptr_initializer (tree desc, tree target)
{
tree init = tinfo_base_init (desc, target);
tree to = TREE_TYPE (target);
@@ -851,10 +894,7 @@ ptr_initializer (tree desc, tree target, bool *non_public_ptr)
bool incomplete = target_incomplete_p (to);
if (incomplete)
- {
- flags |= 8;
- *non_public_ptr = true;
- }
+ flags |= 8;
init = tree_cons (NULL_TREE, build_int_2 (flags, 0), init);
init = tree_cons (NULL_TREE,
get_tinfo_ptr (TYPE_MAIN_VARIANT (to)),
@@ -873,7 +913,7 @@ ptr_initializer (tree desc, tree target, bool *non_public_ptr)
base. */
static tree
-ptm_initializer (tree desc, tree target, bool *non_public_ptr)
+ptm_initializer (tree desc, tree target)
{
tree init = tinfo_base_init (desc, target);
tree to = TYPE_PTRMEM_POINTED_TO_TYPE (target);
@@ -882,15 +922,9 @@ ptm_initializer (tree desc, tree target, bool *non_public_ptr)
bool incomplete = target_incomplete_p (to);
if (incomplete)
- {
- flags |= 0x8;
- *non_public_ptr = true;
- }
+ flags |= 0x8;
if (!COMPLETE_TYPE_P (klass))
- {
- flags |= 0x10;
- *non_public_ptr = true;
- }
+ flags |= 0x10;
init = tree_cons (NULL_TREE, build_int_2 (flags, 0), init);
init = tree_cons (NULL_TREE,
get_tinfo_ptr (TYPE_MAIN_VARIANT (to)),
@@ -1003,22 +1037,18 @@ typeinfo_in_lib_p (tree type)
}
}
-/* Generate the initializer for the type info describing
- TYPE. VAR_DESC is a . NON_PUBLIC_P is set nonzero, if the VAR_DECL
- should not be exported from this object file. This should only be
- called at the end of translation, when we know that no further
- types will be completed. */
+/* Generate the initializer for the type info describing TYPE. */
static tree
-get_pseudo_ti_init (tree type, tree var_desc, bool *non_public_p)
+get_pseudo_ti_init (tree type, tree var_desc)
{
my_friendly_assert (at_eof, 20021120);
switch (TREE_CODE (type))
{
case OFFSET_TYPE:
- return ptm_initializer (var_desc, type, non_public_p);
+ return ptm_initializer (var_desc, type);
case POINTER_TYPE:
- return ptr_initializer (var_desc, type, non_public_p);
+ return ptr_initializer (var_desc, type);
case ENUMERAL_TYPE:
return generic_initializer (var_desc, type);
break;
@@ -1031,14 +1061,9 @@ get_pseudo_ti_init (tree type, tree var_desc, bool *non_public_p)
case UNION_TYPE:
case RECORD_TYPE:
if (TYPE_PTRMEMFUNC_P (type))
- return ptm_initializer (var_desc, type, non_public_p);
+ return ptm_initializer (var_desc, type);
else if (var_desc == class_desc_type_node)
- {
- if (!COMPLETE_TYPE_P (type))
- /* Emit a non-public class_type_info. */
- *non_public_p = true;
- return class_initializer (var_desc, type, NULL_TREE);
- }
+ return class_initializer (var_desc, type, NULL_TREE);
else if (var_desc == si_class_desc_type_node)
{
tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), 0);
@@ -1414,30 +1439,6 @@ emit_support_tinfos (void)
}
}
-/* Return true, iff T is a type_info variable which has not had a
- definition emitted for it. */
-
-static bool
-unemitted_tinfo_decl_p (tree t)
-{
- if (/* It's a var decl */
- TREE_CODE (t) == VAR_DECL
- /* which has a name */
- && DECL_NAME (t)
- /* whose name points back to itself */
- && IDENTIFIER_GLOBAL_VALUE (DECL_NAME (t)) == t
- /* whose name's type is non-null */
- && TREE_TYPE (DECL_NAME (t))
- /* and whose type is a struct */
- && TREE_CODE (TREE_TYPE (t)) == RECORD_TYPE
- /* with a field */
- && TYPE_FIELDS (TREE_TYPE (t))
- /* which is our pseudo type info */
- && TREE_TYPE (TYPE_FIELDS (TREE_TYPE (t))) == ti_desc_type_node)
- return true;
- return false;
-}
-
/* Finish a type info decl. DECL_PTR is a pointer to an unemitted
tinfo decl. Determine whether it needs emitting, and if so
generate the initializer. */
@@ -1446,35 +1447,48 @@ bool
emit_tinfo_decl (tree decl)
{
tree type = TREE_TYPE (DECL_NAME (decl));
- bool non_public;
int in_library = typeinfo_in_lib_p (type);
tree var_desc, var_init;
- my_friendly_assert (unemitted_tinfo_decl_p (decl), 20030307);
+ my_friendly_assert (DECL_TINFO_P (decl), 20030307);
- import_export_tinfo (decl, type, in_library);
- if (DECL_REALLY_EXTERN (decl) || !DECL_NEEDED_P (decl))
- return false;
+ if (in_library)
+ {
+ if (doing_runtime)
+ DECL_EXTERNAL (decl) = 0;
+ else
+ {
+ /* If we're not in the runtime, then DECL (which is already
+ DECL_EXTERNAL) will not be defined here. */
+ DECL_INTERFACE_KNOWN (decl) = 1;
+ return false;
+ }
+ }
+ else if (involves_incomplete_p (type))
+ {
+ if (!decl_needed_p (decl))
+ return false;
+ /* If TYPE involves an incomplete class type, then the typeinfo
+ object will be emitted with internal linkage. There is no
+ way to know whether or not types are incomplete until the end
+ of the compilation, so this determination must be deferred
+ until this point. */
+ TREE_PUBLIC (decl) = 0;
+ DECL_EXTERNAL (decl) = 0;
+ DECL_INTERFACE_KNOWN (decl) = 1;
+ }
- if (!doing_runtime && in_library)
+ import_export_decl (decl);
+ if (DECL_NOT_REALLY_EXTERN (decl) && decl_needed_p (decl))
+ {
+ DECL_EXTERNAL (decl) = 0;
+ var_desc = get_pseudo_ti_desc (type);
+ var_init = get_pseudo_ti_init (type, var_desc);
+ DECL_INITIAL (decl) = var_init;
+ mark_used (decl);
+ cp_finish_decl (decl, var_init, NULL_TREE, 0);
+ return true;
+ }
+ else
return false;
-
- non_public = false;
- var_desc = get_pseudo_ti_desc (type);
- var_init = get_pseudo_ti_init (type, var_desc, &non_public);
-
- DECL_EXTERNAL (decl) = 0;
- TREE_PUBLIC (decl) = !non_public;
- if (non_public)
- DECL_COMDAT (decl) = 0;
-
- DECL_INITIAL (decl) = var_init;
- mark_used (decl);
- cp_finish_decl (decl, var_init, NULL_TREE, 0);
- /* cp_finish_decl will have dealt with linkage. */
-
- /* Say we've dealt with it. */
- TREE_TYPE (DECL_NAME (decl)) = NULL_TREE;
-
- return true;
}