aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r--gcc/cp/class.c2163
1 files changed, 1310 insertions, 853 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 376260b0d6a..3113dcb4322 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -66,12 +66,15 @@ typedef struct vtbl_init_data_s
{
/* The base for which we're building initializers. */
tree binfo;
- /* The binfo for the most-derived type. */
+ /* The type of the most-derived type. */
tree derived;
+ /* The binfo for the dynamic type. This will be TYPE_BINFO (derived),
+ unless ctor_vtbl_p is true. */
+ tree rtti_binfo;
/* The negative-index vtable initializers built up so far. These
are in order from least negative index to most negative index. */
tree inits;
- /* The last (i.e., most negative entry in INITS. */
+ /* The last (i.e., most negative) entry in INITS. */
tree* last_init;
/* The binfo for the virtual base for which we're building
vcall offset initializers. */
@@ -104,9 +107,8 @@ varray_type local_classes;
static tree get_vfield_name PARAMS ((tree));
static void finish_struct_anon PARAMS ((tree));
static tree build_vbase_pointer PARAMS ((tree, tree));
-static tree build_vtable_entry PARAMS ((tree, tree, tree, int));
+static tree build_vtable_entry PARAMS ((tree, tree, tree));
static tree get_vtable_name PARAMS ((tree));
-static tree get_derived_offset PARAMS ((tree, tree));
static tree get_basefndecls PARAMS ((tree, tree));
static int build_primary_vtable PARAMS ((tree, tree));
static int build_secondary_vtable PARAMS ((tree, tree));
@@ -119,9 +121,7 @@ static void delete_duplicate_fields PARAMS ((tree));
static void finish_struct_bits PARAMS ((tree));
static int alter_access PARAMS ((tree, tree, tree));
static void handle_using_decl PARAMS ((tree, tree));
-static int same_signature_p PARAMS ((tree, tree));
static int strictly_overrides PARAMS ((tree, tree));
-static void mark_overriders PARAMS ((tree, tree));
static void check_for_override PARAMS ((tree, tree));
static tree dfs_modify_vtables PARAMS ((tree, void *));
static tree modify_all_vtables PARAMS ((tree, int *, tree));
@@ -131,7 +131,7 @@ static void maybe_warn_about_overly_private_class PARAMS ((tree));
static int field_decl_cmp PARAMS ((const tree *, const tree *));
static int method_name_cmp PARAMS ((const tree *, const tree *));
static tree add_implicitly_declared_members PARAMS ((tree, int, int, int));
-static tree fixed_type_or_null PARAMS ((tree, int *));
+static tree fixed_type_or_null PARAMS ((tree, int *, int *));
static tree resolve_address_of_overloaded_function PARAMS ((tree, tree, int,
int, int, tree));
static void build_vtable_entry_ref PARAMS ((tree, tree, tree));
@@ -142,10 +142,10 @@ static void check_bitfield_decl PARAMS ((tree));
static void check_field_decl PARAMS ((tree, tree, int *, int *, int *, int *));
static void check_field_decls PARAMS ((tree, tree *, int *, int *, int *,
int *));
-static void build_base_field PARAMS ((record_layout_info, tree, int *,
- unsigned int *, splay_tree));
-static void build_base_fields PARAMS ((record_layout_info, int *,
- splay_tree));
+static bool build_base_field PARAMS ((record_layout_info, tree, int *,
+ splay_tree, tree));
+static bool build_base_fields PARAMS ((record_layout_info, int *,
+ splay_tree, tree));
static tree build_vbase_pointer_fields PARAMS ((record_layout_info, int *));
static tree build_vtbl_or_vbase_field PARAMS ((tree, tree, tree, tree, tree,
int *));
@@ -158,7 +158,7 @@ static void layout_class_type PARAMS ((tree, int *, int *, tree *, tree *));
static void fixup_pending_inline PARAMS ((tree));
static void fixup_inline_methods PARAMS ((tree));
static void set_primary_base PARAMS ((tree, tree, int *));
-static void propagate_binfo_offsets PARAMS ((tree, tree));
+static void propagate_binfo_offsets PARAMS ((tree, tree, tree));
static void layout_virtual_bases PARAMS ((tree, splay_tree));
static tree dfs_set_offset_for_unshared_vbases PARAMS ((tree, void *));
static void build_vbase_offset_vtbl_entries PARAMS ((tree, vtbl_init_data *));
@@ -169,48 +169,54 @@ static void layout_vtable_decl PARAMS ((tree, int));
static tree dfs_find_final_overrider PARAMS ((tree, void *));
static tree find_final_overrider PARAMS ((tree, tree, tree));
static int make_new_vtable PARAMS ((tree, tree));
-static void dump_class_hierarchy_r PARAMS ((FILE *, tree, tree, int));
-extern void dump_class_hierarchy PARAMS ((const char *, tree));
+static int maybe_indent_hierarchy PARAMS ((FILE *, int, int));
+static void dump_class_hierarchy_r PARAMS ((FILE *, int, tree, tree, int));
+static void dump_class_hierarchy PARAMS ((tree));
+static void dump_array PARAMS ((FILE *, tree));
+static void dump_vtable PARAMS ((tree, tree, tree));
+static void dump_vtt PARAMS ((tree, tree));
static tree build_vtable PARAMS ((tree, tree, tree));
static void initialize_vtable PARAMS ((tree, tree));
static void initialize_array PARAMS ((tree, tree));
static void layout_nonempty_base_or_field PARAMS ((record_layout_info,
tree, tree,
- splay_tree));
+ splay_tree, tree));
static unsigned HOST_WIDE_INT end_of_class PARAMS ((tree, int));
-static void layout_empty_base PARAMS ((tree, tree, splay_tree));
+static bool layout_empty_base PARAMS ((tree, tree, splay_tree, tree));
static void accumulate_vtbl_inits PARAMS ((tree, tree, tree, tree, tree));
static tree dfs_accumulate_vtbl_inits PARAMS ((tree, tree, tree, tree,
tree));
-static void set_vindex PARAMS ((tree, tree, int *));
-static void build_rtti_vtbl_entries PARAMS ((tree, tree, vtbl_init_data *));
+static void set_vindex PARAMS ((tree, int *));
+static void build_rtti_vtbl_entries PARAMS ((tree, vtbl_init_data *));
static void build_vcall_and_vbase_vtbl_entries PARAMS ((tree,
vtbl_init_data *));
static void force_canonical_binfo_r PARAMS ((tree, tree, tree, tree));
static void force_canonical_binfo PARAMS ((tree, tree, tree, tree));
+static tree dfs_unshared_virtual_bases PARAMS ((tree, void *));
static void mark_primary_bases PARAMS ((tree));
-static tree mark_primary_virtual_base PARAMS ((tree, tree, tree));
+static tree mark_primary_virtual_base PARAMS ((tree, tree));
static void clone_constructors_and_destructors PARAMS ((tree));
static tree build_clone PARAMS ((tree, tree));
static void update_vtable_entry_for_fn PARAMS ((tree, tree, tree, tree *));
static tree copy_virtuals PARAMS ((tree));
static void build_ctor_vtbl_group PARAMS ((tree, tree));
static void build_vtt PARAMS ((tree));
+static tree binfo_ctor_vtable PARAMS ((tree));
static tree *build_vtt_inits PARAMS ((tree, tree, tree *, tree *));
static tree dfs_build_secondary_vptr_vtt_inits PARAMS ((tree, void *));
static tree dfs_ctor_vtable_bases_queue_p PARAMS ((tree, void *data));
static tree dfs_fixup_binfo_vtbls PARAMS ((tree, void *));
-static tree get_matching_base PARAMS ((tree, tree));
+static tree get_original_base PARAMS ((tree, tree));
static tree dfs_get_primary_binfo PARAMS ((tree, void*));
static int record_subobject_offset PARAMS ((tree, tree, splay_tree));
static int check_subobject_offset PARAMS ((tree, tree, splay_tree));
static int walk_subobject_offsets PARAMS ((tree, subobject_offset_fn,
- tree, splay_tree, int));
+ tree, splay_tree, tree, int));
static void record_subobject_offsets PARAMS ((tree, tree, splay_tree, int));
static int layout_conflict_p PARAMS ((tree, tree, splay_tree, int));
static int splay_tree_compare_integer_csts PARAMS ((splay_tree_key k1,
splay_tree_key k2));
-
+static void warn_about_ambiguous_direct_bases PARAMS ((tree));
/* Macros for dfs walking during vtt construction. See
dfs_ctor_vtable_bases_queue_p, dfs_build_secondary_vptr_vtt_inits
@@ -381,6 +387,9 @@ build_vbase_path (code, type, expr, path, nonnull)
convert back to the type we want. Until that is done, we only optimize
if the complete type is the same type as expr has. */
fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
+ if (fixed_type_p < 0)
+ /* Virtual base layout is not fixed, even in ctors and dtors. */
+ fixed_type_p = 0;
if (!fixed_type_p && TREE_SIDE_EFFECTS (expr))
expr = save_expr (expr);
@@ -538,9 +547,9 @@ build_vtable_entry_ref (basetype, vtbl, idx)
}
/* Given an object INSTANCE, return an expression which yields the
- virtual function vtable element corresponding to INDEX. There are
- many special cases for INSTANCE which we take care of here, mainly
- to avoid creating extra tree nodes when we don't have to. */
+ vtable element corresponding to INDEX. There are many special
+ cases for INSTANCE which we take care of here, mainly to avoid
+ creating extra tree nodes when we don't have to. */
tree
build_vtbl_ref (instance, idx)
@@ -637,7 +646,15 @@ build_vfn_ref (ptr_to_instptr, instance, idx)
/* When using thunks, there is no extra delta, and we get the pfn
directly. */
if (flag_vtable_thunks)
- return aref;
+ {
+ /* When using function descriptors, the address of the
+ vtable entry is treated as a function pointer. */
+ if (TARGET_VTABLE_USES_DESCRIPTORS)
+ return build1 (NOP_EXPR, TREE_TYPE (aref),
+ build_unary_op (ADDR_EXPR, aref, /*noconvert=*/1));
+
+ return aref;
+ }
if (ptr_to_instptr)
{
@@ -663,11 +680,7 @@ static tree
get_vtable_name (type)
tree type;
{
- if (flag_new_abi)
- return mangle_vtbl_for_type (type);
- else
- return build_overload_with_type (get_identifier (VTABLE_NAME_PREFIX),
- type);
+ return mangle_vtbl_for_type (type);
}
/* Return an IDENTIFIER_NODE for the name of the virtual table table
@@ -677,42 +690,7 @@ tree
get_vtt_name (type)
tree type;
{
- if (flag_new_abi)
- return mangle_vtt_for_type (type);
- else
- return build_overload_with_type (get_identifier (VTT_NAME_PREFIX),
- type);
-}
-
-/* Return the offset to the main vtable for a given base BINFO. */
-
-tree
-get_vfield_offset (binfo)
- tree binfo;
-{
- return
- size_binop (PLUS_EXPR, byte_position (TYPE_VFIELD (BINFO_TYPE (binfo))),
- BINFO_OFFSET (binfo));
-}
-
-/* Get the offset to the start of the original binfo that we derived
- this binfo from. If we find TYPE first, return the offset only
- that far. The shortened search is useful because the this pointer
- on method calling is expected to point to a DECL_CONTEXT (fndecl)
- object, and not a baseclass of it. */
-
-static tree
-get_derived_offset (binfo, type)
- tree binfo, type;
-{
- tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
- tree offset2;
-
- while (!same_type_p (BINFO_TYPE (binfo), type))
- binfo = get_primary_binfo (binfo);
-
- offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
- return size_binop (MINUS_EXPR, offset1, offset2);
+ return mangle_vtt_for_type (type);
}
/* Create a VAR_DECL for a primary or secondary vtable for CLASS_TYPE.
@@ -728,13 +706,13 @@ build_vtable (class_type, name, vtable_type)
tree decl;
decl = build_lang_decl (VAR_DECL, name, vtable_type);
+ /* vtable names are already mangled; give them their DECL_ASSEMBLER_NAME
+ now to avoid confusion in mangle_decl. */
+ SET_DECL_ASSEMBLER_NAME (decl, name);
DECL_CONTEXT (decl) = class_type;
DECL_ARTIFICIAL (decl) = 1;
TREE_STATIC (decl) = 1;
-#ifndef WRITABLE_VTABLES
- /* Make them READONLY by default. (mrs) */
TREE_READONLY (decl) = 1;
-#endif
DECL_VIRTUAL_P (decl) = 1;
import_export_vtable (decl, class_type, 0);
@@ -796,12 +774,11 @@ copy_virtuals (binfo)
{
BV_VCALL_INDEX (t) = NULL_TREE;
BV_USE_VCALL_INDEX_P (t) = 0;
- BV_GENERATE_THUNK_WITH_VTABLE_P (t) = 0;
}
return copies;
}
-
+
/* Build the primary virtual function table for TYPE. If BINFO is
non-NULL, build the vtable starting with the initial approximation
that it is the same as the one which is the head of the association
@@ -899,20 +876,8 @@ build_secondary_vtable (binfo, for_type)
/* Make fresh virtual list, so we can smash it later. */
BINFO_VIRTUALS (binfo) = copy_virtuals (binfo);
- if (TREE_VIA_VIRTUAL (binfo))
- {
- tree binfo1 = binfo_for_vbase (BINFO_TYPE (binfo), for_type);
-
- /* XXX - This should never happen, if it does, the caller should
- ensure that the binfo is from for_type's binfos, not from any
- base type's. We can remove all this code after a while. */
- if (binfo1 != binfo)
- warning ("internal inconsistency: binfo offset error for rtti");
-
- offset = BINFO_OFFSET (binfo1);
- }
- else
- offset = BINFO_OFFSET (binfo);
+ my_friendly_assert (binfo == CANONICAL_BINFO (binfo, for_type), 20010605);
+ offset = BINFO_OFFSET (binfo);
/* In the new ABI, secondary vtables are laid out as part of the
same structure as the primary vtable. */
@@ -1024,9 +989,11 @@ make_new_vtable (t, binfo)
{
if (binfo == TYPE_BINFO (t))
/* In this case, it is *type*'s vtable we are modifying. We start
- with the approximation that it's vtable is that of the
+ with the approximation that its vtable is that of the
immediate base class. */
- return build_primary_vtable (TYPE_BINFO (DECL_CONTEXT (TYPE_VFIELD (t))),
+ /* ??? This actually passes TYPE_BINFO (t), not the primary base binfo,
+ since we've updated DECL_CONTEXT (TYPE_VFIELD (t)) by now. */
+ return build_primary_vtable (TYPE_BINFO (DECL_CONTEXT (TYPE_VFIELD (t))),
t);
else
/* This is our very own copy of `basetype' to play with. Later,
@@ -1077,7 +1044,12 @@ modify_vtable_entry (t, binfo, fndecl, delta, virtuals)
BV_FN (v) = fndecl;
/* Now assign virtual dispatch information, if unset. We can
- dispatch this, through any overridden base function. */
+ dispatch this through any overridden base function.
+
+ FIXME this can choose a secondary vtable if the primary is not
+ also lexically first, leading to useless conversions.
+ In the V3 ABI, there's no reason for DECL_VIRTUAL_CONTEXT to
+ ever be different from DECL_CONTEXT. */
if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
{
DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl);
@@ -1086,35 +1058,19 @@ modify_vtable_entry (t, binfo, fndecl, delta, virtuals)
}
}
-/* Return the index (in the virtual function table) of the first
- virtual function. */
-
-int
-first_vfun_index (t)
- tree t;
-{
- /* Under the old ABI, the offset-to-top and RTTI entries are at
- indices zero and one; under the new ABI, the first virtual
- function is at index zero. */
- if (!CLASSTYPE_COM_INTERFACE (t) && !flag_new_abi)
- return flag_vtable_thunks ? 2 : 1;
-
- return 0;
-}
-
/* Set DECL_VINDEX for DECL. VINDEX_P is the number of virtual
functions present in the vtable so far. */
static void
-set_vindex (t, decl, vfuns_p)
- tree t;
+set_vindex (decl, vfuns_p)
tree decl;
int *vfuns_p;
{
int vindex;
- vindex = (*vfuns_p)++;
- vindex += first_vfun_index (t);
+ vindex = *vfuns_p;
+ *vfuns_p += (TARGET_VTABLE_USES_DESCRIPTORS
+ ? TARGET_VTABLE_USES_DESCRIPTORS : 1);
DECL_VINDEX (decl) = build_shared_int_cst (vindex);
}
@@ -1158,7 +1114,7 @@ add_virtual_function (new_virtuals_p, overridden_virtuals_p,
CLASSTYPE_RTTI (t) = t;
/* Now assign virtual dispatch information. */
- set_vindex (t, fndecl, vfuns_p);
+ set_vindex (fndecl, vfuns_p);
DECL_VIRTUAL_CONTEXT (fndecl) = t;
/* Save the state we've computed on the NEW_VIRTUALS list. */
@@ -1308,22 +1264,38 @@ add_method (type, method, error_p)
/* [over.load] Member function declarations with the
same name and the same parameter types cannot be
overloaded if any of them is a static member
- function declaration. */
+ function declaration.
+
+ [namespace.udecl] When a using-declaration brings names
+ from a base class into a derived class scope, member
+ functions in the derived class override and/or hide member
+ functions with the same name and parameter types in a base
+ class (rather than conflicting). */
if ((DECL_STATIC_FUNCTION_P (fn)
!= DECL_STATIC_FUNCTION_P (method))
|| using)
{
tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn));
tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (method));
-
+ int same = 1;
+
+ /* Compare the quals on the 'this' parm. Don't compare
+ the whole types, as used functions are treated as
+ coming from the using class in overload resolution. */
+ if (using
+ && ! DECL_STATIC_FUNCTION_P (fn)
+ && ! DECL_STATIC_FUNCTION_P (method)
+ && (TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms1)))
+ != TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms2)))))
+ same = 0;
if (! DECL_STATIC_FUNCTION_P (fn))
parms1 = TREE_CHAIN (parms1);
if (! DECL_STATIC_FUNCTION_P (method))
parms2 = TREE_CHAIN (parms2);
- if (compparms (parms1, parms2))
+ if (same && compparms (parms1, parms2))
{
- if (using)
+ if (using && DECL_CONTEXT (fn) == type)
/* Defer to the local function. */
return;
else
@@ -1331,17 +1303,9 @@ add_method (type, method, error_p)
fn, method);
}
}
-
- /* Since this is an ordinary function in a
- non-template class, it's mangled name can be used
- as a unique identifier. This technique is only
- an optimization; we would get the same results if
- we just used decls_match here. */
- if (DECL_ASSEMBLER_NAME (fn)
- != DECL_ASSEMBLER_NAME (method))
- continue;
}
- else if (!decls_match (fn, method))
+
+ if (!decls_match (fn, method))
continue;
/* There has already been a declaration of this method
@@ -1486,6 +1450,9 @@ alter_access (t, fdecl, access)
if (!DECL_LANG_SPECIFIC (fdecl))
retrofit_lang_decl (fdecl);
+ if (DECL_DISCRIMINATOR_P (fdecl))
+ abort ();
+
elem = purpose_member (t, DECL_ACCESS (fdecl));
if (elem)
{
@@ -1622,12 +1589,12 @@ check_bases (t, cant_have_default_ctor_p, cant_have_const_ctor_p,
{
int n_baseclasses;
int i;
- int seen_nearly_empty_base_p;
+ int seen_non_virtual_nearly_empty_base_p;
tree binfos;
binfos = TYPE_BINFO_BASETYPES (t);
n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
- seen_nearly_empty_base_p = 0;
+ seen_non_virtual_nearly_empty_base_p = 0;
/* An aggregate cannot have baseclasses. */
CLASSTYPE_NON_AGGREGATE (t) |= (n_baseclasses != 0);
@@ -1688,19 +1655,23 @@ check_bases (t, cant_have_default_ctor_p, cant_have_const_ctor_p,
basetype);
}
- /* If the base class is not empty or nearly empty, then this
- class cannot be nearly empty. */
- if (!CLASSTYPE_NEARLY_EMPTY_P (basetype) && !is_empty_class (basetype))
- CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
- /* And if there is more than one nearly empty base, then the
- derived class is not nearly empty either. */
- else if (CLASSTYPE_NEARLY_EMPTY_P (basetype)
- && seen_nearly_empty_base_p)
- CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
- /* If this is the first nearly empty base class, then remember
- that we saw it. */
+ if (TREE_VIA_VIRTUAL (base_binfo))
+ /* A virtual base does not effect nearly emptiness. */
+ ;
else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
- seen_nearly_empty_base_p = 1;
+ {
+ if (seen_non_virtual_nearly_empty_base_p)
+ /* And if there is more than one nearly empty base, then the
+ derived class is not nearly empty either. */
+ CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
+ else
+ /* Remember we've seen one. */
+ seen_non_virtual_nearly_empty_base_p = 1;
+ }
+ else if (!is_empty_class (basetype))
+ /* If the base class is not empty or nearly empty, then this
+ class cannot be nearly empty. */
+ CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
/* A lot of properties from the bases also apply to the derived
class. */
@@ -1742,10 +1713,15 @@ force_canonical_binfo_r (to, from, type, mappings)
tree mappings;
{
int i, n_baseclasses = BINFO_N_BASETYPES (from);
-
+
+ my_friendly_assert (to != from, 20010905);
BINFO_INDIRECT_PRIMARY_P (to)
= BINFO_INDIRECT_PRIMARY_P (from);
BINFO_INDIRECT_PRIMARY_P (from) = 0;
+ BINFO_UNSHARED_MARKED (to) = BINFO_UNSHARED_MARKED (from);
+ BINFO_UNSHARED_MARKED (from) = 0;
+ BINFO_LOST_PRIMARY_P (to) = BINFO_LOST_PRIMARY_P (from);
+ BINFO_LOST_PRIMARY_P (from) = 0;
if (BINFO_PRIMARY_P (from))
{
tree primary = BINFO_PRIMARY_BASE_OF (from);
@@ -1759,18 +1735,31 @@ force_canonical_binfo_r (to, from, type, mappings)
BINFO_PRIMARY_BASE_OF (to) = primary;
BINFO_PRIMARY_BASE_OF (from) = NULL_TREE;
}
- my_friendly_assert (same_type_p (BINFO_TYPE (to), BINFO_TYPE (from)), 20010104);
+ my_friendly_assert (same_type_p (BINFO_TYPE (to), BINFO_TYPE (from)),
+ 20010104);
mappings = tree_cons (from, to, mappings);
+
+ if (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (from))
+ && TREE_VIA_VIRTUAL (CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (from))))
+ {
+ tree from_primary = get_primary_binfo (from);
+
+ if (BINFO_PRIMARY_BASE_OF (from_primary) == from)
+ force_canonical_binfo (get_primary_binfo (to), from_primary,
+ type, mappings);
+ }
+
for (i = 0; i != n_baseclasses; i++)
{
tree from_binfo = BINFO_BASETYPE (from, i);
tree to_binfo = BINFO_BASETYPE (to, i);
-
+
if (TREE_VIA_VIRTUAL (from_binfo))
{
- tree shared_binfo = binfo_for_vbase (BINFO_TYPE (from_binfo), type);
-
- if (shared_binfo == from_binfo)
+ if (BINFO_PRIMARY_P (from_binfo) &&
+ purpose_member (BINFO_PRIMARY_BASE_OF (from_binfo), mappings))
+ /* This base is a primary of some binfo we have already
+ reseated. We must reseat this one too. */
force_canonical_binfo (to_binfo, from_binfo, type, mappings);
}
else
@@ -1797,30 +1786,29 @@ force_canonical_binfo (to, from, type, mappings)
{
tree assoc = purpose_member (BINFO_TYPE (to),
CLASSTYPE_VBASECLASSES (type));
- TREE_VALUE (assoc) = to;
- force_canonical_binfo_r (to, from, type, mappings);
+ if (TREE_VALUE (assoc) != to)
+ {
+ TREE_VALUE (assoc) = to;
+ force_canonical_binfo_r (to, from, type, mappings);
+ }
}
-/* Make BASE_BINFO the primary virtual base of BINFO within the hierarchy
- dominated by TYPE. Returns BASE_BINFO, if it can be made so, NULL
+/* Make BASE_BINFO the a primary virtual base within the hierarchy
+ dominated by TYPE. Returns BASE_BINFO, if it is not already one, NULL
otherwise (because something else has already made it primary). */
static tree
-mark_primary_virtual_base (binfo, base_binfo, type)
- tree binfo;
+mark_primary_virtual_base (base_binfo, type)
tree base_binfo;
tree type;
{
tree shared_binfo = binfo_for_vbase (BINFO_TYPE (base_binfo), type);
- tree delta;
if (BINFO_PRIMARY_P (shared_binfo))
{
/* It's already allocated in the hierarchy. BINFO won't have a
primary base in this hierachy, even though the complete object
BINFO is for, would do. */
- BINFO_LOST_PRIMARY_P (binfo) = 1;
-
return NULL_TREE;
}
@@ -1831,13 +1819,60 @@ mark_primary_virtual_base (binfo, base_binfo, type)
if (base_binfo != shared_binfo)
force_canonical_binfo (base_binfo, shared_binfo, type, NULL);
- delta = size_diffop (BINFO_OFFSET (binfo), BINFO_OFFSET (base_binfo));
- if (!integer_zerop (delta))
+ return base_binfo;
+}
+
+/* If BINFO is an unmarked virtual binfo for a class with a primary virtual
+ base, then BINFO has no primary base in this graph. Called from
+ mark_primary_bases. DATA is the most derived type. */
+
+static tree dfs_unshared_virtual_bases (binfo, data)
+ tree binfo;
+ void *data;
+{
+ tree t = (tree) data;
+
+ if (!BINFO_UNSHARED_MARKED (binfo)
+ && CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (binfo)))
{
- propagate_binfo_offsets (base_binfo, delta);
- BINFO_OFFSET (base_binfo) = BINFO_OFFSET (binfo);
+ /* This morally virtual base has a primary base when it
+ is a complete object. We need to locate the shared instance
+ of this binfo in the type dominated by T. We duplicate the
+ primary base information from there to here. */
+ tree vbase;
+ tree unshared_base;
+
+ for (vbase = binfo; !TREE_VIA_VIRTUAL (vbase);
+ vbase = BINFO_INHERITANCE_CHAIN (vbase))
+ continue;
+ unshared_base = get_original_base (binfo,
+ binfo_for_vbase (BINFO_TYPE (vbase),
+ t));
+ my_friendly_assert (unshared_base != binfo, 20010612);
+ BINFO_LOST_PRIMARY_P (binfo) = BINFO_LOST_PRIMARY_P (unshared_base);
+ if (!BINFO_LOST_PRIMARY_P (binfo))
+ BINFO_PRIMARY_BASE_OF (get_primary_binfo (binfo)) = binfo;
}
- return base_binfo;
+
+ if (binfo != TYPE_BINFO (t))
+ /* The vtable fields will have been copied when duplicating the
+ base binfos. That information is bogus, make sure we don't try
+ and use it. */
+ BINFO_VTABLE (binfo) = NULL_TREE;
+
+ /* If this is a virtual primary base, make sure its offset matches
+ that which it is primary for. */
+ if (BINFO_PRIMARY_P (binfo) && TREE_VIA_VIRTUAL (binfo) &&
+ binfo_for_vbase (BINFO_TYPE (binfo), t) == binfo)
+ {
+ tree delta = size_diffop (BINFO_OFFSET (BINFO_PRIMARY_BASE_OF (binfo)),
+ BINFO_OFFSET (binfo));
+ if (!integer_zerop (delta))
+ propagate_binfo_offsets (binfo, delta, t);
+ }
+
+ BINFO_UNSHARED_MARKED (binfo) = 0;
+ return NULL;
}
/* Set BINFO_PRIMARY_BASE_OF for all binfos in the hierarchy
@@ -1861,11 +1896,24 @@ mark_primary_bases (type)
base_binfo = get_primary_binfo (binfo);
if (TREE_VIA_VIRTUAL (base_binfo))
- base_binfo = mark_primary_virtual_base (binfo, base_binfo, type);
+ base_binfo = mark_primary_virtual_base (base_binfo, type);
if (base_binfo)
BINFO_PRIMARY_BASE_OF (base_binfo) = binfo;
+ else
+ BINFO_LOST_PRIMARY_P (binfo) = 1;
+
+ BINFO_UNSHARED_MARKED (binfo) = 1;
}
+ /* There could remain unshared morally virtual bases which were not
+ visited in the inheritance graph walk. These bases will have lost
+ their virtual primary base (should they have one). We must now
+ find them. Also we must fix up the BINFO_OFFSETs of primary
+ virtual bases. We could not do that as we went along, as they
+ were originally copied from the bases we inherited from by
+ unshare_base_binfos. That may have decided differently about
+ where a virtual primary base went. */
+ dfs_walk (TYPE_BINFO (type), dfs_unshared_virtual_bases, NULL, type);
}
/* Make the BINFO the primary base of T. */
@@ -1942,9 +1990,6 @@ determine_primary_base (t, vfuns_p)
= tree_cons (base_binfo,
VF_BASETYPE_VALUE (vfields),
CLASSTYPE_VFIELDS (t));
-
- if (!flag_new_abi && *vfuns_p == 0)
- set_primary_base (t, base_binfo, vfuns_p);
}
}
}
@@ -1994,7 +2039,7 @@ determine_primary_base (t, vfuns_p)
/* The new ABI allows for the use of a "nearly-empty" virtual base
class as the primary base class if no non-virtual polymorphic
base can be found. */
- if (flag_new_abi && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
+ if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
{
/* If not NULL, this is the best primary base candidate we have
found so far. */
@@ -2459,13 +2504,11 @@ layout_vtable_decl (binfo, n)
tree binfo;
int n;
{
- tree itype;
tree atype;
tree vtable;
- itype = size_int (n);
atype = build_cplus_array_type (vtable_entry_type,
- build_index_type (itype));
+ build_index_type (size_int (n - 1)));
layout_type (atype);
/* We may have to grow the vtable. */
@@ -2486,7 +2529,7 @@ layout_vtable_decl (binfo, n)
/* True iff FNDECL and BASE_FNDECL (both non-static member functions)
have the same signature. */
-static int
+int
same_signature_p (fndecl, base_fndecl)
tree fndecl, base_fndecl;
{
@@ -2524,6 +2567,9 @@ typedef struct find_final_overrider_data_s {
tree most_derived_type;
/* The final overriding function. */
tree overriding_fn;
+ /* The functions that we thought might be final overriders, but
+ aren't. */
+ tree candidates;
/* The BINFO for the class in which the final overriding function
appears. */
tree overriding_base;
@@ -2554,13 +2600,8 @@ dfs_find_final_overrider (binfo, data)
path;
path = TREE_CHAIN (path))
{
- for (method = TYPE_METHODS (BINFO_TYPE (TREE_VALUE (path)));
- method;
- method = TREE_CHAIN (method))
- if (DECL_VIRTUAL_P (method)
- && same_signature_p (method, ffod->fn))
- break;
-
+ method = look_for_overrides_here (BINFO_TYPE (TREE_VALUE (path)),
+ ffod->fn);
if (method)
break;
}
@@ -2582,49 +2623,91 @@ dfs_find_final_overrider (binfo, data)
break;
}
- if (ffod->overriding_fn && ffod->overriding_fn != method)
+ /* If we didn't already have an overrider, or any
+ candidates, then this function is the best candidate so
+ far. */
+ if (!ffod->overriding_fn && !ffod->candidates)
{
- /* We've found a different overrider along a different
- path. That can be OK if the new one overrides the
- old one. Consider:
-
- struct S { virtual void f(); };
- struct T : public virtual S { virtual void f(); };
- struct U : public virtual S, public virtual T {};
-
- Here `T::f' is the final overrider for `S::f'. */
- if (strictly_overrides (method, ffod->overriding_fn))
+ ffod->overriding_fn = method;
+ ffod->overriding_base = TREE_VALUE (path);
+ }
+ else if (ffod->overriding_fn)
+ {
+ /* We had a best overrider; let's see how this compares. */
+
+ if (ffod->overriding_fn == method
+ && (tree_int_cst_equal
+ (BINFO_OFFSET (TREE_VALUE (path)),
+ BINFO_OFFSET (ffod->overriding_base))))
+ /* We found the same overrider we already have, and in the
+ same place; it's still the best. */;
+ else if (strictly_overrides (ffod->overriding_fn, method))
+ /* The old function overrides this function; it's still the
+ best. */;
+ else if (strictly_overrides (method, ffod->overriding_fn))
{
+ /* The new function overrides the old; it's now the
+ best. */
ffod->overriding_fn = method;
ffod->overriding_base = TREE_VALUE (path);
}
- else if (!strictly_overrides (ffod->overriding_fn, method))
+ else
{
- cp_error ("no unique final overrider for `%D' in `%T'",
- ffod->most_derived_type,
- ffod->fn);
- cp_error ("candidates are: `%#D'", ffod->overriding_fn);
- cp_error (" `%#D'", method);
- return error_mark_node;
+ /* Ambiguous. */
+ ffod->candidates
+ = build_tree_list (NULL_TREE,
+ ffod->overriding_fn);
+ if (method != ffod->overriding_fn)
+ ffod->candidates
+ = tree_cons (NULL_TREE, method, ffod->candidates);
+ ffod->overriding_fn = NULL_TREE;
+ ffod->overriding_base = NULL_TREE;
}
}
- else if (ffod->overriding_base
- && (!tree_int_cst_equal
- (BINFO_OFFSET (TREE_VALUE (path)),
- BINFO_OFFSET (ffod->overriding_base))))
- {
- /* We've found two instances of the same base that
- provide overriders. */
- cp_error ("no unique final overrider for `%D' since there two instances of `%T' in `%T'",
- ffod->fn,
- BINFO_TYPE (ffod->overriding_base),
- ffod->most_derived_type);
- return error_mark_node;
- }
else
{
- ffod->overriding_fn = method;
- ffod->overriding_base = TREE_VALUE (path);
+ /* We had a list of ambiguous overrides; let's see how this
+ new one compares. */
+
+ tree candidates;
+ bool incomparable = false;
+
+ /* If there were previous candidates, and this function
+ overrides all of them, then it is the new best
+ candidate. */
+ for (candidates = ffod->candidates;
+ candidates;
+ candidates = TREE_CHAIN (candidates))
+ {
+ /* If the candidate overrides the METHOD, then we
+ needn't worry about it any further. */
+ if (strictly_overrides (TREE_VALUE (candidates),
+ method))
+ {
+ method = NULL_TREE;
+ break;
+ }
+
+ /* If the METHOD doesn't override the candidate,
+ then it is incomporable. */
+ if (!strictly_overrides (method,
+ TREE_VALUE (candidates)))
+ incomparable = true;
+ }
+
+ /* If METHOD overrode all the candidates, then it is the
+ new best candidate. */
+ if (!candidates && !incomparable)
+ {
+ ffod->overriding_fn = method;
+ ffod->overriding_base = TREE_VALUE (path);
+ ffod->candidates = NULL_TREE;
+ }
+ /* If METHOD didn't override all the candidates, then it
+ is another candidate. */
+ else if (method && incomparable)
+ ffod->candidates
+ = tree_cons (NULL_TREE, method, ffod->candidates);
}
}
}
@@ -2658,7 +2741,7 @@ find_final_overrider (t, binfo, fn)
struct T : virtual public R { virtual void f (); };
struct U : public S, public T { };
- is not -- there's no way to decide whether to put `S::f' or
+ is not -- there's no way to decide whether to put `S::f' or
`T::f' in the vtable for `R'.
The solution is to look at all paths to BINFO. If we find
@@ -2668,19 +2751,43 @@ find_final_overrider (t, binfo, fn)
ffod.most_derived_type = t;
ffod.overriding_fn = NULL_TREE;
ffod.overriding_base = NULL_TREE;
+ ffod.candidates = NULL_TREE;
- if (dfs_walk (TYPE_BINFO (t),
- dfs_find_final_overrider,
- NULL,
- &ffod))
- return error_mark_node;
+ dfs_walk (TYPE_BINFO (t),
+ dfs_find_final_overrider,
+ NULL,
+ &ffod);
+
+ /* If there was no winner, issue an error message. */
+ if (!ffod.overriding_fn)
+ {
+ cp_error ("no unique final overrider for `%D' in `%T'", fn, t);
+ return error_mark_node;
+ }
return build_tree_list (ffod.overriding_fn, ffod.overriding_base);
}
-/* Update a entry in the vtable for BINFO, which is in the hierarchy
- dominated by T. FN has been overridden in BINFO; VIRTUALS points
- to the corresponding position in the BINFO_VIRTUALS list. */
+/* Returns the function from the BINFO_VIRTUALS entry in T which matches
+ the signature of FUNCTION_DECL FN, or NULL_TREE if none. In other words,
+ the function that the slot in T's primary vtable points to. */
+
+static tree get_matching_virtual PARAMS ((tree, tree));
+static tree
+get_matching_virtual (t, fn)
+ tree t, fn;
+{
+ tree f;
+
+ for (f = BINFO_VIRTUALS (TYPE_BINFO (t)); f; f = TREE_CHAIN (f))
+ if (same_signature_p (BV_FN (f), fn))
+ return BV_FN (f);
+ return NULL_TREE;
+}
+
+/* Update an entry in the vtable for BINFO, which is in the hierarchy
+ dominated by T. FN has been overriden in BINFO; VIRTUALS points to the
+ corresponding position in the BINFO_VIRTUALS list. */
static void
update_vtable_entry_for_fn (t, binfo, fn, virtuals)
@@ -2693,98 +2800,95 @@ update_vtable_entry_for_fn (t, binfo, fn, virtuals)
tree overrider;
tree delta;
tree virtual_base;
- int generate_thunk_with_vtable_p;
+ tree first_defn;
+ bool lost = false;
- /* Find the function which originally caused this vtable
- entry to be present. */
- b = binfo;
- while (1)
+ /* Find the nearest primary base (possibly binfo itself) which defines
+ this function; this is the class the caller will convert to when
+ calling FN through BINFO. */
+ for (b = binfo; ; b = get_primary_binfo (b))
{
- tree primary_base;
- tree f;
-
- primary_base = get_primary_binfo (b);
- if (!primary_base)
- break;
-
- for (f = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (primary_base)));
- f;
- f = TREE_CHAIN (f))
- if (same_signature_p (BV_FN (f), fn))
- break;
-
- if (!f)
+ if (look_for_overrides_here (BINFO_TYPE (b), fn))
break;
- fn = BV_FN (f);
- b = primary_base;
+ /* The nearest definition is from a lost primary. */
+ if (BINFO_LOST_PRIMARY_P (b))
+ lost = true;
}
+ first_defn = b;
/* Find the final overrider. */
overrider = find_final_overrider (t, b, fn);
if (overrider == error_mark_node)
return;
- /* Compute the constant adjustment to the `this' pointer. The
- `this' pointer, when this function is called, will point at the
- class whose vtable this is. */
- delta = size_binop (PLUS_EXPR,
- get_derived_offset (binfo,
- DECL_VIRTUAL_CONTEXT (fn)),
- BINFO_OFFSET (binfo));
-
/* Assume that we will produce a thunk that convert all the way to
the final overrider, and not to an intermediate virtual base. */
virtual_base = NULL_TREE;
- /* Assume that we will always generate thunks with the vtables that
- reference them. */
- generate_thunk_with_vtable_p = 1;
+ /* See if we can convert to an intermediate virtual base first, and then
+ use the vcall offset located there to finish the conversion. */
+ for (; b; b = BINFO_INHERITANCE_CHAIN (b))
+ {
+ /* If we find the final overrider, then we can stop
+ walking. */
+ if (same_type_p (BINFO_TYPE (b),
+ BINFO_TYPE (TREE_VALUE (overrider))))
+ break;
+
+ /* If we find a virtual base, and we haven't yet found the
+ overrider, then there is a virtual base between the
+ declaring base (first_defn) and the final overrider. */
+ if (!virtual_base && TREE_VIA_VIRTUAL (b))
+ virtual_base = b;
+ }
- /* Under the new ABI, we will convert to an intermediate virtual
- base first, and then use the vcall offset located there to finish
- the conversion. */
- if (flag_new_abi)
+ /* Compute the constant adjustment to the `this' pointer. The
+ `this' pointer, when this function is called, will point at BINFO
+ (or one of its primary bases, which are at the same offset). */
+
+ if (virtual_base)
+ /* The `this' pointer needs to be adjusted from the declaration to
+ the nearest virtual base. */
+ delta = size_diffop (BINFO_OFFSET (virtual_base),
+ BINFO_OFFSET (first_defn));
+ else if (lost)
+ /* If the nearest definition is in a lost primary, we don't need an
+ entry in our vtable. Except possibly in a constructor vtable,
+ if we happen to get our primary back. In that case, the offset
+ will be zero, as it will be a primary base. */
+ delta = size_zero_node;
+ else
{
- while (b)
- {
- /* If we find BINFO, then the final overrider is in a class
- derived from BINFO, so the thunks can be generated with
- the final overrider. */
- if (!virtual_base
- && same_type_p (BINFO_TYPE (b), BINFO_TYPE (binfo)))
- generate_thunk_with_vtable_p = 0;
-
- /* If we find the final overrider, then we can stop
- walking. */
- if (same_type_p (BINFO_TYPE (b),
- BINFO_TYPE (TREE_VALUE (overrider))))
- break;
+ /* The `this' pointer needs to be adjusted from pointing to
+ BINFO to pointing at the base where the final overrider
+ appears. */
+ delta = size_diffop (BINFO_OFFSET (TREE_VALUE (overrider)),
+ BINFO_OFFSET (binfo));
- /* If we find a virtual base, and we haven't yet found the
- overrider, then there is a virtual base between the
- declaring base and the final overrider. */
- if (!virtual_base && TREE_VIA_VIRTUAL (b))
+ if (! integer_zerop (delta))
+ {
+ /* We'll need a thunk. But if we have a (perhaps formerly)
+ primary virtual base, we have a vcall slot for this function,
+ so we can use it rather than create a non-virtual thunk. */
+
+ b = get_primary_binfo (first_defn);
+ for (; b; b = get_primary_binfo (b))
{
- generate_thunk_with_vtable_p = 1;
- virtual_base = b;
+ tree f = get_matching_virtual (BINFO_TYPE (b), fn);
+ if (!f)
+ /* b doesn't have this function; no suitable vbase. */
+ break;
+ if (TREE_VIA_VIRTUAL (b))
+ {
+ /* Found one; we can treat ourselves as a virtual base. */
+ virtual_base = binfo;
+ delta = size_zero_node;
+ break;
+ }
}
-
- b = BINFO_INHERITANCE_CHAIN (b);
}
}
- else
- virtual_base = NULL_TREE;
-
- if (virtual_base)
- /* The `this' pointer needs to be adjusted to the nearest virtual
- base. */
- delta = size_diffop (BINFO_OFFSET (virtual_base), delta);
- else
- /* The `this' pointer needs to be adjusted from pointing to
- BINFO to pointing at the base where the final overrider
- appears. */
- delta = size_diffop (BINFO_OFFSET (TREE_VALUE (overrider)), delta);
modify_vtable_entry (t,
binfo,
@@ -2794,8 +2898,6 @@ update_vtable_entry_for_fn (t, binfo, fn, virtuals)
if (virtual_base)
BV_USE_VCALL_INDEX_P (*virtuals) = 1;
- if (generate_thunk_with_vtable_p)
- BV_GENERATE_THUNK_WITH_VTABLE_P (*virtuals) = 1;
}
/* Called from modify_all_vtables via dfs_walk. */
@@ -2806,9 +2908,9 @@ dfs_modify_vtables (binfo, data)
void *data;
{
if (/* There's no need to modify the vtable for a non-virtual
- primary base; we're not going to use that vtable anyhow
- (virtual primary bases can become non-primary in a
- class derivation of this one.) */
+ primary base; we're not going to use that vtable anyhow.
+ We do still need to do this for virtual primary bases, as they
+ could become non-primary in a construction vtable. */
(!BINFO_PRIMARY_P (binfo) || TREE_VIA_VIRTUAL (binfo))
/* Similarly, a base without a vtable needs no modification. */
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
@@ -2822,8 +2924,7 @@ dfs_modify_vtables (binfo, data)
/* If we're supporting RTTI then we always need a new vtable to
point to the RTTI information. Under the new ABI we may need
a new vtable to contain vcall and vbase offsets. */
- if (flag_rtti || flag_new_abi)
- make_new_vtable (t, binfo);
+ make_new_vtable (t, binfo);
/* Now, go through each of the virtual functions in the virtual
function table for BINFO. Find the final overrider, and
@@ -2884,7 +2985,7 @@ modify_all_vtables (t, vfuns_p, overridden_virtuals)
|| !value_member (fn, BINFO_VIRTUALS (binfo)))
{
/* Set the vtable index. */
- set_vindex (t, fn, vfuns_p);
+ set_vindex (fn, vfuns_p);
/* We don't need to convert to a base class when calling
this function. */
DECL_VIRTUAL_CONTEXT (fn) = t;
@@ -2925,59 +3026,37 @@ strictly_overrides (fndecl1, fndecl2)
return 0;
}
-/* Get the base virtual function declarations in T that are either
- overridden or hidden by FNDECL as a list. We set TREE_PURPOSE with
- the overrider/hider. */
+/* Get the base virtual function declarations in T that have the
+ indicated NAME. */
static tree
-get_basefndecls (fndecl, t)
- tree fndecl, t;
+get_basefndecls (name, t)
+ tree name, t;
{
- tree methods = TYPE_METHODS (t);
+ tree methods;
tree base_fndecls = NULL_TREE;
- tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
- int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
-
- while (methods)
- {
- if (TREE_CODE (methods) == FUNCTION_DECL
- && DECL_VINDEX (methods) != NULL_TREE
- && DECL_NAME (fndecl) == DECL_NAME (methods))
- base_fndecls = tree_cons (fndecl, methods, base_fndecls);
+ int n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
+ int i;
- methods = TREE_CHAIN (methods);
- }
+ for (methods = TYPE_METHODS (t); methods; methods = TREE_CHAIN (methods))
+ if (TREE_CODE (methods) == FUNCTION_DECL
+ && DECL_VINDEX (methods) != NULL_TREE
+ && DECL_NAME (methods) == name)
+ base_fndecls = tree_cons (NULL_TREE, methods, base_fndecls);
if (base_fndecls)
return base_fndecls;
for (i = 0; i < n_baseclasses; i++)
{
- tree base_binfo = TREE_VEC_ELT (binfos, i);
- tree basetype = BINFO_TYPE (base_binfo);
-
- base_fndecls = chainon (get_basefndecls (fndecl, basetype),
+ tree basetype = TYPE_BINFO_BASETYPE (t, i);
+ base_fndecls = chainon (get_basefndecls (name, basetype),
base_fndecls);
}
return base_fndecls;
}
-/* Mark the functions that have been hidden with their overriders.
- Since we start out with all functions already marked with a hider,
- no need to mark functions that are just hidden.
-
- Subroutine of warn_hidden. */
-
-static void
-mark_overriders (fndecl, base_fndecls)
- tree fndecl, base_fndecls;
-{
- for (; base_fndecls; base_fndecls = TREE_CHAIN (base_fndecls))
- if (same_signature_p (fndecl, TREE_VALUE (base_fndecls)))
- TREE_PURPOSE (base_fndecls) = fndecl;
-}
-
/* If this declaration supersedes the declaration of
a method declared virtual in the base class, then
mark this field as being virtual as well. */
@@ -3025,57 +3104,59 @@ warn_hidden (t)
/* We go through each separately named virtual function. */
for (i = 2; i < n_methods && TREE_VEC_ELT (method_vec, i); ++i)
{
- tree fns = TREE_VEC_ELT (method_vec, i);
- tree fndecl = NULL_TREE;
-
- tree base_fndecls = NULL_TREE;
- tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
- int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
-
- /* First see if we have any virtual functions in this batch. */
- for (; fns; fns = OVL_NEXT (fns))
+ tree fns;
+ tree name;
+ tree fndecl;
+ tree base_fndecls;
+ int j;
+
+ /* All functions in this slot in the CLASSTYPE_METHOD_VEC will
+ have the same name. Figure out what name that is. */
+ name = DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
+ /* There are no possibly hidden functions yet. */
+ base_fndecls = NULL_TREE;
+ /* Iterate through all of the base classes looking for possibly
+ hidden functions. */
+ for (j = 0; j < CLASSTYPE_N_BASECLASSES (t); j++)
{
- fndecl = OVL_CURRENT (fns);
- if (DECL_VINDEX (fndecl))
- break;
+ tree basetype = TYPE_BINFO_BASETYPE (t, j);
+ base_fndecls = chainon (get_basefndecls (name, basetype),
+ base_fndecls);
}
- if (fns == NULL_TREE)
+ /* If there are no functions to hide, continue. */
+ if (!base_fndecls)
continue;
- /* First we get a list of all possible functions that might be
- hidden from each base class. */
- for (i = 0; i < n_baseclasses; i++)
+ /* Remove any overridden functions. */
+ for (fns = TREE_VEC_ELT (method_vec, i); fns; fns = OVL_NEXT (fns))
{
- tree base_binfo = TREE_VEC_ELT (binfos, i);
- tree basetype = BINFO_TYPE (base_binfo);
-
- base_fndecls = chainon (get_basefndecls (fndecl, basetype),
- base_fndecls);
+ fndecl = OVL_CURRENT (fns);
+ if (DECL_VINDEX (fndecl))
+ {
+ tree *prev = &base_fndecls;
+
+ while (*prev)
+ /* If the method from the base class has the same
+ signature as the method from the derived class, it
+ has been overridden. */
+ if (same_signature_p (fndecl, TREE_VALUE (*prev)))
+ *prev = TREE_CHAIN (*prev);
+ else
+ prev = &TREE_CHAIN (*prev);
+ }
}
- fns = OVL_NEXT (fns);
-
- /* ...then mark up all the base functions with overriders, preferring
- overriders to hiders. */
- if (base_fndecls)
- for (; fns; fns = OVL_NEXT (fns))
- {
- fndecl = OVL_CURRENT (fns);
- if (DECL_VINDEX (fndecl))
- mark_overriders (fndecl, base_fndecls);
- }
-
/* Now give a warning for all base functions without overriders,
as they are hidden. */
- for (; base_fndecls; base_fndecls = TREE_CHAIN (base_fndecls))
- if (!same_signature_p (TREE_PURPOSE (base_fndecls),
- TREE_VALUE (base_fndecls)))
- {
- /* Here we know it is a hider, and no overrider exists. */
- cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls));
- cp_warning_at (" by `%D'", TREE_PURPOSE (base_fndecls));
- }
+ while (base_fndecls)
+ {
+ /* Here we know it is a hider, and no overrider exists. */
+ cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls));
+ cp_warning_at (" by `%D'",
+ OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
+ base_fndecls = TREE_CHAIN (base_fndecls);
+ }
}
}
@@ -3624,10 +3705,9 @@ check_field_decls (t, access_decls, empty_p,
if (DECL_MUTABLE_P (x) || TYPE_HAS_MUTABLE_P (type))
CLASSTYPE_HAS_MUTABLE (t) = 1;
- if (! pod_type_p (type)
- /* For some reason, pointers to members are POD types themselves,
- but are not allowed in POD structs. Silly. */
- || TYPE_PTRMEM_P (type) || TYPE_PTRMEMFUNC_P (type))
+ if (! pod_type_p (type))
+ /* DR 148 now allows pointers to members (which are POD themselves),
+ to be allowed in POD structs. */
CLASSTYPE_NON_POD_P (t) = 1;
/* If any field is const, the structure type is pseudo-const. */
@@ -3724,7 +3804,7 @@ build_vtbl_or_vbase_field (name, assembler_name, type, class_type, fcontext,
/* Build the FIELD_DECL. */
field = build_decl (FIELD_DECL, name, type);
- DECL_ASSEMBLER_NAME (field) = assembler_name;
+ SET_DECL_ASSEMBLER_NAME (field, assembler_name);
DECL_VIRTUAL_P (field) = 1;
DECL_ARTIFICIAL (field) = 1;
DECL_FIELD_CONTEXT (field) = class_type;
@@ -3794,20 +3874,30 @@ check_subobject_offset (type, offset, offsets)
/* Walk through all the subobjects of TYPE (located at OFFSET). Call
F for every subobject, passing it the type, offset, and table of
OFFSETS. If VBASES_P is non-zero, then even virtual non-primary
- bases should be traversed; otherwise, they are ignored. If F
- returns a non-zero value, the traversal ceases, and that value is
- returned. Otherwise, returns zero. */
+ bases should be traversed; otherwise, they are ignored.
+
+ If MAX_OFFSET is non-NULL, then subobjects with an offset greater
+ than MAX_OFFSET will not be walked.
+
+ If F returns a non-zero value, the traversal ceases, and that value
+ is returned. Otherwise, returns zero. */
static int
-walk_subobject_offsets (type, f, offset, offsets, vbases_p)
+walk_subobject_offsets (type, f, offset, offsets, max_offset, vbases_p)
tree type;
subobject_offset_fn f;
tree offset;
splay_tree offsets;
+ tree max_offset;
int vbases_p;
{
int r = 0;
+ /* If this OFFSET is bigger than the MAX_OFFSET, then we should
+ stop. */
+ if (max_offset && INT_CST_LT (max_offset, offset))
+ return 0;
+
if (CLASS_TYPE_P (type))
{
tree field;
@@ -3834,6 +3924,7 @@ walk_subobject_offsets (type, f, offset, offsets, vbases_p)
offset,
BINFO_OFFSET (binfo)),
offsets,
+ max_offset,
vbases_p);
if (r)
return r;
@@ -3849,6 +3940,7 @@ walk_subobject_offsets (type, f, offset, offsets, vbases_p)
offset,
DECL_FIELD_OFFSET (field)),
offsets,
+ max_offset,
/*vbases_p=*/1);
if (r)
return r;
@@ -3868,11 +3960,17 @@ walk_subobject_offsets (type, f, offset, offsets, vbases_p)
f,
offset,
offsets,
+ max_offset,
/*vbases_p=*/1);
if (r)
return r;
offset = size_binop (PLUS_EXPR, offset,
TYPE_SIZE_UNIT (TREE_TYPE (type)));
+ /* If this new OFFSET is bigger than the MAX_OFFSET, then
+ there's no point in iterating through the remaining
+ elements of the array. */
+ if (max_offset && INT_CST_LT (max_offset, offset))
+ break;
}
}
@@ -3891,7 +3989,7 @@ record_subobject_offsets (type, offset, offsets, vbases_p)
int vbases_p;
{
walk_subobject_offsets (type, record_subobject_offset, offset,
- offsets, vbases_p);
+ offsets, /*max_offset=*/NULL_TREE, vbases_p);
}
/* Returns non-zero if any of the empty subobjects of TYPE (located at
@@ -3905,22 +4003,34 @@ layout_conflict_p (type, offset, offsets, vbases_p)
splay_tree offsets;
int vbases_p;
{
+ splay_tree_node max_node;
+
+ /* Get the node in OFFSETS that indicates the maximum offset where
+ an empty subobject is located. */
+ max_node = splay_tree_max (offsets);
+ /* If there aren't any empty subobjects, then there's no point in
+ performing this check. */
+ if (!max_node)
+ return 0;
+
return walk_subobject_offsets (type, check_subobject_offset, offset,
- offsets, vbases_p);
+ offsets, (tree) (max_node->key),
+ vbases_p);
}
/* DECL is a FIELD_DECL corresponding either to a base subobject of a
non-static data member of the type indicated by RLI. BINFO is the
binfo corresponding to the base subobject, OFFSETS maps offsets to
- types already located at those offsets. This function determines
- the position of the DECL. */
+ types already located at those offsets. T is the most derived
+ type. This function determines the position of the DECL. */
static void
-layout_nonempty_base_or_field (rli, decl, binfo, offsets)
+layout_nonempty_base_or_field (rli, decl, binfo, offsets, t)
record_layout_info rli;
tree decl;
tree binfo;
splay_tree offsets;
+ tree t;
{
tree offset = NULL_TREE;
tree type = TREE_TYPE (decl);
@@ -3954,10 +4064,10 @@ layout_nonempty_base_or_field (rli, decl, binfo, offsets)
empty class, have non-zero size, any overlap can happen only
with a direct or indirect base-class -- it can't happen with
a data member. */
- if (flag_new_abi && layout_conflict_p (TREE_TYPE (decl),
- offset,
- offsets,
- field_p))
+ if (layout_conflict_p (TREE_TYPE (decl),
+ offset,
+ offsets,
+ field_p))
{
/* Strip off the size allocated to this field. That puts us
at the first place we could have put the field with
@@ -3977,26 +4087,29 @@ layout_nonempty_base_or_field (rli, decl, binfo, offsets)
break;
}
- /* Now that we know where it wil be placed, update its
+ /* Now that we know where it will be placed, update its
BINFO_OFFSET. */
if (binfo && CLASS_TYPE_P (BINFO_TYPE (binfo)))
propagate_binfo_offsets (binfo,
- convert (ssizetype, offset));
+ convert (ssizetype, offset), t);
}
/* Layout the empty base BINFO. EOC indicates the byte currently just
past the end of the class, and should be correctly aligned for a
class of the type indicated by BINFO; OFFSETS gives the offsets of
- the empty bases allocated so far. */
+ the empty bases allocated so far. T is the most derived
+ type. Return non-zero iff we added it at the end. */
-static void
-layout_empty_base (binfo, eoc, offsets)
+static bool
+layout_empty_base (binfo, eoc, offsets, t)
tree binfo;
tree eoc;
splay_tree offsets;
+ tree t;
{
tree alignment;
tree basetype = BINFO_TYPE (binfo);
+ bool atend = false;
/* This routine should only be used for empty classes. */
my_friendly_assert (is_empty_class (basetype), 20000321);
@@ -4011,7 +4124,8 @@ layout_empty_base (binfo, eoc, offsets)
{
/* That didn't work. Now, we move forward from the next
available spot in the class. */
- propagate_binfo_offsets (binfo, convert (ssizetype, eoc));
+ atend = true;
+ propagate_binfo_offsets (binfo, convert (ssizetype, eoc), t);
while (1)
{
if (!layout_conflict_p (BINFO_TYPE (binfo),
@@ -4022,31 +4136,35 @@ layout_empty_base (binfo, eoc, offsets)
break;
/* There's overlap here, too. Bump along to the next spot. */
- propagate_binfo_offsets (binfo, alignment);
+ propagate_binfo_offsets (binfo, alignment, t);
}
}
+ return atend;
}
/* Build a FIELD_DECL for the base given by BINFO in the class
indicated by RLI. If the new object is non-empty, clear *EMPTY_P.
*BASE_ALIGN is a running maximum of the alignments of any base
- class. OFFSETS gives the location of empty base subobjects. */
+ class. OFFSETS gives the location of empty base subobjects. T is
+ the most derived type. Return non-zero if the new object cannot be
+ nearly-empty. */
-static void
-build_base_field (rli, binfo, empty_p, base_align, offsets)
+static bool
+build_base_field (rli, binfo, empty_p, offsets, t)
record_layout_info rli;
tree binfo;
int *empty_p;
- unsigned int *base_align;
splay_tree offsets;
+ tree t;
{
tree basetype = BINFO_TYPE (binfo);
tree decl;
+ bool atend = false;
if (!COMPLETE_TYPE_P (basetype))
/* This error is now reported in xref_tag, thus giving better
location information. */
- return;
+ return atend;
decl = build_decl (FIELD_DECL, NULL_TREE, basetype);
DECL_ARTIFICIAL (decl) = 1;
@@ -4056,20 +4174,6 @@ build_base_field (rli, binfo, empty_p, base_align, offsets)
DECL_ALIGN (decl) = CLASSTYPE_ALIGN (basetype);
DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
- if (! flag_new_abi)
- {
- /* Brain damage for backwards compatibility. For no good
- reason, the old basetype layout made every base have at least
- as large as the alignment for the bases up to that point,
- gratuitously wasting space. So we do the same thing here. */
- *base_align = MAX (*base_align, DECL_ALIGN (decl));
- DECL_SIZE (decl)
- = size_binop (MAX_EXPR, DECL_SIZE (decl), bitsize_int (*base_align));
- DECL_SIZE_UNIT (decl)
- = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
- size_int (*base_align / BITS_PER_UNIT));
- }
-
if (!integer_zerop (DECL_SIZE (decl)))
{
/* The containing class is non-empty because it has a non-empty
@@ -4079,7 +4183,7 @@ build_base_field (rli, binfo, empty_p, base_align, offsets)
/* Try to place the field. It may take more than one try if we
have a hard time placing the field without putting two
objects of the same type at the same address. */
- layout_nonempty_base_or_field (rli, decl, binfo, offsets);
+ layout_nonempty_base_or_field (rli, decl, binfo, offsets, t);
}
else
{
@@ -4089,44 +4193,40 @@ build_base_field (rli, binfo, empty_p, base_align, offsets)
byte-aligned. */
eoc = tree_low_cst (rli_size_unit_so_far (rli), 0);
eoc = CEIL (eoc, DECL_ALIGN_UNIT (decl)) * DECL_ALIGN_UNIT (decl);
- layout_empty_base (binfo, size_int (eoc), offsets);
+ atend |= layout_empty_base (binfo, size_int (eoc), offsets, t);
}
- /* Check for inaccessible base classes. If the same base class
- appears more than once in the hierarchy, but isn't virtual, then
- it's ambiguous. */
- if (get_base_distance (basetype, rli->t, 0, NULL) == -2)
- cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
- basetype, rli->t);
-
/* Record the offsets of BINFO and its base subobjects. */
record_subobject_offsets (BINFO_TYPE (binfo),
BINFO_OFFSET (binfo),
offsets,
/*vbases_p=*/0);
+ return atend;
}
/* Layout all of the non-virtual base classes. Record empty
- subobjects in OFFSETS. */
+ subobjects in OFFSETS. T is the most derived type. Return
+ non-zero if the type cannot be nearly empty. */
-static void
-build_base_fields (rli, empty_p, offsets)
+static bool
+build_base_fields (rli, empty_p, offsets, t)
record_layout_info rli;
int *empty_p;
splay_tree offsets;
+ tree t;
{
/* Chain to hold all the new FIELD_DECLs which stand in for base class
subobjects. */
tree rec = rli->t;
int n_baseclasses = CLASSTYPE_N_BASECLASSES (rec);
int i;
- unsigned int base_align = 0;
+ bool atend = 0;
/* Under the new ABI, the primary base class is always allocated
first. */
- if (flag_new_abi && CLASSTYPE_HAS_PRIMARY_BASE_P (rec))
+ if (CLASSTYPE_HAS_PRIMARY_BASE_P (rec))
build_base_field (rli, CLASSTYPE_PRIMARY_BINFO (rec),
- empty_p, &base_align, offsets);
+ empty_p, offsets, t);
/* Now allocate the rest of the bases. */
for (i = 0; i < n_baseclasses; ++i)
@@ -4137,7 +4237,7 @@ build_base_fields (rli, empty_p, offsets)
/* Under the new ABI, the primary base was already allocated
above, so we don't need to allocate it again here. */
- if (flag_new_abi && base_binfo == CLASSTYPE_PRIMARY_BINFO (rec))
+ if (base_binfo == CLASSTYPE_PRIMARY_BINFO (rec))
continue;
/* A primary virtual base class is allocated just like any other
@@ -4147,8 +4247,9 @@ build_base_fields (rli, empty_p, offsets)
&& !BINFO_PRIMARY_P (base_binfo))
continue;
- build_base_field (rli, base_binfo, empty_p, &base_align, offsets);
+ atend |= build_base_field (rli, base_binfo, empty_p, offsets, t);
}
+ return atend;
}
/* Go through the TYPE_METHODS of T issuing any appropriate
@@ -4167,7 +4268,8 @@ check_methods (t)
GNU_xref_member (current_class_name, x);
/* If this was an evil function, don't keep it in class. */
- if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
+ if (DECL_ASSEMBLER_NAME_SET_P (x)
+ && IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
continue;
check_for_override (x, t);
@@ -4196,18 +4298,13 @@ check_methods (t)
[class.free]) requires that the second argument be set
correctly. */
second_parm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (x)));
- /* This is overly conservative, but we must maintain this
- behavior for backwards compatibility. */
- if (!flag_new_abi && second_parm != void_list_node)
- TYPE_VEC_DELETE_TAKES_SIZE (t) = 1;
/* Under the new ABI, we choose only those function that are
explicitly declared as `operator delete[] (void *,
size_t)'. */
- else if (flag_new_abi
- && !seen_one_arg_array_delete_p
- && second_parm
- && TREE_CHAIN (second_parm) == void_list_node
- && same_type_p (TREE_VALUE (second_parm), sizetype))
+ if (!seen_one_arg_array_delete_p
+ && second_parm
+ && TREE_CHAIN (second_parm) == void_list_node
+ && same_type_p (TREE_VALUE (second_parm), sizetype))
TYPE_VEC_DELETE_TAKES_SIZE (t) = 1;
/* If there's no second parameter, then this is the usual
deallocation function. */
@@ -4233,16 +4330,15 @@ build_clone (fn, name)
clone = copy_decl (fn);
/* Remember where this function came from. */
DECL_CLONED_FUNCTION (clone) = fn;
+ DECL_ABSTRACT_ORIGIN (clone) = fn;
/* Reset the function name. */
DECL_NAME (clone) = name;
- DECL_ASSEMBLER_NAME (clone) = DECL_NAME (clone);
+ SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
/* There's no pending inline data for this function. */
DECL_PENDING_INLINE_INFO (clone) = NULL;
DECL_PENDING_INLINE_P (clone) = 0;
/* And it hasn't yet been deferred. */
DECL_DEFERRED_FN (clone) = 0;
- /* There's no magic VTT parameter in the clone. */
- DECL_VTT_PARM (clone) = NULL_TREE;
/* The base-class destructor is not virtual. */
if (name == base_dtor_identifier)
@@ -4267,10 +4363,12 @@ build_clone (fn, name)
parmtypes = TREE_CHAIN (parmtypes);
/* Skip the in-charge parameter. */
parmtypes = TREE_CHAIN (parmtypes);
+ /* And the VTT parm, in a complete [cd]tor. */
+ if (DECL_HAS_VTT_PARM_P (fn)
+ && ! DECL_NEEDS_VTT_PARM_P (clone))
+ parmtypes = TREE_CHAIN (parmtypes);
/* If this is subobject constructor or destructor, add the vtt
parameter. */
- if (DECL_NEEDS_VTT_PARM_P (clone))
- parmtypes = hash_tree_chain (vtt_parm_type, parmtypes);
TREE_TYPE (clone)
= build_cplus_method_type (basetype,
TREE_TYPE (TREE_TYPE (clone)),
@@ -4280,8 +4378,8 @@ build_clone (fn, name)
exceptions);
}
- /* Copy the function parameters. But, DECL_ARGUMENTS aren't
- function parameters; instead, those are the template parameters. */
+ /* Copy the function parameters. But, DECL_ARGUMENTS on a TEMPLATE_DECL
+ aren't function parameters; those are the template parameters. */
if (TREE_CODE (clone) != TEMPLATE_DECL)
{
DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
@@ -4292,16 +4390,17 @@ build_clone (fn, name)
= TREE_CHAIN (TREE_CHAIN (DECL_ARGUMENTS (clone)));
DECL_HAS_IN_CHARGE_PARM_P (clone) = 0;
}
-
- /* Add the VTT parameter. */
- if (DECL_NEEDS_VTT_PARM_P (clone))
+ /* And the VTT parm, in a complete [cd]tor. */
+ if (DECL_HAS_VTT_PARM_P (fn))
{
- tree parm;
-
- parm = build_artificial_parm (vtt_parm_identifier,
- vtt_parm_type);
- TREE_CHAIN (parm) = TREE_CHAIN (DECL_ARGUMENTS (clone));
- TREE_CHAIN (DECL_ARGUMENTS (clone)) = parm;
+ if (DECL_NEEDS_VTT_PARM_P (clone))
+ DECL_HAS_VTT_PARM_P (clone) = 1;
+ else
+ {
+ TREE_CHAIN (DECL_ARGUMENTS (clone))
+ = TREE_CHAIN (TREE_CHAIN (DECL_ARGUMENTS (clone)));
+ DECL_HAS_VTT_PARM_P (clone) = 0;
+ }
}
for (parms = DECL_ARGUMENTS (clone); parms; parms = TREE_CHAIN (parms))
@@ -4311,11 +4410,8 @@ build_clone (fn, name)
}
}
- /* Mangle the function name. */
- set_mangled_name_for_decl (clone);
-
/* Create the RTL for this function. */
- DECL_RTL (clone) = NULL_RTX;
+ SET_DECL_RTL (clone, NULL_RTX);
rest_of_decl_compilation (clone, NULL, /*top_level=*/1, at_eof);
/* Make it easy to find the CLONE given the FN. */
@@ -4351,9 +4447,8 @@ clone_function_decl (fn, update_method_vec_p)
tree clone;
/* Avoid inappropriate cloning. */
- if (! flag_new_abi
- || (TREE_CHAIN (fn)
- && DECL_CLONED_FUNCTION (TREE_CHAIN (fn))))
+ if (TREE_CHAIN (fn)
+ && DECL_CLONED_FUNCTION (TREE_CHAIN (fn)))
return;
if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
@@ -4376,10 +4471,16 @@ clone_function_decl (fn, update_method_vec_p)
version. We clone the deleting version first because that
means it will go second on the TYPE_METHODS list -- and that
corresponds to the correct layout order in the virtual
- function table. */
- clone = build_clone (fn, deleting_dtor_identifier);
- if (update_method_vec_p)
- add_method (DECL_CONTEXT (clone), clone, /*error_p=*/0);
+ function table.
+
+ For a non-virtual destructor, we do not build a deleting
+ destructor. */
+ if (DECL_VIRTUAL_P (fn))
+ {
+ clone = build_clone (fn, deleting_dtor_identifier);
+ if (update_method_vec_p)
+ add_method (DECL_CONTEXT (clone), clone, /*error_p=*/0);
+ }
clone = build_clone (fn, complete_dtor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, /*error_p=*/0);
@@ -4387,6 +4488,83 @@ clone_function_decl (fn, update_method_vec_p)
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, /*error_p=*/0);
}
+
+ /* Note that this is an abstract function that is never emitted. */
+ DECL_ABSTRACT (fn) = 1;
+}
+
+/* DECL is an in charge constructor, which is being defined. This will
+ have had an in class declaration, from whence clones were
+ declared. An out-of-class definition can specify additional default
+ arguments. As it is the clones that are involved in overload
+ resolution, we must propagate the information from the DECL to its
+ clones. */
+
+void
+adjust_clone_args (decl)
+ tree decl;
+{
+ tree clone;
+
+ for (clone = TREE_CHAIN (decl); clone && DECL_CLONED_FUNCTION (clone);
+ clone = TREE_CHAIN (clone))
+ {
+ tree orig_clone_parms = TYPE_ARG_TYPES (TREE_TYPE (clone));
+ tree orig_decl_parms = TYPE_ARG_TYPES (TREE_TYPE (decl));
+ tree decl_parms, clone_parms;
+
+ clone_parms = orig_clone_parms;
+
+ /* Skip the 'this' parameter. */
+ orig_clone_parms = TREE_CHAIN (orig_clone_parms);
+ orig_decl_parms = TREE_CHAIN (orig_decl_parms);
+
+ if (DECL_HAS_IN_CHARGE_PARM_P (decl))
+ orig_decl_parms = TREE_CHAIN (orig_decl_parms);
+ if (DECL_HAS_VTT_PARM_P (decl))
+ orig_decl_parms = TREE_CHAIN (orig_decl_parms);
+
+ clone_parms = orig_clone_parms;
+ if (DECL_HAS_VTT_PARM_P (clone))
+ clone_parms = TREE_CHAIN (clone_parms);
+
+ for (decl_parms = orig_decl_parms; decl_parms;
+ decl_parms = TREE_CHAIN (decl_parms),
+ clone_parms = TREE_CHAIN (clone_parms))
+ {
+ my_friendly_assert (same_type_p (TREE_TYPE (decl_parms),
+ TREE_TYPE (clone_parms)), 20010424);
+
+ if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms))
+ {
+ /* A default parameter has been added. Adjust the
+ clone's parameters. */
+ tree exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (clone));
+ tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
+ tree type;
+
+ clone_parms = orig_decl_parms;
+
+ if (DECL_HAS_VTT_PARM_P (clone))
+ {
+ clone_parms = tree_cons (TREE_PURPOSE (orig_clone_parms),
+ TREE_VALUE (orig_clone_parms),
+ clone_parms);
+ TREE_TYPE (clone_parms) = TREE_TYPE (orig_clone_parms);
+ }
+ type = build_cplus_method_type (basetype,
+ TREE_TYPE (TREE_TYPE (clone)),
+ clone_parms);
+ if (exceptions)
+ type = build_exception_variant (type, exceptions);
+ TREE_TYPE (clone) = type;
+
+ clone_parms = NULL_TREE;
+ break;
+ }
+ }
+ my_friendly_assert (!clone_parms, 20010424);
+ }
}
/* For each of the constructors and destructors in T, create an
@@ -4398,10 +4576,6 @@ clone_constructors_and_destructors (t)
{
tree fns;
- /* We only clone constructors and destructors under the new ABI. */
- if (!flag_new_abi)
- return;
-
/* If for some reason we don't have a CLASSTYPE_METHOD_VEC, we bail
out now. */
if (!CLASSTYPE_METHOD_VEC (t))
@@ -4500,7 +4674,7 @@ check_bases_and_members (t, empty_p)
|| TYPE_HAS_ASSIGN_REF (t));
TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
TYPE_HAS_COMPLEX_ASSIGN_REF (t)
- |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t);
+ |= TYPE_HAS_ASSIGN_REF (t) || TYPE_CONTAINS_VPTR_P (t);
/* Synthesize any needed methods. Note that methods will be synthesized
for anonymous unions; grok_x_components undoes that. */
@@ -4540,8 +4714,7 @@ create_vtable_ptr (t, empty_p, vfuns_p,
/* Loop over the virtual functions, adding them to our various
vtables. */
for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
- if (DECL_VINDEX (fn)
- && !(flag_new_abi && DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)))
+ if (DECL_VINDEX (fn) && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn))
add_virtual_function (new_virtuals_p, overridden_virtuals_p,
vfuns_p, fn, t);
@@ -4580,7 +4753,7 @@ create_vtable_ptr (t, empty_p, vfuns_p,
t,
empty_p);
- if (flag_new_abi && CLASSTYPE_N_BASECLASSES (t))
+ if (CLASSTYPE_N_BASECLASSES (t))
/* If there were any baseclasses, they can't possibly be at
offset zero any more, because that's where the vtable
pointer is. So, converting to a base class is going to
@@ -4648,9 +4821,10 @@ fixup_inline_methods (type)
OFFSET, which is a type offset, is number of bytes. */
static void
-propagate_binfo_offsets (binfo, offset)
+propagate_binfo_offsets (binfo, offset, t)
tree binfo;
tree offset;
+ tree t;
{
int i;
tree primary_binfo;
@@ -4671,9 +4845,9 @@ propagate_binfo_offsets (binfo, offset)
{
tree base_binfo;
- /* On the first through the loop, do the primary base. Because
- the primary base need not be an immediate base, we must
- handle the primary base specially. */
+ /* On the first time through the loop, do the primary base.
+ Because the primary base need not be an immediate base, we
+ must handle the primary base specially. */
if (i == -1)
{
if (!primary_binfo)
@@ -4689,12 +4863,13 @@ propagate_binfo_offsets (binfo, offset)
continue;
}
- /* Skip virtual bases that aren't our primary base. */
+ /* Skip virtual bases that aren't our canonical primary base. */
if (TREE_VIA_VIRTUAL (base_binfo)
- && BINFO_PRIMARY_BASE_OF (base_binfo) != binfo)
+ && (BINFO_PRIMARY_BASE_OF (base_binfo) != binfo
+ || base_binfo != binfo_for_vbase (BINFO_TYPE (base_binfo), t)))
continue;
- propagate_binfo_offsets (base_binfo, offset);
+ propagate_binfo_offsets (base_binfo, offset, t);
}
}
@@ -4708,15 +4883,18 @@ dfs_set_offset_for_unshared_vbases (binfo, data)
/* If this is a virtual base, make sure it has the same offset as
the shared copy. If it's a primary base, then we know it's
correct. */
- if (TREE_VIA_VIRTUAL (binfo) && !BINFO_PRIMARY_P (binfo))
+ if (TREE_VIA_VIRTUAL (binfo))
{
tree t = (tree) data;
tree vbase;
tree offset;
vbase = binfo_for_vbase (BINFO_TYPE (binfo), t);
- offset = size_diffop (BINFO_OFFSET (vbase), BINFO_OFFSET (binfo));
- propagate_binfo_offsets (binfo, offset);
+ if (vbase != binfo)
+ {
+ offset = size_diffop (BINFO_OFFSET (vbase), BINFO_OFFSET (binfo));
+ propagate_binfo_offsets (binfo, offset, t);
+ }
}
return NULL_TREE;
@@ -4751,26 +4929,19 @@ layout_virtual_bases (t, offsets)
TYPE_ALIGN (t) = MAX (TYPE_ALIGN (t), BITS_PER_UNIT);
/* Go through the virtual bases, allocating space for each virtual
- base that is not already a primary base class. Under the new
+ base that is not already a primary base class. Under the old
ABI, these are allocated according to a depth-first left-to-right
postorder traversal; in the new ABI, inheritance graph order is
used instead. */
- for (vbases = (flag_new_abi
- ? TYPE_BINFO (t)
- : CLASSTYPE_VBASECLASSES (t));
+ for (vbases = TYPE_BINFO (t);
vbases;
vbases = TREE_CHAIN (vbases))
{
tree vbase;
- if (flag_new_abi)
- {
- if (!TREE_VIA_VIRTUAL (vbases))
- continue;
- vbase = binfo_for_vbase (BINFO_TYPE (vbases), t);
- }
- else
- vbase = TREE_VALUE (vbases);
+ if (!TREE_VIA_VIRTUAL (vbases))
+ continue;
+ vbase = binfo_for_vbase (BINFO_TYPE (vbases), t);
if (!BINFO_PRIMARY_P (vbase))
{
@@ -4781,13 +4952,7 @@ layout_virtual_bases (t, offsets)
basetype = BINFO_TYPE (vbase);
- if (flag_new_abi)
- desired_align = CLASSTYPE_ALIGN (basetype);
- else
- /* Under the old ABI, virtual bases were aligned as for the
- entire base object (including its virtual bases). That's
- wasteful, in general. */
- desired_align = TYPE_ALIGN (basetype);
+ desired_align = CLASSTYPE_ALIGN (basetype);
TYPE_ALIGN (t) = MAX (TYPE_ALIGN (t), desired_align);
/* Add padding so that we can put the virtual base class at an
@@ -4796,10 +4961,10 @@ layout_virtual_bases (t, offsets)
/* Under the new ABI, we try to squish empty virtual bases in
just like ordinary empty bases. */
- if (flag_new_abi && is_empty_class (basetype))
+ if (is_empty_class (basetype))
layout_empty_base (vbase,
size_int (CEIL (dsize, BITS_PER_UNIT)),
- offsets);
+ offsets, t);
else
{
tree offset;
@@ -4810,7 +4975,7 @@ layout_virtual_bases (t, offsets)
BINFO_OFFSET (vbase)));
/* And compute the offset of the virtual base. */
- propagate_binfo_offsets (vbase, offset);
+ propagate_binfo_offsets (vbase, offset, t);
/* Every virtual baseclass takes a least a UNIT, so that
we can take it's address and get something different
for each base. */
@@ -4838,7 +5003,7 @@ layout_virtual_bases (t, offsets)
multiple such bases at the same location. */
eoc = end_of_class (t, /*include_virtuals_p=*/1);
if (eoc * BITS_PER_UNIT > dsize)
- dsize = (eoc + 1) * BITS_PER_UNIT;
+ dsize = eoc * BITS_PER_UNIT;
/* Now, make sure that the total size of the type is a multiple of
its alignment. */
@@ -4877,6 +5042,7 @@ end_of_class (t, include_virtuals_p)
{
tree base_binfo;
tree offset;
+ tree size;
unsigned HOST_WIDE_INT end_of_base;
base_binfo = BINFO_BASETYPE (TYPE_BINFO (t), i);
@@ -4886,9 +5052,16 @@ end_of_class (t, include_virtuals_p)
&& !BINFO_PRIMARY_P (base_binfo))
continue;
+ if (is_empty_class (BINFO_TYPE (base_binfo)))
+ /* An empty class has zero CLASSTYPE_SIZE_UNIT, but we need to
+ allocate some space for it. It cannot have virtual bases,
+ so TYPE_SIZE_UNIT is fine. */
+ size = TYPE_SIZE_UNIT (BINFO_TYPE (base_binfo));
+ else
+ size = CLASSTYPE_SIZE_UNIT (BINFO_TYPE (base_binfo));
offset = size_binop (PLUS_EXPR,
BINFO_OFFSET (base_binfo),
- CLASSTYPE_SIZE_UNIT (BINFO_TYPE (base_binfo)));
+ size);
end_of_base = tree_low_cst (offset, /*pos=*/1);
if (end_of_base > result)
result = end_of_base;
@@ -4897,6 +5070,32 @@ end_of_class (t, include_virtuals_p)
return result;
}
+/* Warn about direct bases of T that are inaccessible because they are
+ ambiguous. For example:
+
+ struct S {};
+ struct T : public S {};
+ struct U : public S, public T {};
+
+ Here, `(S*) new U' is not allowed because there are two `S'
+ subobjects of U. */
+
+static void
+warn_about_ambiguous_direct_bases (t)
+ tree t;
+{
+ int i;
+
+ for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); ++i)
+ {
+ tree basetype = TYPE_BINFO_BASETYPE (t, i);
+
+ if (get_base_distance (basetype, t, 0, NULL) == -2)
+ cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
+ basetype, t);
+ }
+}
+
/* Compare two INTEGER_CSTs K1 and K2. */
static int
@@ -4945,7 +5144,7 @@ layout_class_type (t, empty_p, vfuns_p,
/* Under the new ABI, the vptr is always the first thing in the
class. */
- if (flag_new_abi && vptr)
+ if (vptr)
{
TYPE_FIELDS (t) = chainon (vptr, TYPE_FIELDS (t));
place_field (rli, vptr);
@@ -4954,14 +5153,15 @@ layout_class_type (t, empty_p, vfuns_p,
/* Build FIELD_DECLs for all of the non-virtual base-types. */
empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
NULL, NULL);
- build_base_fields (rli, empty_p, empty_base_offsets);
+ if (build_base_fields (rli, empty_p, empty_base_offsets, t))
+ CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
+
/* Add pointers to all of our virtual base-classes. */
TYPE_FIELDS (t) = chainon (build_vbase_pointer_fields (rli, empty_p),
TYPE_FIELDS (t));
/* CLASSTYPE_INLINE_FRIENDS is really TYPE_NONCOPIED_PARTS. Thus,
- we have to save this before we start modifying
- TYPE_NONCOPIED_PARTS. */
+ we have to save this before we zap TYPE_NONCOPIED_PARTS. */
fixup_inline_methods (t);
/* Layout the non-static data members. */
@@ -4986,12 +5186,7 @@ layout_class_type (t, empty_p, vfuns_p,
rules, but the back-end can't handle bitfields longer than a
`long long', so we use the same mechanism. */
if (DECL_C_BIT_FIELD (field)
- && ((flag_new_abi
- && INT_CST_LT (TYPE_SIZE (type), DECL_SIZE (field)))
- || (!flag_new_abi
- && 0 < compare_tree_int (DECL_SIZE (field),
- TYPE_PRECISION
- (long_long_unsigned_type_node)))))
+ && INT_CST_LT (TYPE_SIZE (type), DECL_SIZE (field)))
{
integer_type_kind itk;
tree integer_type;
@@ -5019,7 +5214,7 @@ layout_class_type (t, empty_p, vfuns_p,
padding = NULL_TREE;
layout_nonempty_base_or_field (rli, field, NULL_TREE,
- empty_base_offsets);
+ empty_base_offsets, t);
/* If we needed additional padding after this field, add it
now. */
@@ -5036,7 +5231,7 @@ layout_class_type (t, empty_p, vfuns_p,
DECL_USER_ALIGN (padding_field) = 0;
layout_nonempty_base_or_field (rli, padding_field,
NULL_TREE,
- empty_base_offsets);
+ empty_base_offsets, t);
}
}
@@ -5049,11 +5244,7 @@ layout_class_type (t, empty_p, vfuns_p,
if (TREE_CODE (rli_size_unit_so_far (rli)) == INTEGER_CST
&& compare_tree_int (rli_size_unit_so_far (rli), eoc) < 0)
{
- /* We don't handle zero-sized base classes specially under the
- old ABI, so if we get here, we had better be operating under
- the new ABI rules. */
- my_friendly_assert (flag_new_abi, 20000321);
- rli->offset = size_binop (MAX_EXPR, rli->offset, size_int (eoc + 1));
+ rli->offset = size_binop (MAX_EXPR, rli->offset, size_int (eoc));
rli->bitpos = bitsize_zero_node;
}
@@ -5062,25 +5253,14 @@ layout_class_type (t, empty_p, vfuns_p,
if it has basetypes. Therefore, we add the fake field after all
the other fields; if there are already FIELD_DECLs on the list,
their offsets will not be disturbed. */
- if (*empty_p)
+ if (!eoc && *empty_p)
{
tree padding;
padding = build_decl (FIELD_DECL, NULL_TREE, char_type_node);
place_field (rli, padding);
- TYPE_NONCOPIED_PARTS (t)
- = tree_cons (NULL_TREE, padding, TYPE_NONCOPIED_PARTS (t));
- TREE_STATIC (TYPE_NONCOPIED_PARTS (t)) = 1;
}
- /* Under the old ABI, the vptr comes at the very end of the
- class. */
- if (!flag_new_abi && vptr)
- {
- place_field (rli, vptr);
- TYPE_FIELDS (t) = chainon (TYPE_FIELDS (t), vptr);
- }
-
/* Let the back-end lay out the type. Note that at this point we
have only included non-virtual base-classes; we will lay out the
virtual base classes later. So, the TYPE_SIZE/TYPE_ALIGN after
@@ -5094,21 +5274,16 @@ layout_class_type (t, empty_p, vfuns_p,
/* Remember the size and alignment of the class before adding
the virtual bases. */
- if (*empty_p && flag_new_abi)
+ if (*empty_p)
{
CLASSTYPE_SIZE (t) = bitsize_zero_node;
CLASSTYPE_SIZE_UNIT (t) = size_zero_node;
}
- else if (flag_new_abi)
+ else
{
CLASSTYPE_SIZE (t) = TYPE_BINFO_SIZE (t);
CLASSTYPE_SIZE_UNIT (t) = TYPE_BINFO_SIZE_UNIT (t);
}
- else
- {
- CLASSTYPE_SIZE (t) = TYPE_SIZE (t);
- CLASSTYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (t);
- }
CLASSTYPE_ALIGN (t) = TYPE_ALIGN (t);
CLASSTYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (t);
@@ -5124,6 +5299,10 @@ layout_class_type (t, empty_p, vfuns_p,
base subobject fields. */
layout_virtual_bases (t, empty_base_offsets);
+ /* Warn about direct bases that can't be talked about due to
+ ambiguity. */
+ warn_about_ambiguous_direct_bases (t);
+
/* Clean up. */
splay_tree_delete (empty_base_offsets);
}
@@ -5202,29 +5381,27 @@ finish_struct_1 (t)
layout_class_type (t, &empty, &vfuns,
&new_virtuals, &overridden_virtuals);
- if (flag_dump_class_layout)
- dump_class_hierarchy (*flag_dump_class_layout
- ? flag_dump_class_layout : NULL,
- t);
-
- /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
- might need to know it for setting up the offsets in the vtable
- (or in thunks) below. */
+ /* Make sure that we get our own copy of the vfield FIELD_DECL. */
vfield = TYPE_VFIELD (t);
- if (vfield != NULL_TREE
- && DECL_FIELD_CONTEXT (vfield) != t)
- {
- tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
-
+ if (vfield && CLASSTYPE_HAS_PRIMARY_BASE_P (t))
+ {
+ tree primary = CLASSTYPE_PRIMARY_BINFO (t);
+
+ my_friendly_assert (same_type_p (DECL_FIELD_CONTEXT (vfield),
+ BINFO_TYPE (primary)),
+ 20010726);
+ /* The vtable better be at the start. */
+ my_friendly_assert (integer_zerop (DECL_FIELD_OFFSET (vfield)),
+ 20010726);
+ my_friendly_assert (integer_zerop (BINFO_OFFSET (primary)),
+ 20010726);
+
vfield = copy_decl (vfield);
-
DECL_FIELD_CONTEXT (vfield) = t;
- DECL_FIELD_OFFSET (vfield)
- = size_binop (PLUS_EXPR,
- BINFO_OFFSET (binfo),
- DECL_FIELD_OFFSET (vfield));
TYPE_VFIELD (t) = vfield;
}
+ else
+ my_friendly_assert (!vfield || DECL_FIELD_CONTEXT (vfield) == t, 20010726);
overridden_virtuals
= modify_all_vtables (t, &vfuns, nreverse (overridden_virtuals));
@@ -5294,14 +5471,9 @@ finish_struct_1 (t)
/* Complete the rtl for any static member objects of the type we're
working on. */
for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x))
- {
- if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
- && TREE_TYPE (x) == t)
- {
- DECL_MODE (x) = TYPE_MODE (t);
- make_decl_rtl (x, NULL);
- }
- }
+ if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
+ && TREE_TYPE (x) == t)
+ DECL_MODE (x) = TYPE_MODE (t);
/* Done with FIELDS...now decide whether to sort these for
faster lookups later.
@@ -5345,20 +5517,9 @@ finish_struct_1 (t)
/* Build the VTT for T. */
build_vtt (t);
- if (TYPE_VFIELD (t))
- {
- /* In addition to this one, all the other vfields should be listed. */
- /* Before that can be done, we have to have FIELD_DECLs for them, and
- a place to find them. */
- TYPE_NONCOPIED_PARTS (t)
- = tree_cons (default_conversion (TYPE_BINFO_VTABLE (t)),
- TYPE_VFIELD (t), TYPE_NONCOPIED_PARTS (t));
-
- if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t)
- && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1)) == NULL_TREE)
- cp_warning ("`%#T' has virtual functions but non-virtual destructor",
- t);
- }
+ if (warn_nonvdtor && TYPE_POLYMORPHIC_P (t) && TYPE_HAS_DESTRUCTOR (t)
+ && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1)) == NULL_TREE)
+ cp_warning ("`%#T' has virtual functions but non-virtual destructor", t);
hack_incomplete_structures (t);
@@ -5367,6 +5528,8 @@ finish_struct_1 (t)
maybe_suppress_debug_info (t);
+ dump_class_hierarchy (t);
+
/* Finish debugging output for this type. */
rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
}
@@ -5461,9 +5624,10 @@ finish_struct (t, attributes)
before this function is called. */
static tree
-fixed_type_or_null (instance, nonnull)
+fixed_type_or_null (instance, nonnull, cdtorp)
tree instance;
int *nonnull;
+ int *cdtorp;
{
switch (TREE_CODE (instance))
{
@@ -5491,31 +5655,31 @@ fixed_type_or_null (instance, nonnull)
*nonnull = 1;
return TREE_TYPE (instance);
}
- return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
+ return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
case RTL_EXPR:
return NULL_TREE;
case PLUS_EXPR:
case MINUS_EXPR:
+ if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
+ return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
/* Propagate nonnull. */
- fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
- if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
- return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
+ fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
return NULL_TREE;
case NOP_EXPR:
case CONVERT_EXPR:
- return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
+ return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
case ADDR_EXPR:
if (nonnull)
*nonnull = 1;
- return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
+ return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
case COMPONENT_REF:
- return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull);
+ return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull, cdtorp);
case VAR_DECL:
case FIELD_DECL:
@@ -5535,21 +5699,25 @@ fixed_type_or_null (instance, nonnull)
*nonnull = 1;
return TREE_TYPE (instance);
}
- else if (nonnull)
- {
- if (instance == current_class_ptr
- && flag_this_is_variable <= 0)
- {
- /* Normally, 'this' must be non-null. */
- if (flag_this_is_variable == 0)
- *nonnull = 1;
-
- /* <0 means we're in a constructor and we know our type. */
- if (flag_this_is_variable < 0)
- return TREE_TYPE (TREE_TYPE (instance));
- }
- else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
- /* Reference variables should be references to objects. */
+ else if (instance == current_class_ptr)
+ {
+ if (nonnull)
+ *nonnull = 1;
+
+ /* if we're in a ctor or dtor, we know our type. */
+ if (DECL_LANG_SPECIFIC (current_function_decl)
+ && (DECL_CONSTRUCTOR_P (current_function_decl)
+ || DECL_DESTRUCTOR_P (current_function_decl)))
+ {
+ if (cdtorp)
+ *cdtorp = 1;
+ return TREE_TYPE (TREE_TYPE (instance));
+ }
+ }
+ else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
+ {
+ /* Reference variables should be references to objects. */
+ if (nonnull)
*nonnull = 1;
}
return NULL_TREE;
@@ -5561,7 +5729,9 @@ fixed_type_or_null (instance, nonnull)
/* Return non-zero if the dynamic type of INSTANCE is known, and equivalent
to the static type. We also handle the case where INSTANCE is really
- a pointer.
+ a pointer. Return negative if this is a ctor/dtor. There the dynamic type
+ is known, but this might not be the most derived base of the original object,
+ and hence virtual bases may not be layed out according to this type.
Used to determine whether the virtual function table is needed
or not.
@@ -5576,12 +5746,16 @@ resolves_to_fixed_type_p (instance, nonnull)
int *nonnull;
{
tree t = TREE_TYPE (instance);
- tree fixed = fixed_type_or_null (instance, nonnull);
+ int cdtorp = 0;
+
+ tree fixed = fixed_type_or_null (instance, nonnull, &cdtorp);
if (fixed == NULL_TREE)
return 0;
if (POINTER_TYPE_P (t))
t = TREE_TYPE (t);
- return same_type_ignoring_top_level_qualifiers_p (t, fixed);
+ if (!same_type_ignoring_top_level_qualifiers_p (t, fixed))
+ return 0;
+ return cdtorp ? -1 : 1;
}
@@ -6493,23 +6667,13 @@ int
is_empty_class (type)
tree type;
{
- tree t;
-
if (type == error_mark_node)
return 0;
if (! IS_AGGR_TYPE (type))
return 0;
- if (flag_new_abi)
- return integer_zerop (CLASSTYPE_SIZE (type));
-
- if (TYPE_BINFO_BASETYPES (type))
- return 0;
- t = TYPE_FIELDS (type);
- while (t && TREE_CODE (t) != FIELD_DECL)
- t = TREE_CHAIN (t);
- return (t == NULL_TREE);
+ return integer_zerop (CLASSTYPE_SIZE (type));
}
/* Find the enclosing class of the given NODE. NODE can be a *_DECL or
@@ -6642,36 +6806,43 @@ get_vtbl_decl_for_binfo (binfo)
return decl;
}
-/* Called from get_primary_binfo via dfs_walk. */
+/* Called from get_primary_binfo via dfs_walk. DATA is a TREE_LIST
+ who's TREE_PURPOSE is the TYPE of the required primary base and
+ who's TREE_VALUE is a list of candidate binfos that we fill in. */
static tree
dfs_get_primary_binfo (binfo, data)
tree binfo;
void *data;
{
- tree primary_base = (tree) data;
+ tree cons = (tree) data;
+ tree primary_base = TREE_PURPOSE (cons);
if (TREE_VIA_VIRTUAL (binfo)
- && same_type_p (BINFO_TYPE (binfo), BINFO_TYPE (primary_base)))
- return binfo;
+ && same_type_p (BINFO_TYPE (binfo), primary_base))
+ /* This is the right type of binfo, but it might be an unshared
+ instance, and the shared instance is later in the dfs walk. We
+ must keep looking. */
+ TREE_VALUE (cons) = tree_cons (NULL, binfo, TREE_VALUE (cons));
return NULL_TREE;
}
-/* Returns the binfo for the primary base of BINFO. Note that in a
- complex hierarchy the resulting BINFO may not actually *be*
- primary. In particular if the resulting BINFO is a virtual base,
- and it occurs elsewhere in the hierarchy, then this occurrence may
- not actually be a primary base in the complete object. Check
- BINFO_PRIMARY_P to be sure. */
+/* Returns the unshared binfo for the primary base of BINFO. Note
+ that in a complex hierarchy the resulting BINFO may not actually
+ *be* primary. In particular if the resulting BINFO is a virtual
+ base, and it occurs elsewhere in the hierarchy, then this
+ occurrence may not actually be a primary base in the complete
+ object. Check BINFO_PRIMARY_P to be sure. */
tree
get_primary_binfo (binfo)
tree binfo;
{
tree primary_base;
- tree result;
-
+ tree result = NULL_TREE;
+ tree virtuals;
+
primary_base = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (binfo));
if (!primary_base)
return NULL_TREE;
@@ -6699,28 +6870,83 @@ get_primary_binfo (binfo)
/* For a primary virtual base, we have to scan the entire hierarchy
rooted at BINFO; the virtual base could be an indirect virtual
- base. */
- result = dfs_walk (binfo, dfs_get_primary_binfo, NULL, primary_base);
- my_friendly_assert (result != NULL_TREE, 20000730);
+ base. There could be more than one instance of the primary base
+ in the hierarchy, and if one is the canonical binfo we want that
+ one. If it exists, it should be the first one we find, but as a
+ consistency check we find them all and make sure. */
+ virtuals = build_tree_list (BINFO_TYPE (primary_base), NULL_TREE);
+ dfs_walk (binfo, dfs_get_primary_binfo, NULL, virtuals);
+ virtuals = TREE_VALUE (virtuals);
+
+ /* We must have found at least one instance. */
+ my_friendly_assert (virtuals, 20010612);
+
+ if (TREE_CHAIN (virtuals))
+ {
+ /* We found more than one instance of the base. We must make
+ sure that, if one is the canonical one, it is the first one
+ we found. As the chain is in reverse dfs order, that means
+ the last on the list. */
+ tree complete_binfo;
+ tree canonical;
+
+ for (complete_binfo = binfo;
+ BINFO_INHERITANCE_CHAIN (complete_binfo);
+ complete_binfo = BINFO_INHERITANCE_CHAIN (complete_binfo))
+ continue;
+ canonical = binfo_for_vbase (BINFO_TYPE (primary_base),
+ BINFO_TYPE (complete_binfo));
+
+ for (; virtuals; virtuals = TREE_CHAIN (virtuals))
+ {
+ result = TREE_VALUE (virtuals);
+
+ if (canonical == result)
+ {
+ /* This is the unshared instance. Make sure it was the
+ first one found. */
+ my_friendly_assert (!TREE_CHAIN (virtuals), 20010612);
+ break;
+ }
+ }
+ }
+ else
+ result = TREE_VALUE (virtuals);
return result;
}
+/* If INDENTED_P is zero, indent to INDENT. Return non-zero. */
+
+static int
+maybe_indent_hierarchy (stream, indent, indented_p)
+ FILE *stream;
+ int indent;
+ int indented_p;
+{
+ if (!indented_p)
+ fprintf (stream, "%*s", indent, "");
+ return 1;
+}
+
/* Dump the offsets of all the bases rooted at BINFO (in the hierarchy
dominated by T) to stderr. INDENT should be zero when called from
the top level; it is incremented recursively. */
static void
-dump_class_hierarchy_r (stream, t, binfo, indent)
+dump_class_hierarchy_r (stream, flags, t, binfo, indent)
FILE *stream;
+ int flags;
tree t;
tree binfo;
int indent;
{
int i;
-
- fprintf (stream, "%*s0x%lx (%s) ", indent, "",
- (unsigned long) binfo,
- type_as_string (binfo, TFF_PLAIN_IDENTIFIER));
+ int indented = 0;
+
+ indented = maybe_indent_hierarchy (stream, indent, 0);
+ fprintf (stream, "%s (0x%lx) ",
+ type_as_string (binfo, TFF_PLAIN_IDENTIFIER),
+ (unsigned long) binfo);
fprintf (stream, HOST_WIDE_INT_PRINT_DEC,
tree_low_cst (BINFO_OFFSET (binfo), 0));
if (is_empty_class (BINFO_TYPE (binfo)))
@@ -6730,48 +6956,174 @@ dump_class_hierarchy_r (stream, t, binfo, indent)
if (TREE_VIA_VIRTUAL (binfo))
{
tree canonical = binfo_for_vbase (BINFO_TYPE (binfo), t);
-
+
+ fprintf (stream, " virtual");
if (canonical == binfo)
- fprintf (stream, " virtual-canonical");
+ fprintf (stream, " canonical");
else
- fprintf (stream, " virtual-non-canonical");
+ fprintf (stream, " non-canonical");
}
- if (BINFO_PRIMARY_P (binfo))
- fprintf (stream, " primary-for 0x%lx (%s)",
- (unsigned long)BINFO_PRIMARY_BASE_OF (binfo),
- type_as_string (BINFO_PRIMARY_BASE_OF (binfo), TFF_PLAIN_IDENTIFIER));
- if (BINFO_LOST_PRIMARY_P (binfo))
- fprintf (stream, " lost-primary");
fprintf (stream, "\n");
+ indented = 0;
+ if (BINFO_PRIMARY_BASE_OF (binfo))
+ {
+ indented = maybe_indent_hierarchy (stream, indent + 3, indented);
+ fprintf (stream, " primary-for %s (0x%lx)",
+ type_as_string (BINFO_PRIMARY_BASE_OF (binfo),
+ TFF_PLAIN_IDENTIFIER),
+ (unsigned long)BINFO_PRIMARY_BASE_OF (binfo));
+ }
+ if (BINFO_LOST_PRIMARY_P (binfo))
+ {
+ indented = maybe_indent_hierarchy (stream, indent + 3, indented);
+ fprintf (stream, " lost-primary");
+ }
+ if (indented)
+ fprintf (stream, "\n");
+
+ if (!(flags & TDF_SLIM))
+ {
+ int indented = 0;
+
+ if (BINFO_SUBVTT_INDEX (binfo))
+ {
+ indented = maybe_indent_hierarchy (stream, indent + 3, indented);
+ fprintf (stream, " subvttidx=%s",
+ expr_as_string (BINFO_SUBVTT_INDEX (binfo),
+ TFF_PLAIN_IDENTIFIER));
+ }
+ if (BINFO_VPTR_INDEX (binfo))
+ {
+ indented = maybe_indent_hierarchy (stream, indent + 3, indented);
+ fprintf (stream, " vptridx=%s",
+ expr_as_string (BINFO_VPTR_INDEX (binfo),
+ TFF_PLAIN_IDENTIFIER));
+ }
+ if (BINFO_VPTR_FIELD (binfo))
+ {
+ indented = maybe_indent_hierarchy (stream, indent + 3, indented);
+ fprintf (stream, " vbaseoffset=%s",
+ expr_as_string (BINFO_VPTR_FIELD (binfo),
+ TFF_PLAIN_IDENTIFIER));
+ }
+ if (BINFO_VTABLE (binfo))
+ {
+ indented = maybe_indent_hierarchy (stream, indent + 3, indented);
+ fprintf (stream, " vptr=%s",
+ expr_as_string (BINFO_VTABLE (binfo),
+ TFF_PLAIN_IDENTIFIER));
+ }
+
+ if (indented)
+ fprintf (stream, "\n");
+ }
+
+
for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
- dump_class_hierarchy_r (stream, t, BINFO_BASETYPE (binfo, i), indent + 2);
+ dump_class_hierarchy_r (stream, flags,
+ t, BINFO_BASETYPE (binfo, i),
+ indent + 2);
}
/* Dump the BINFO hierarchy for T. */
-void
-dump_class_hierarchy (name, t)
- const char *name;
+static void
+dump_class_hierarchy (t)
tree t;
{
- FILE *stream = stderr;
+ int flags;
+ FILE *stream = dump_begin (TDI_class, &flags);
+
+ if (!stream)
+ return;
- if (name)
+ fprintf (stream, "Class %s\n", type_as_string (t, TFF_PLAIN_IDENTIFIER));
+ fprintf (stream, " size=%lu align=%lu\n",
+ (unsigned long)(tree_low_cst (TYPE_SIZE (t), 0) / BITS_PER_UNIT),
+ (unsigned long)(TYPE_ALIGN (t) / BITS_PER_UNIT));
+ dump_class_hierarchy_r (stream, flags, t, TYPE_BINFO (t), 0);
+ fprintf (stream, "\n");
+ dump_end (TDI_class, stream);
+}
+
+static void
+dump_array (stream, decl)
+ FILE *stream;
+ tree decl;
+{
+ tree inits;
+ int ix;
+ HOST_WIDE_INT elt;
+ tree size = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (decl)));
+
+ elt = (tree_low_cst (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))), 0)
+ / BITS_PER_UNIT);
+ fprintf (stream, "%s:", decl_as_string (decl, TFF_PLAIN_IDENTIFIER));
+ fprintf (stream, " %s entries",
+ expr_as_string (size_binop (PLUS_EXPR, size, size_one_node),
+ TFF_PLAIN_IDENTIFIER));
+ fprintf (stream, "\n");
+
+ for (ix = 0, inits = TREE_OPERAND (DECL_INITIAL (decl), 1);
+ inits; ix++, inits = TREE_CHAIN (inits))
+ fprintf (stream, "%-4d %s\n", ix * elt,
+ expr_as_string (TREE_VALUE (inits), TFF_PLAIN_IDENTIFIER));
+}
+
+static void
+dump_vtable (t, binfo, vtable)
+ tree t;
+ tree binfo;
+ tree vtable;
+{
+ int flags;
+ FILE *stream = dump_begin (TDI_class, &flags);
+
+ if (!stream)
+ return;
+
+ if (!(flags & TDF_SLIM))
{
- static int append = 0;
+ int ctor_vtbl_p = TYPE_BINFO (t) != binfo;
- stream = fopen (name, append++ ? "a" : "w");
- if (!stream)
- error ("could not open dump file `%s'", name);
- return;
+ fprintf (stream, "%s for %s",
+ ctor_vtbl_p ? "Construction vtable" : "Vtable",
+ type_as_string (binfo, TFF_PLAIN_IDENTIFIER));
+ if (ctor_vtbl_p)
+ {
+ if (!TREE_VIA_VIRTUAL (binfo))
+ fprintf (stream, " (0x%lx instance)", (unsigned long)binfo);
+ fprintf (stream, " in %s", type_as_string (t, TFF_PLAIN_IDENTIFIER));
+ }
+ fprintf (stream, "\n");
+ dump_array (stream, vtable);
+ fprintf (stream, "\n");
}
- fprintf (stream, "%s\n",
- type_as_string (t, TFF_PLAIN_IDENTIFIER));
- dump_class_hierarchy_r (stream, t, TYPE_BINFO (t), 0);
- fprintf (stream, "\n");
- if (name)
- fclose (stream);
+
+ dump_end (TDI_class, stream);
+}
+
+static void
+dump_vtt (t, vtt)
+ tree t;
+ tree vtt;
+{
+ int flags;
+ FILE *stream = dump_begin (TDI_class, &flags);
+
+ if (!stream)
+ return;
+
+ if (!(flags & TDF_SLIM))
+ {
+ fprintf (stream, "VTT for %s\n",
+ type_as_string (t, TFF_PLAIN_IDENTIFIER));
+ dump_array (stream, vtt);
+ fprintf (stream, "\n");
+ }
+
+ dump_end (TDI_class, stream);
}
/* Virtual function table initialization. */
@@ -6786,6 +7138,7 @@ finish_vtbls (t)
{
tree list;
tree vbase;
+ int i;
/* Under the new ABI, we lay out the primary and secondary
vtables in one contiguous vtable. The primary vtable is
@@ -6811,6 +7164,18 @@ finish_vtbls (t)
TYPE_BINFO (t), t, list);
}
+ /* Fill in BINFO_VPTR_FIELD in the immediate binfos for our virtual
+ base classes, for the benefit of the debugging backends. */
+ for (i = 0; i < BINFO_N_BASETYPES (TYPE_BINFO (t)); ++i)
+ {
+ tree base = BINFO_BASETYPE (TYPE_BINFO (t), i);
+ if (TREE_VIA_VIRTUAL (base))
+ {
+ tree vbase = binfo_for_vbase (BINFO_TYPE (base), t);
+ BINFO_VPTR_FIELD (base) = BINFO_VPTR_FIELD (vbase);
+ }
+ }
+
if (TYPE_BINFO_VTABLE (t))
initialize_vtable (TYPE_BINFO (t), TREE_VALUE (list));
}
@@ -6854,6 +7219,7 @@ initialize_vtable (binfo, inits)
layout_vtable_decl (binfo, list_length (inits));
decl = get_vtbl_decl_for_binfo (binfo);
initialize_array (decl, inits);
+ dump_vtable (BINFO_TYPE (binfo), binfo, decl);
}
/* Initialize DECL (a declaration for a namespace-scope array) with
@@ -6894,10 +7260,6 @@ build_vtt (t)
tree vtt;
tree index;
- /* Under the old ABI, we don't use VTTs. */
- if (!flag_new_abi)
- return;
-
/* Build up the initializers for the VTT. */
inits = NULL_TREE;
index = size_zero_node;
@@ -6908,41 +7270,67 @@ build_vtt (t)
return;
/* Figure out the type of the VTT. */
- type = build_index_type (size_int (list_length (inits)));
+ type = build_index_type (size_int (list_length (inits) - 1));
type = build_cplus_array_type (const_ptr_type_node, type);
/* Now, build the VTT object itself. */
vtt = build_vtable (t, get_vtt_name (t), type);
pushdecl_top_level (vtt);
initialize_array (vtt, inits);
+
+ dump_vtt (t, vtt);
}
-/* The type corresponding to BINFO is a base class of T, but BINFO is
- in the base class hierarchy of a class derived from T. Return the
- base, in T's hierarchy, that corresponds to BINFO. */
+/* The type corresponding to BASE_BINFO is a base of the type of BINFO, but
+ from within some heirarchy which is inherited from the type of BINFO.
+ Return BASE_BINFO's equivalent binfo from the hierarchy dominated by
+ BINFO. */
static tree
-get_matching_base (binfo, t)
+get_original_base (base_binfo, binfo)
+ tree base_binfo;
tree binfo;
- tree t;
{
tree derived;
- int i;
-
- if (same_type_p (BINFO_TYPE (binfo), t))
+ int ix;
+
+ if (same_type_p (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo)))
return binfo;
+ if (TREE_VIA_VIRTUAL (base_binfo))
+ return binfo_for_vbase (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo));
+ derived = get_original_base (BINFO_INHERITANCE_CHAIN (base_binfo), binfo);
+
+ for (ix = 0; ix != BINFO_N_BASETYPES (derived); ix++)
+ if (same_type_p (BINFO_TYPE (base_binfo),
+ BINFO_TYPE (BINFO_BASETYPE (derived, ix))))
+ return BINFO_BASETYPE (derived, ix);
+ my_friendly_abort (20010223);
+ return NULL;
+}
- if (TREE_VIA_VIRTUAL (binfo))
- return binfo_for_vbase (BINFO_TYPE (binfo), t);
+/* When building a secondary VTT, BINFO_VTABLE is set to a TREE_LIST with
+ PURPOSE the RTTI_BINFO, VALUE the real vtable pointer for this binfo,
+ and CHAIN the vtable pointer for this binfo after construction is
+ complete. VALUE can also be another BINFO, in which case we recurse. */
- derived = get_matching_base (BINFO_INHERITANCE_CHAIN (binfo), t);
- for (i = 0; i < BINFO_N_BASETYPES (derived); ++i)
- if (same_type_p (BINFO_TYPE (BINFO_BASETYPE (derived, i)),
- BINFO_TYPE (binfo)))
- return BINFO_BASETYPE (derived, i);
+static tree
+binfo_ctor_vtable (binfo)
+ tree binfo;
+{
+ tree vt;
- my_friendly_abort (20000628);
- return NULL_TREE;
+ while (1)
+ {
+ vt = BINFO_VTABLE (binfo);
+ if (TREE_CODE (vt) == TREE_LIST)
+ vt = TREE_VALUE (vt);
+ if (TREE_CODE (vt) == TREE_VEC)
+ binfo = vt;
+ else
+ break;
+ }
+
+ return vt;
}
/* Recursively build the VTT-initializer for BINFO (which is in the
@@ -6981,9 +7369,7 @@ build_vtt_inits (binfo, t, inits, index)
}
/* Add the address of the primary vtable for the complete object. */
- init = BINFO_VTABLE (binfo);
- if (TREE_CODE (init) == TREE_LIST)
- init = TREE_VALUE (init);
+ init = binfo_ctor_vtable (binfo);
*inits = build_tree_list (NULL_TREE, init);
inits = &TREE_CHAIN (*inits);
if (top_level_p)
@@ -7120,33 +7506,26 @@ dfs_build_secondary_vptr_vtt_inits (binfo, data)
while (BINFO_PRIMARY_BASE_OF (binfo))
binfo = BINFO_PRIMARY_BASE_OF (binfo);
}
- init = BINFO_VTABLE (binfo);
- if (TREE_CODE (init) == TREE_LIST)
- init = TREE_VALUE (init);
+ init = binfo_ctor_vtable (binfo);
TREE_VALUE (l) = tree_cons (NULL_TREE, init, TREE_VALUE (l));
return NULL_TREE;
}
/* dfs_walk_real predicate for building vtables. DATA is a TREE_LIST,
- TREE_UNSIGNED indicates that a constructor vtable is being built.
- TREE_USED indicates whether marked or unmarked bases should be walked.
- TREE_PURPOSE is the TREE_TYPE that dominates the hierarchy. */
+ VTT_MARKED_BINFO_P indicates whether marked or unmarked bases
+ should be walked. TREE_PURPOSE is the TREE_TYPE that dominates the
+ hierarchy. */
static tree
dfs_ctor_vtable_bases_queue_p (binfo, data)
tree binfo;
void *data;
{
- if (TREE_VIA_VIRTUAL (binfo) && !BINFO_PRIMARY_P (binfo))
- {
- tree type = TREE_PURPOSE ((tree) data);
+ if (TREE_VIA_VIRTUAL (binfo))
+ /* Get the shared version. */
+ binfo = binfo_for_vbase (BINFO_TYPE (binfo), TREE_PURPOSE ((tree) data));
- /* This is a non-primary virtual base, get the shared version. */
- binfo = binfo_for_vbase (BINFO_TYPE (binfo), type);
- if (VTT_TOP_LEVEL_P ((tree) data) && BINFO_PRIMARY_P (binfo))
- return NULL_TREE;
- }
if (!BINFO_MARKED (binfo) == VTT_MARKED_BINFO_P ((tree) data))
return NULL_TREE;
return binfo;
@@ -7170,7 +7549,8 @@ dfs_fixup_binfo_vtbls (binfo, data)
/* If we scribbled the construction vtable vptr into BINFO, clear it
out now. */
- if (TREE_CODE (BINFO_VTABLE (binfo)) == TREE_LIST
+ if (BINFO_VTABLE (binfo)
+ && TREE_CODE (BINFO_VTABLE (binfo)) == TREE_LIST
&& (TREE_PURPOSE (BINFO_VTABLE (binfo))
== TREE_VALUE ((tree) data)))
BINFO_VTABLE (binfo) = TREE_CHAIN (BINFO_VTABLE (binfo));
@@ -7193,11 +7573,8 @@ build_ctor_vtbl_group (binfo, t)
tree id;
tree vbase;
- /* See if we've already create this construction vtable group. */
- if (flag_new_abi)
- id = mangle_ctor_vtbl_for_type (t, binfo);
- else
- id = get_ctor_vtbl_name (t, binfo);
+ /* See if we've already created this construction vtable group. */
+ id = mangle_ctor_vtbl_for_type (t, binfo);
if (IDENTIFIER_GLOBAL_VALUE (id))
return;
@@ -7229,13 +7606,14 @@ build_ctor_vtbl_group (binfo, t)
inits = TREE_VALUE (list);
/* Figure out the type of the construction vtable. */
- type = build_index_type (size_int (list_length (inits)));
+ type = build_index_type (size_int (list_length (inits) - 1));
type = build_cplus_array_type (vtable_entry_type, type);
TREE_TYPE (vtbl) = type;
/* Initialize the construction vtable. */
pushdecl_top_level (vtbl);
initialize_array (vtbl, inits);
+ dump_vtable (t, binfo, vtbl);
}
/* Add the vtbl initializers for BINFO (and its bases other than
@@ -7263,6 +7641,10 @@ accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, t, inits)
BINFO_TYPE (orig_binfo)),
20000517);
+ /* If it doesn't have a vptr, we don't do anything. */
+ if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
+ return;
+
/* If we're building a construction vtable, we're not interested in
subobjects that don't require construction vtables. */
if (ctor_vtbl_p
@@ -7314,49 +7696,56 @@ dfs_accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, t, l)
if (ctor_vtbl_p
&& TREE_VIA_VIRTUAL (orig_binfo) && BINFO_PRIMARY_P (orig_binfo))
{
- /* In the hierarchy of BINFO_TYPE (RTTI_BINFO), this is a primary
- virtual base. If it is not the same primary in the hierarchy of T,
- we'll need to generate a ctor vtable for it, to place at its
- location in T. If it is the same primary, we still need a VTT
- entry for the vtable, but that must be the base it is a
- primary for within the sub-hierarchy of RTTI_BINFO. */
- tree parent;
- tree best_primary = NULL;
- tree primary_for;
-
- my_friendly_assert (BINFO_PRIMARY_P (binfo), 20010131);
+ /* In the hierarchy of BINFO_TYPE (RTTI_BINFO), this is a
+ primary virtual base. If it is not the same primary in
+ the hierarchy of T, we'll need to generate a ctor vtable
+ for it, to place at its location in T. If it is the same
+ primary, we still need a VTT entry for the vtable, but it
+ should point to the ctor vtable for the base it is a
+ primary for within the sub-hierarchy of RTTI_BINFO.
+
+ There are three possible cases:
+
+ 1) We are in the same place.
+ 2) We are a primary base within a lost primary virtual base of
+ RTTI_BINFO.
+ 3) We are primary to something not a base of RTTI_BINFO. */
+
+ tree b = BINFO_PRIMARY_BASE_OF (binfo);
+ tree last = NULL_TREE;
- for (primary_for = BINFO_PRIMARY_BASE_OF (binfo);
- primary_for;
- primary_for = BINFO_PRIMARY_BASE_OF (primary_for))
- {
- for (parent = primary_for;
- parent;
- parent = BINFO_INHERITANCE_CHAIN (parent))
- {
- if (parent == rtti_binfo)
- {
- best_primary = primary_for;
- break;
- }
- }
- if (!parent)
- break;
- }
- if (best_primary)
- {
- vtbl = BINFO_VTABLE (best_primary);
- if (TREE_CODE (vtbl) == TREE_LIST)
- {
- my_friendly_assert (TREE_PURPOSE (vtbl) == rtti_binfo,
- 20010126);
- vtbl = TREE_VALUE (vtbl);
- }
- }
+ /* First, look through the bases we are primary to for RTTI_BINFO
+ or a virtual base. */
+ for (; b; b = BINFO_PRIMARY_BASE_OF (b))
+ {
+ last = b;
+ if (TREE_VIA_VIRTUAL (b) || b == rtti_binfo)
+ break;
+ }
+ /* If we run out of primary links, keep looking down our
+ inheritance chain; we might be an indirect primary. */
+ if (b == NULL_TREE)
+ for (b = last; b; b = BINFO_INHERITANCE_CHAIN (b))
+ if (TREE_VIA_VIRTUAL (b) || b == rtti_binfo)
+ break;
+
+ /* If we found RTTI_BINFO, this is case 1. If we found a virtual
+ base B and it is a base of RTTI_BINFO, this is case 2. In
+ either case, we share our vtable with LAST, i.e. the
+ derived-most base within B of which we are a primary. */
+ if (b == rtti_binfo
+ || (b && binfo_for_vbase (BINFO_TYPE (b),
+ BINFO_TYPE (rtti_binfo))))
+ /* Just set our BINFO_VTABLE to point to LAST, as we may not have
+ set LAST's BINFO_VTABLE yet. We'll extract the actual vptr in
+ binfo_ctor_vtable after everything's been set up. */
+ vtbl = last;
+
+ /* Otherwise, this is case 3 and we get our own. */
}
else if (!BINFO_NEW_VTABLE_MARKED (orig_binfo, BINFO_TYPE (rtti_binfo)))
return inits;
-
+
if (!vtbl)
{
tree index;
@@ -7381,18 +7770,16 @@ dfs_accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, t, l)
TREE_CONSTANT (vtbl) = 1;
}
- if (!ctor_vtbl_p)
- {
- /* For an ordinary vtable, set BINFO_VTABLE. */
- BINFO_VTABLE (binfo) = vtbl;
- if (BINFO_PRIMARY_P (binfo) && TREE_VIA_VIRTUAL (binfo))
- inits = NULL_TREE;
- }
- else
+ if (ctor_vtbl_p)
/* For a construction vtable, we can't overwrite BINFO_VTABLE.
So, we make a TREE_LIST. Later, dfs_fixup_binfo_vtbls will
straighten this out. */
BINFO_VTABLE (binfo) = tree_cons (rtti_binfo, vtbl, BINFO_VTABLE (binfo));
+ else if (BINFO_PRIMARY_P (binfo) && TREE_VIA_VIRTUAL (binfo))
+ inits = NULL_TREE;
+ else
+ /* For an ordinary vtable, set BINFO_VTABLE. */
+ BINFO_VTABLE (binfo) = vtbl;
return inits;
}
@@ -7428,7 +7815,7 @@ build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo, non_fn_entries_p)
tree rtti_binfo;
int *non_fn_entries_p;
{
- tree v;
+ tree v, b;
tree vfun_inits;
tree vbase;
vtbl_init_data vid;
@@ -7437,6 +7824,7 @@ build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo, non_fn_entries_p)
memset (&vid, 0, sizeof (vid));
vid.binfo = binfo;
vid.derived = t;
+ vid.rtti_binfo = rtti_binfo;
vid.last_init = &vid.inits;
vid.primary_vtbl_p = (binfo == TYPE_BINFO (t));
vid.ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
@@ -7444,7 +7832,7 @@ build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo, non_fn_entries_p)
vid.index = ssize_int (-3);
/* Add entries to the vtable for RTTI. */
- build_rtti_vtbl_entries (binfo, rtti_binfo, &vid);
+ build_rtti_vtbl_entries (binfo, &vid);
/* Create an array for keeping track of the functions we've
processed. When we see multiple functions with the same
@@ -7474,7 +7862,7 @@ build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo, non_fn_entries_p)
tree fn;
tree pfn;
tree init;
-
+
/* Pull the offset for `this', and the function to call, out of
the list. */
delta = BV_DELTA (v);
@@ -7485,7 +7873,7 @@ build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo, non_fn_entries_p)
my_friendly_assert (vcall_index != NULL_TREE, 20000621);
}
else
- vcall_index = NULL_TREE;
+ vcall_index = NULL_TREE;
fn = BV_FN (v);
my_friendly_assert (TREE_CODE (delta) == INTEGER_CST, 19990727);
@@ -7501,11 +7889,55 @@ build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo, non_fn_entries_p)
pfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
/* The address of a function can't change. */
TREE_CONSTANT (pfn) = 1;
+
/* Enter it in the vtable. */
- init = build_vtable_entry (delta, vcall_index, pfn,
- BV_GENERATE_THUNK_WITH_VTABLE_P (v));
+ init = build_vtable_entry (delta, vcall_index, pfn);
+
+ /* If the only definition of this function signature along our
+ primary base chain is from a lost primary, this vtable slot will
+ never be used, so just zero it out. This is important to avoid
+ requiring extra thunks which cannot be generated with the function.
+
+ We could also handle this in update_vtable_entry_for_fn; doing it
+ here means we zero out unused slots in ctor vtables as well,
+ rather than filling them with erroneous values (though harmless,
+ apart from relocation costs). */
+ if (fn != abort_fndecl)
+ for (b = binfo; ; b = get_primary_binfo (b))
+ {
+ /* We found a defn before a lost primary; go ahead as normal. */
+ if (look_for_overrides_here (BINFO_TYPE (b), fn))
+ break;
+
+ /* The nearest definition is from a lost primary; clear the
+ slot. */
+ if (BINFO_LOST_PRIMARY_P (b))
+ {
+ init = size_zero_node;
+ break;
+ }
+ }
+
/* And add it to the chain of initializers. */
- vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
+ if (TARGET_VTABLE_USES_DESCRIPTORS)
+ {
+ int i;
+ if (init == size_zero_node)
+ for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
+ vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
+ else
+ for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
+ {
+ tree fdesc = build (FDESC_EXPR, vfunc_ptr_type_node,
+ TREE_OPERAND (init, 0),
+ build_int_2 (i, 0));
+ TREE_CONSTANT (fdesc) = 1;
+
+ vfun_inits = tree_cons (NULL_TREE, fdesc, vfun_inits);
+ }
+ }
+ else
+ vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
}
/* The initializers for virtual functions were built up in reverse
@@ -7519,7 +7951,7 @@ build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo, non_fn_entries_p)
return chainon (vid.inits, vfun_inits);
}
-/* Sets vid->inits to be the initializers for the vbase and vcall
+/* Adds to vid->inits the initializers for the vbase and vcall
offsets in BINFO, which is in the hierarchy dominated by T. */
static void
@@ -7553,6 +7985,7 @@ build_vbase_offset_vtbl_entries (binfo, vid)
{
tree vbase;
tree t;
+ tree non_primary_binfo;
/* Under the old ABI, pointers to virtual bases are stored in each
object. */
@@ -7565,6 +7998,30 @@ build_vbase_offset_vtbl_entries (binfo, vid)
return;
t = vid->derived;
+
+ /* We might be a primary base class. Go up the inheritance hierarchy
+ until we find the most derived class of which we are a primary base:
+ it is the offset of that which we need to use. */
+ non_primary_binfo = binfo;
+ while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
+ {
+ tree b;
+
+ /* If we have reached a virtual base, then it must be a primary
+ base (possibly multi-level) of vid->binfo, or we wouldn't
+ have called build_vcall_and_vbase_vtbl_entries for it. But it
+ might be a lost primary, so just skip down to vid->binfo. */
+ if (TREE_VIA_VIRTUAL (non_primary_binfo))
+ {
+ non_primary_binfo = vid->binfo;
+ break;
+ }
+
+ b = BINFO_INHERITANCE_CHAIN (non_primary_binfo);
+ if (get_primary_binfo (b) != non_primary_binfo)
+ break;
+ non_primary_binfo = b;
+ }
/* Go through the virtual bases, adding the offsets. */
for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
@@ -7616,7 +8073,8 @@ build_vbase_offset_vtbl_entries (binfo, vid)
The vbase offsets go in reverse inheritance-graph order, and
we are walking in inheritance graph order so these end up in
the right order. */
- delta = size_diffop (BINFO_OFFSET (b), BINFO_OFFSET (binfo));
+ delta = size_diffop (BINFO_OFFSET (b), BINFO_OFFSET (non_primary_binfo));
+
*vid->last_init
= build_tree_list (NULL_TREE,
fold (build1 (NOP_EXPR,
@@ -7627,8 +8085,8 @@ build_vbase_offset_vtbl_entries (binfo, vid)
}
/* Adds the initializers for the vcall offset entries in the vtable
- for BINFO (which is part of the class hierarchy dominated by T) to
- VID->INITS. */
+ for BINFO (which is part of the class hierarchy dominated by VID->DERIVED)
+ to VID->INITS. */
static void
build_vcall_offset_vtbl_entries (binfo, vid)
@@ -7648,22 +8106,20 @@ build_vcall_offset_vtbl_entries (binfo, vid)
vtable. For example:
class A { virtual void f (); };
- class B : virtual public A { };
- class C: virtual public A, public B {};
-
- Now imagine:
-
- B* b = new C;
- b->f();
-
- The location of `A' is not at a fixed offset relative to `B'; the
- offset depends on the complete object derived from `B'. So,
- `B' vtable contains an entry for `f' that indicates by what
- amount the `this' pointer for `B' needs to be adjusted to arrive
- at `A'.
+ class B1 : virtual public A { virtual void f (); };
+ class B2 : virtual public A { virtual void f (); };
+ class C: public B1, public B2 { virtual void f (); };
+
+ A C object has a primary base of B1, which has a primary base of A. A
+ C also has a secondary base of B2, which no longer has a primary base
+ of A. So the B2-in-C construction vtable needs a secondary vtable for
+ A, which will adjust the A* to a B2* to call f. We have no way of
+ knowing what (or even whether) this offset will be when we define B2,
+ so we store this "vcall offset" in the A sub-vtable and look it up in
+ a "virtual thunk" for B2::f.
We need entries for all the functions in our primary vtable and
- in our non-virtual bases vtables. */
+ in our non-virtual bases' secondary vtables. */
vid->vbase = binfo;
/* Now, walk through the non-virtual bases, adding vcall offsets. */
add_vcall_offset_vtbl_entries_r (binfo, vid);
@@ -7680,7 +8136,9 @@ add_vcall_offset_vtbl_entries_r (binfo, vid)
tree primary_binfo;
/* Don't walk into virtual bases -- except, of course, for the
- virtual base for which we are building vcall offsets. */
+ virtual base for which we are building vcall offsets. Any
+ primary virtual base will have already had its offsets generated
+ through the recursion in build_vcall_and_vbase_vtbl_entries. */
if (TREE_VIA_VIRTUAL (binfo) && vid->vbase != binfo)
return;
@@ -7714,27 +8172,30 @@ add_vcall_offset_vtbl_entries_1 (binfo, vid)
tree base_virtuals;
tree orig_virtuals;
tree binfo_inits;
- /* If BINFO is a primary base, this is the least derived class of
- BINFO that is not a primary base. */
+ /* If BINFO is a primary base, the most derived class which has BINFO as
+ a primary base; otherwise, just BINFO. */
tree non_primary_binfo;
binfo_inits = NULL_TREE;
- /* We might be a primary base class. Go up the inheritance
- hierarchy until we find the class of which we are a primary base:
+ /* We might be a primary base class. Go up the inheritance hierarchy
+ until we find the most derived class of which we are a primary base:
it is the BINFO_VIRTUALS there that we need to consider. */
non_primary_binfo = binfo;
while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
{
tree b;
- /* If we have reached a virtual base, then it must be the
- virtual base for which we are building vcall offsets. In
- turn, the virtual base must be a (possibly indirect) primary
- base of the class that we are initializing, or we wouldn't
- care about its vtable offsets. */
+ /* If we have reached a virtual base, then it must be vid->vbase,
+ because we ignore other virtual bases in
+ add_vcall_offset_vtbl_entries_r. In turn, it must be a primary
+ base (possibly multi-level) of vid->binfo, or we wouldn't
+ have called build_vcall_and_vbase_vtbl_entries for it. But it
+ might be a lost primary, so just skip down to vid->binfo. */
if (TREE_VIA_VIRTUAL (non_primary_binfo))
{
+ if (non_primary_binfo != vid->vbase)
+ abort ();
non_primary_binfo = vid->binfo;
break;
}
@@ -7745,6 +8206,12 @@ add_vcall_offset_vtbl_entries_1 (binfo, vid)
non_primary_binfo = b;
}
+ if (vid->ctor_vtbl_p)
+ /* For a ctor vtable we need the equivalent binfo within the hierarchy
+ where rtti_binfo is the most derived type. */
+ non_primary_binfo = get_original_base
+ (non_primary_binfo, TYPE_BINFO (BINFO_TYPE (vid->rtti_binfo)));
+
/* Make entries for the rest of the virtuals. */
for (base_virtuals = BINFO_VIRTUALS (binfo),
derived_virtuals = BINFO_VIRTUALS (non_primary_binfo),
@@ -7759,15 +8226,15 @@ add_vcall_offset_vtbl_entries_1 (binfo, vid)
tree base;
tree base_binfo;
size_t i;
+ tree vcall_offset;
/* Find the declaration that originally caused this function to
- be present. */
+ be present in BINFO_TYPE (binfo). */
orig_fn = BV_FN (orig_virtuals);
- /* We do not need an entry if this function is declared in a
- virtual base (or one of its virtual bases), and not
- overridden in the section of the hierarchy dominated by the
- virtual base for which we are building vcall offsets. */
+ /* When processing BINFO, we only want to generate vcall slots for
+ function slots introduced in BINFO. So don't try to generate
+ one if the function isn't even defined in BINFO. */
if (!same_type_p (DECL_CONTEXT (orig_fn), BINFO_TYPE (binfo)))
continue;
@@ -7783,33 +8250,45 @@ add_vcall_offset_vtbl_entries_1 (binfo, vid)
tree derived_entry;
derived_entry = VARRAY_TREE (vid->fns, i);
- if (same_signature_p (BV_FN (derived_entry), fn))
+ if (same_signature_p (BV_FN (derived_entry), fn)
+ /* We only use one vcall offset for virtual destructors,
+ even though there are two virtual table entries. */
+ || (DECL_DESTRUCTOR_P (BV_FN (derived_entry))
+ && DECL_DESTRUCTOR_P (fn)))
{
- BV_VCALL_INDEX (derived_virtuals)
- = BV_VCALL_INDEX (derived_entry);
+ if (!vid->ctor_vtbl_p)
+ BV_VCALL_INDEX (derived_virtuals)
+ = BV_VCALL_INDEX (derived_entry);
break;
}
}
if (i != VARRAY_ACTIVE_SIZE (vid->fns))
continue;
- /* The FN comes from BASE. So, we must calculate the adjustment
- from the virtual base that derived from BINFO to BASE. */
+ /* The FN comes from BASE. So, we must calculate the adjustment from
+ vid->vbase to BASE. We can just look for BASE in the complete
+ object because we are converting from a virtual base, so if there
+ were multiple copies, there would not be a unique final overrider
+ and vid->derived would be ill-formed. */
base = DECL_CONTEXT (fn);
base_binfo = get_binfo (base, vid->derived, /*protect=*/0);
/* Compute the vcall offset. */
- *vid->last_init
- = (build_tree_list
- (NULL_TREE,
- fold (build1 (NOP_EXPR, vtable_entry_type,
- size_diffop (BINFO_OFFSET (base_binfo),
- BINFO_OFFSET (vid->vbase))))));
+ /* As mentioned above, the vbase we're working on is a primary base of
+ vid->binfo. But it might be a lost primary, so its BINFO_OFFSET
+ might be wrong, so we just use the BINFO_OFFSET from vid->binfo. */
+ vcall_offset = BINFO_OFFSET (vid->binfo);
+ vcall_offset = size_diffop (BINFO_OFFSET (base_binfo),
+ vcall_offset);
+ vcall_offset = fold (build1 (NOP_EXPR, vtable_entry_type,
+ vcall_offset));
+
+ *vid->last_init = build_tree_list (NULL_TREE, vcall_offset);
vid->last_init = &TREE_CHAIN (*vid->last_init);
/* Keep track of the vtable index where this vcall offset can be
found. For a construction vtable, we already made this
- annotation when we build the original vtable. */
+ annotation when we built the original vtable. */
if (!vid->ctor_vtbl_p)
BV_VCALL_INDEX (derived_virtuals) = vid->index;
@@ -7824,12 +8303,11 @@ add_vcall_offset_vtbl_entries_1 (binfo, vid)
/* Return vtbl initializers for the RTTI entries coresponding to the
BINFO's vtable. The RTTI entries should indicate the object given
- by RTTI_BINFO. */
+ by VID->rtti_binfo. */
static void
-build_rtti_vtbl_entries (binfo, rtti_binfo, vid)
+build_rtti_vtbl_entries (binfo, vid)
tree binfo;
- tree rtti_binfo;
vtbl_init_data *vid;
{
tree b;
@@ -7840,7 +8318,7 @@ build_rtti_vtbl_entries (binfo, rtti_binfo, vid)
tree init;
basetype = BINFO_TYPE (binfo);
- t = BINFO_TYPE (rtti_binfo);
+ t = BINFO_TYPE (vid->rtti_binfo);
/* For a COM object there is no RTTI entry. */
if (CLASSTYPE_COM_INTERFACE (basetype))
@@ -7858,37 +8336,18 @@ build_rtti_vtbl_entries (binfo, rtti_binfo, vid)
my_friendly_assert (BINFO_PRIMARY_BASE_OF (primary_base) == b, 20010127);
b = primary_base;
}
- offset = size_diffop (BINFO_OFFSET (rtti_binfo), BINFO_OFFSET (b));
+ offset = size_diffop (BINFO_OFFSET (vid->rtti_binfo), BINFO_OFFSET (b));
- /* The second entry is, in the case of the new ABI, the address of
- the typeinfo object, or, in the case of the old ABI, a function
- which returns a typeinfo object. */
- if (new_abi_rtti_p ())
- {
- if (flag_rtti)
- decl = build_unary_op (ADDR_EXPR, get_tinfo_decl (t), 0);
- else
- decl = integer_zero_node;
-
- /* Convert the declaration to a type that can be stored in the
- vtable. */
- init = build1 (NOP_EXPR, vfunc_ptr_type_node, decl);
- TREE_CONSTANT (init) = 1;
- }
+ /* The second entry is the address of the typeinfo object. */
+ if (flag_rtti)
+ decl = build_unary_op (ADDR_EXPR, get_tinfo_decl (t), 0);
else
- {
- if (flag_rtti)
- decl = get_tinfo_decl (t);
- else
- decl = abort_fndecl;
-
- /* Convert the declaration to a type that can be stored in the
- vtable. */
- init = build1 (ADDR_EXPR, vfunc_ptr_type_node, decl);
- TREE_CONSTANT (init) = 1;
- init = build_vtable_entry (offset, NULL_TREE, init,
- /*generate_with_vtable_p=*/0);
- }
+ decl = integer_zero_node;
+
+ /* Convert the declaration to a type that can be stored in the
+ vtable. */
+ init = build1 (NOP_EXPR, vfunc_ptr_type_node, decl);
+ TREE_CONSTANT (init) = 1;
*vid->last_init = build_tree_list (NULL_TREE, init);
vid->last_init = &TREE_CHAIN (*vid->last_init);
@@ -7907,18 +8366,17 @@ build_rtti_vtbl_entries (binfo, rtti_binfo, vid)
/* Build an entry in the virtual function table. DELTA is the offset
for the `this' pointer. VCALL_INDEX is the vtable index containing
- the vcall offset; zero if none. ENTRY is the virtual function
+ the vcall offset; NULL_TREE if none. ENTRY is the virtual function
table entry itself. It's TREE_TYPE must be VFUNC_PTR_TYPE_NODE,
but it may not actually be a virtual function table pointer. (For
example, it might be the address of the RTTI object, under the new
ABI.) */
static tree
-build_vtable_entry (delta, vcall_index, entry, generate_with_vtable_p)
+build_vtable_entry (delta, vcall_index, entry)
tree delta;
tree vcall_index;
tree entry;
- int generate_with_vtable_p;
{
if (flag_vtable_thunks)
{
@@ -7929,8 +8387,7 @@ build_vtable_entry (delta, vcall_index, entry, generate_with_vtable_p)
&& fn != abort_fndecl
&& !DECL_TINFO_FN_P (fn))
{
- entry = make_thunk (entry, delta, vcall_index,
- generate_with_vtable_p);
+ entry = make_thunk (entry, delta, vcall_index);
entry = build1 (ADDR_EXPR, vtable_entry_type, entry);
TREE_READONLY (entry) = 1;
TREE_CONSTANT (entry) = 1;