#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "cp-tree.h"
#include "flags.h"
#include "rtl.h"
#include "output.h"
#include "toplev.h"
#include "target.h"
#include "convert.h"
#include "tree-iterator.h"
#include "cgraph.h"
#include "tree-dump.h"
int current_class_depth;
typedef struct class_stack_node {
tree name;
tree type;
tree access;
splay_tree names_used;
size_t hidden;
}* class_stack_node_t;
typedef struct vtbl_init_data_s
{
tree binfo;
tree derived;
tree rtti_binfo;
tree inits;
tree* last_init;
tree vbase;
VEC(tree,gc) *fns;
tree index;
int primary_vtbl_p;
int ctor_vtbl_p;
bool generate_vcall_entries;
} vtbl_init_data;
typedef int (*subobject_offset_fn) (tree, tree, splay_tree);
static int current_class_stack_size;
static class_stack_node_t current_class_stack;
static GTY (()) tree sizeof_biggest_empty_class;
VEC(tree,gc) *local_classes;
static tree get_vfield_name (tree);
static void finish_struct_anon (tree);
static tree get_vtable_name (tree);
static tree get_basefndecls (tree, tree);
static int build_primary_vtable (tree, tree);
static int build_secondary_vtable (tree);
static void finish_vtbls (tree);
static void modify_vtable_entry (tree, tree, tree, tree, tree *);
static void finish_struct_bits (tree);
static int alter_access (tree, tree, tree);
static void handle_using_decl (tree, tree);
static tree dfs_modify_vtables (tree, void *);
static tree modify_all_vtables (tree, tree);
static void determine_primary_bases (tree);
static void finish_struct_methods (tree);
static void maybe_warn_about_overly_private_class (tree);
static int method_name_cmp (const void *, const void *);
static int resort_method_name_cmp (const void *, const void *);
static void add_implicitly_declared_members (tree, int, int);
static tree fixed_type_or_null (tree, int *, int *);
static tree build_simple_base_path (tree expr, tree binfo);
static tree build_vtbl_ref_1 (tree, tree);
static tree build_vtbl_initializer (tree, tree, tree, tree, int *);
static int count_fields (tree);
static int add_fields_to_record_type (tree, struct sorted_fields_type*, int);
static void check_bitfield_decl (tree);
static void check_field_decl (tree, tree, int *, int *, int *);
static void check_field_decls (tree, tree *, int *, int *);
static tree *build_base_field (record_layout_info, tree, splay_tree, tree *);
static void build_base_fields (record_layout_info, splay_tree, tree *);
static void check_methods (tree);
static void remove_zero_width_bit_fields (tree);
static void check_bases (tree, int *, int *);
static void check_bases_and_members (tree);
static tree create_vtable_ptr (tree, tree *);
static void include_empty_classes (record_layout_info);
static void layout_class_type (tree, tree *);
static void fixup_pending_inline (tree);
static void fixup_inline_methods (tree);
static void propagate_binfo_offsets (tree, tree);
static void layout_virtual_bases (record_layout_info, splay_tree);
static void build_vbase_offset_vtbl_entries (tree, vtbl_init_data *);
static void add_vcall_offset_vtbl_entries_r (tree, vtbl_init_data *);
static void add_vcall_offset_vtbl_entries_1 (tree, vtbl_init_data *);
static void build_vcall_offset_vtbl_entries (tree, vtbl_init_data *);
static void add_vcall_offset (tree, tree, vtbl_init_data *);
static void layout_vtable_decl (tree, int);
static tree dfs_find_final_overrider_pre (tree, void *);
static tree dfs_find_final_overrider_post (tree, void *);
static tree find_final_overrider (tree, tree, tree);
static int make_new_vtable (tree, tree);
static tree get_primary_binfo (tree);
static int maybe_indent_hierarchy (FILE *, int, int);
static tree dump_class_hierarchy_r (FILE *, int, tree, tree, int);
static void dump_class_hierarchy (tree);
static void dump_class_hierarchy_1 (FILE *, int, tree);
static void dump_array (FILE *, tree);
static void dump_vtable (tree, tree, tree);
static void dump_vtt (tree, tree);
static void dump_thunk (FILE *, int, tree);
static tree build_vtable (tree, tree, tree);
static void initialize_vtable (tree, tree);
static void layout_nonempty_base_or_field (record_layout_info,
tree, tree, splay_tree);
static tree end_of_class (tree, int);
static bool layout_empty_base (tree, tree, splay_tree);
static void accumulate_vtbl_inits (tree, tree, tree, tree, tree);
static tree dfs_accumulate_vtbl_inits (tree, tree, tree, tree,
tree);
static void build_rtti_vtbl_entries (tree, vtbl_init_data *);
static void build_vcall_and_vbase_vtbl_entries (tree, vtbl_init_data *);
static void clone_constructors_and_destructors (tree);
static tree build_clone (tree, tree);
static void update_vtable_entry_for_fn (tree, tree, tree, tree *, unsigned);
static void build_ctor_vtbl_group (tree, tree);
static void build_vtt (tree);
static tree binfo_ctor_vtable (tree);
static tree *build_vtt_inits (tree, tree, tree *, tree *);
static tree dfs_build_secondary_vptr_vtt_inits (tree, void *);
static tree dfs_fixup_binfo_vtbls (tree, void *);
static int record_subobject_offset (tree, tree, splay_tree);
static int check_subobject_offset (tree, tree, splay_tree);
static int walk_subobject_offsets (tree, subobject_offset_fn,
tree, splay_tree, tree, int);
static void record_subobject_offsets (tree, tree, splay_tree, bool);
static int layout_conflict_p (tree, tree, splay_tree, int);
static int splay_tree_compare_integer_csts (splay_tree_key k1,
splay_tree_key k2);
static void warn_about_ambiguous_bases (tree);
static bool type_requires_array_cookie (tree);
static bool contains_empty_class_p (tree);
static bool base_derived_from (tree, tree);
static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree);
static tree end_of_base (tree);
static tree get_vcall_index (tree, tree);
#ifdef GATHER_STATISTICS
int n_vtables = 0;
int n_vtable_entries = 0;
int n_vtable_searches = 0;
int n_vtable_elems = 0;
int n_convert_harshness = 0;
int n_compute_conversion_costs = 0;
int n_inner_fields_searched = 0;
#endif
tree
build_base_path (enum tree_code code,
tree expr,
tree binfo,
int nonnull)
{
tree v_binfo = NULL_TREE;
tree d_binfo = NULL_TREE;
tree probe;
tree offset;
tree target_type;
tree null_test = NULL;
tree ptr_target_type;
int fixed_type_p;
int want_pointer = TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE;
bool has_empty = false;
bool virtual_access;
if (expr == error_mark_node || binfo == error_mark_node || !binfo)
return error_mark_node;
for (probe = binfo; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
{
d_binfo = probe;
if (is_empty_class (BINFO_TYPE (probe)))
has_empty = true;
if (!v_binfo && BINFO_VIRTUAL_P (probe))
v_binfo = probe;
}
probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
if (want_pointer)
probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
gcc_assert ((code == MINUS_EXPR
&& SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), probe))
|| (code == PLUS_EXPR
&& SAME_BINFO_TYPE_P (BINFO_TYPE (d_binfo), probe)));
if (binfo == d_binfo)
return expr;
if (code == MINUS_EXPR && v_binfo)
{
error ("cannot convert from base %qT to derived type %qT via virtual base %qT",
BINFO_TYPE (binfo), BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo));
return error_mark_node;
}
if (!want_pointer)
expr = build_unary_op (ADDR_EXPR, expr, 0);
offset = BINFO_OFFSET (binfo);
fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo);
virtual_access = (v_binfo && fixed_type_p <= 0);
if (want_pointer && !nonnull)
{
if (!virtual_access && integer_zerop (offset))
{
tree class_type;
class_type = TREE_TYPE (TREE_TYPE (expr));
target_type
= cp_build_qualified_type (target_type,
cp_type_quals (class_type));
return build_nop (build_pointer_type (target_type), expr);
}
null_test = error_mark_node;
}
if (TREE_SIDE_EFFECTS (expr) && (null_test || virtual_access))
expr = save_expr (expr);
if (null_test)
{
tree zero = cp_convert (TREE_TYPE (expr), integer_zero_node);
null_test = fold_build2 (NE_EXPR, boolean_type_node,
expr, zero);
}
if (code == PLUS_EXPR && !virtual_access
&& !has_empty)
{
expr = build_indirect_ref (expr, NULL);
expr = build_simple_base_path (expr, binfo);
if (want_pointer)
expr = build_address (expr);
target_type = TREE_TYPE (expr);
goto out;
}
if (virtual_access)
{
tree v_offset;
if (fixed_type_p < 0 && in_base_initializer)
{
tree t;
t = TREE_TYPE (TYPE_VFIELD (current_class_type));
t = build_pointer_type (t);
v_offset = convert (t, current_vtt_parm);
v_offset = build_indirect_ref (v_offset, NULL);
}
else
v_offset = build_vfield_ref (build_indirect_ref (expr, NULL),
TREE_TYPE (TREE_TYPE (expr)));
v_offset = build2 (PLUS_EXPR, TREE_TYPE (v_offset),
v_offset, BINFO_VPTR_FIELD (v_binfo));
v_offset = build1 (NOP_EXPR,
build_pointer_type (ptrdiff_type_node),
v_offset);
v_offset = build_indirect_ref (v_offset, NULL);
TREE_CONSTANT (v_offset) = 1;
TREE_INVARIANT (v_offset) = 1;
offset = convert_to_integer (ptrdiff_type_node,
size_diffop (offset,
BINFO_OFFSET (v_binfo)));
if (!integer_zerop (offset))
v_offset = build2 (code, ptrdiff_type_node, v_offset, offset);
if (fixed_type_p < 0)
offset = build3 (COND_EXPR, ptrdiff_type_node,
build2 (EQ_EXPR, boolean_type_node,
current_in_charge_parm, integer_zero_node),
v_offset,
convert_to_integer (ptrdiff_type_node,
BINFO_OFFSET (binfo)));
else
offset = v_offset;
}
target_type = cp_build_qualified_type
(target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr))));
ptr_target_type = build_pointer_type (target_type);
if (want_pointer)
target_type = ptr_target_type;
expr = build1 (NOP_EXPR, ptr_target_type, expr);
if (!integer_zerop (offset))
expr = build2 (code, ptr_target_type, expr, offset);
else
null_test = NULL;
if (!want_pointer)
expr = build_indirect_ref (expr, NULL);
out:
if (null_test)
expr = fold_build3 (COND_EXPR, target_type, null_test, expr,
fold_build1 (NOP_EXPR, target_type,
integer_zero_node));
return expr;
}
static tree
build_simple_base_path (tree expr, tree binfo)
{
tree type = BINFO_TYPE (binfo);
tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
tree field;
if (d_binfo == NULL_TREE)
{
tree temp;
gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type);
temp = unary_complex_lvalue (ADDR_EXPR, expr);
if (temp)
expr = build_indirect_ref (temp, NULL);
return expr;
}
expr = build_simple_base_path (expr, d_binfo);
for (field = TYPE_FIELDS (BINFO_TYPE (d_binfo));
field; field = TREE_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL
&& DECL_FIELD_IS_BASE (field)
&& TREE_TYPE (field) == type)
{
int type_quals = cp_type_quals (TREE_TYPE (expr));
expr = build3 (COMPONENT_REF,
cp_build_qualified_type (type, type_quals),
expr, field, NULL_TREE);
expr = fold_if_not_in_template (expr);
if (type_quals & TYPE_QUAL_CONST)
TREE_READONLY (expr) = 1;
if (type_quals & TYPE_QUAL_VOLATILE)
TREE_THIS_VOLATILE (expr) = 1;
return expr;
}
gcc_unreachable ();
}
tree
convert_to_base (tree object, tree type, bool check_access, bool nonnull)
{
tree binfo;
tree object_type;
if (TYPE_PTR_P (TREE_TYPE (object)))
{
object_type = TREE_TYPE (TREE_TYPE (object));
type = TREE_TYPE (type);
}
else
object_type = TREE_TYPE (object);
binfo = lookup_base (object_type, type,
check_access ? ba_check : ba_unique,
NULL);
if (!binfo || binfo == error_mark_node)
return error_mark_node;
return build_base_path (PLUS_EXPR, object, binfo, nonnull);
}
tree
convert_to_base_statically (tree expr, tree base)
{
tree expr_type;
expr_type = TREE_TYPE (expr);
if (!SAME_BINFO_TYPE_P (BINFO_TYPE (base), expr_type))
{
tree pointer_type;
pointer_type = build_pointer_type (expr_type);
expr = build_unary_op (ADDR_EXPR, expr, 1);
if (!integer_zerop (BINFO_OFFSET (base)))
expr = build2 (PLUS_EXPR, pointer_type, expr,
build_nop (pointer_type, BINFO_OFFSET (base)));
expr = build_nop (build_pointer_type (BINFO_TYPE (base)), expr);
expr = build1 (INDIRECT_REF, BINFO_TYPE (base), expr);
}
return expr;
}
tree
build_vfield_ref (tree datum, tree type)
{
tree vfield, vcontext;
if (datum == error_mark_node)
return error_mark_node;
if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (datum), type))
datum = convert_to_base (datum, type, false,
true);
vfield = TYPE_VFIELD (type);
vcontext = DECL_CONTEXT (vfield);
while (!same_type_ignoring_top_level_qualifiers_p (vcontext, type))
{
datum = build_simple_base_path (datum, CLASSTYPE_PRIMARY_BINFO (type));
type = TREE_TYPE (datum);
}
return build3 (COMPONENT_REF, TREE_TYPE (vfield), datum, vfield, NULL_TREE);
}
static tree
build_vtbl_ref_1 (tree instance, tree idx)
{
tree aref;
tree vtbl = NULL_TREE;
int cdtorp = 0;
tree fixed_type = fixed_type_or_null (instance, NULL, &cdtorp);
tree basetype = non_reference (TREE_TYPE (instance));
if (fixed_type && !cdtorp)
{
tree binfo = lookup_base (fixed_type, basetype,
ba_unique | ba_quiet, NULL);
if (binfo)
vtbl = unshare_expr (BINFO_VTABLE (binfo));
}
if (!vtbl)
vtbl = build_vfield_ref (instance, basetype);
assemble_external (vtbl);
#ifdef ADJUST_VTABLE_INDEX
ADJUST_VTABLE_INDEX (idx, vtbl);
#endif
aref = build_array_ref (vtbl, idx);
TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
TREE_INVARIANT (aref) = TREE_CONSTANT (aref);
return aref;
}
tree
build_vtbl_ref (tree instance, tree idx)
{
tree aref = build_vtbl_ref_1 (instance, idx);
return aref;
}
tree
build_vfn_ref (tree instance_ptr, tree idx)
{
tree aref;
aref = build_vtbl_ref_1 (build_indirect_ref (instance_ptr, 0), idx);
if (TARGET_VTABLE_USES_DESCRIPTORS)
aref = build1 (NOP_EXPR, TREE_TYPE (aref),
build_unary_op (ADDR_EXPR, aref, 1));
aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr, idx);
return aref;
}
tree
build_vfn_ref_using_vtable (tree vtbl, tree idx)
{
tree aref;
vtbl = unshare_expr (vtbl);
assemble_external (vtbl);
#ifdef ADJUST_VTABLE_INDEX
ADJUST_VTABLE_INDEX (idx, vtbl);
#endif
aref = build_array_ref (vtbl, idx);
TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
TREE_INVARIANT (aref) = TREE_CONSTANT (aref);
return aref;
}
static tree
get_vtable_name (tree type)
{
return mangle_vtbl_for_type (type);
}
void
set_linkage_according_to_type (tree type, tree decl)
{
if (no_linkage_check (type, true))
{
TREE_PUBLIC (decl) = 0;
DECL_INTERFACE_KNOWN (decl) = 1;
}
else
TREE_PUBLIC (decl) = 1;
}
static tree
build_vtable (tree class_type, tree name, tree vtable_type)
{
tree decl;
decl = build_lang_decl (VAR_DECL, name, vtable_type);
SET_DECL_ASSEMBLER_NAME (decl, name);
DECL_CONTEXT (decl) = class_type;
DECL_ARTIFICIAL (decl) = 1;
TREE_STATIC (decl) = 1;
TREE_READONLY (decl) = 1;
DECL_VIRTUAL_P (decl) = 1;
DECL_ALIGN (decl) = TARGET_VTABLE_ENTRY_ALIGN;
DECL_VTABLE_OR_VTT_P (decl) = 1;
DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
DECL_ALIGN (decl));
set_linkage_according_to_type (class_type, decl);
DECL_EXTERNAL (decl) = 1;
DECL_NOT_REALLY_EXTERN (decl) = 1;
DECL_IGNORED_P (decl) = 1;
return decl;
}
tree
get_vtable_decl (tree type, int complete)
{
tree decl;
if (CLASSTYPE_VTABLES (type))
return CLASSTYPE_VTABLES (type);
decl = build_vtable (type, get_vtable_name (type), vtbl_type_node);
CLASSTYPE_VTABLES (type) = decl;
if (complete)
{
DECL_EXTERNAL (decl) = 1;
finish_decl (decl, NULL_TREE, NULL_TREE);
}
return decl;
}
static int
build_primary_vtable (tree binfo, tree type)
{
tree decl;
tree virtuals;
decl = get_vtable_decl (type, 0);
if (binfo)
{
if (BINFO_NEW_VTABLE_MARKED (binfo))
return 0;
virtuals = copy_list (BINFO_VIRTUALS (binfo));
TREE_TYPE (decl) = TREE_TYPE (get_vtbl_decl_for_binfo (binfo));
DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (decl));
DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
}
else
{
gcc_assert (TREE_TYPE (decl) == vtbl_type_node);
virtuals = NULL_TREE;
}
#ifdef GATHER_STATISTICS
n_vtables += 1;
n_vtable_elems += list_length (virtuals);
#endif
BINFO_VTABLE (TYPE_BINFO (type)) = decl;
BINFO_VIRTUALS (TYPE_BINFO (type)) = virtuals;
SET_BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (type));
return 1;
}
static int
build_secondary_vtable (tree binfo)
{
if (BINFO_NEW_VTABLE_MARKED (binfo))
return 0;
SET_BINFO_NEW_VTABLE_MARKED (binfo);
BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
BINFO_VTABLE (binfo) = NULL_TREE;
return 1;
}
static int
make_new_vtable (tree t, tree binfo)
{
if (binfo == TYPE_BINFO (t))
return build_primary_vtable (binfo, t);
else
return build_secondary_vtable (binfo);
}
static void
modify_vtable_entry (tree t,
tree binfo,
tree fndecl,
tree delta,
tree *virtuals)
{
tree v;
v = *virtuals;
if (fndecl != BV_FN (v)
|| !tree_int_cst_equal (delta, BV_DELTA (v)))
{
if (make_new_vtable (t, binfo))
{
*virtuals = BINFO_VIRTUALS (binfo);
while (BV_FN (*virtuals) != BV_FN (v))
*virtuals = TREE_CHAIN (*virtuals);
v = *virtuals;
}
BV_DELTA (v) = delta;
BV_VCALL_INDEX (v) = NULL_TREE;
BV_FN (v) = fndecl;
}
}
bool
add_method (tree type, tree method, tree using_decl)
{
unsigned slot;
tree overload;
bool template_conv_p = false;
bool conv_p;
VEC(tree,gc) *method_vec;
bool complete_p;
bool insert_p = false;
tree current_fns;
if (method == error_mark_node)
return false;
complete_p = COMPLETE_TYPE_P (type);
conv_p = DECL_CONV_FN_P (method);
if (conv_p)
template_conv_p = (TREE_CODE (method) == TEMPLATE_DECL
&& DECL_TEMPLATE_CONV_FN_P (method));
method_vec = CLASSTYPE_METHOD_VEC (type);
if (!method_vec)
{
method_vec = VEC_alloc (tree, gc, 8);
VEC_quick_push (tree, method_vec, NULL_TREE);
VEC_quick_push (tree, method_vec, NULL_TREE);
CLASSTYPE_METHOD_VEC (type) = method_vec;
}
grok_special_member_properties (method);
if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (method))
slot = CLASSTYPE_CONSTRUCTOR_SLOT;
else if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (method))
{
slot = CLASSTYPE_DESTRUCTOR_SLOT;
if (TYPE_FOR_JAVA (type))
{
if (!DECL_ARTIFICIAL (method))
error ("Java class %qT cannot have a destructor", type);
else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
error ("Java class %qT cannot have an implicit non-trivial "
"destructor",
type);
}
}
else
{
tree m;
insert_p = true;
for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
VEC_iterate (tree, method_vec, slot, m);
++slot)
{
m = OVL_CURRENT (m);
if (template_conv_p)
{
if (TREE_CODE (m) == TEMPLATE_DECL
&& DECL_TEMPLATE_CONV_FN_P (m))
insert_p = false;
break;
}
if (conv_p && !DECL_CONV_FN_P (m))
break;
if (DECL_NAME (m) == DECL_NAME (method))
{
insert_p = false;
break;
}
if (complete_p
&& !DECL_CONV_FN_P (m)
&& DECL_NAME (m) > DECL_NAME (method))
break;
}
}
current_fns = insert_p ? NULL_TREE : VEC_index (tree, method_vec, slot);
if (processing_template_decl)
;
else
{
tree fns;
for (fns = current_fns; fns; fns = OVL_NEXT (fns))
{
tree fn = OVL_CURRENT (fns);
tree fn_type;
tree method_type;
tree parms1;
tree parms2;
if (TREE_CODE (fn) != TREE_CODE (method))
continue;
fn_type = TREE_TYPE (fn);
method_type = TREE_TYPE (method);
parms1 = TYPE_ARG_TYPES (fn_type);
parms2 = TYPE_ARG_TYPES (method_type);
if (! DECL_STATIC_FUNCTION_P (fn)
&& ! DECL_STATIC_FUNCTION_P (method)
&& (TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms1)))
!= TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms2)))))
continue;
if (TREE_CODE (fn) == TEMPLATE_DECL
&& (!same_type_p (TREE_TYPE (fn_type),
TREE_TYPE (method_type))
|| !comp_template_parms (DECL_TEMPLATE_PARMS (fn),
DECL_TEMPLATE_PARMS (method))))
continue;
if (! DECL_STATIC_FUNCTION_P (fn))
parms1 = TREE_CHAIN (parms1);
if (! DECL_STATIC_FUNCTION_P (method))
parms2 = TREE_CHAIN (parms2);
if (compparms (parms1, parms2)
&& (!DECL_CONV_FN_P (fn)
|| same_type_p (TREE_TYPE (fn_type),
TREE_TYPE (method_type))))
{
if (using_decl)
{
if (DECL_CONTEXT (fn) == type)
return false;
if (DECL_CONTEXT (fn) == DECL_CONTEXT (method))
error ("repeated using declaration %q+D", using_decl);
else
error ("using declaration %q+D conflicts with a previous using declaration",
using_decl);
}
else
{
error ("%q+#D cannot be overloaded", method);
error ("with %q+#D", fn);
}
return false;
}
}
}
if (current_fns && DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (method))
return false;
overload = build_overload (method, current_fns);
if (conv_p)
TYPE_HAS_CONVERSION (type) = 1;
else if (slot >= CLASSTYPE_FIRST_CONVERSION_SLOT && !complete_p)
push_class_level_binding (DECL_NAME (method), overload);
if (insert_p)
{
bool reallocated;
if (complete_p)
reallocated = VEC_reserve_exact (tree, gc, method_vec, 1);
else
reallocated = VEC_reserve (tree, gc, method_vec, 1);
if (reallocated)
CLASSTYPE_METHOD_VEC (type) = method_vec;
if (slot == VEC_length (tree, method_vec))
VEC_quick_push (tree, method_vec, overload);
else
VEC_quick_insert (tree, method_vec, slot, overload);
}
else
VEC_replace (tree, method_vec, slot, overload);
return true;
}
static int
alter_access (tree t, tree fdecl, tree access)
{
tree elem;
if (!DECL_LANG_SPECIFIC (fdecl))
retrofit_lang_decl (fdecl);
gcc_assert (!DECL_DISCRIMINATOR_P (fdecl));
elem = purpose_member (t, DECL_ACCESS (fdecl));
if (elem)
{
if (TREE_VALUE (elem) != access)
{
if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
error ("conflicting access specifications for method"
" %q+D, ignored", TREE_TYPE (fdecl));
else
error ("conflicting access specifications for field %qE, ignored",
DECL_NAME (fdecl));
}
else
{
;
}
}
else
{
perform_or_defer_access_check (TYPE_BINFO (t), fdecl, fdecl);
DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
return 1;
}
return 0;
}
static void
handle_using_decl (tree using_decl, tree t)
{
tree decl = USING_DECL_DECLS (using_decl);
tree name = DECL_NAME (using_decl);
tree access
= TREE_PRIVATE (using_decl) ? access_private_node
: TREE_PROTECTED (using_decl) ? access_protected_node
: access_public_node;
tree flist = NULL_TREE;
tree old_value;
gcc_assert (!processing_template_decl && decl);
old_value = lookup_member (t, name, 0, false);
if (old_value)
{
if (is_overloaded_fn (old_value))
old_value = OVL_CURRENT (old_value);
if (DECL_P (old_value) && DECL_CONTEXT (old_value) == t)
;
else
old_value = NULL_TREE;
}
cp_emit_debug_info_for_using (decl, USING_DECL_SCOPE (using_decl));
if (is_overloaded_fn (decl))
flist = decl;
if (! old_value)
;
else if (is_overloaded_fn (old_value))
{
if (flist)
;
else
{
error ("%q+D invalid in %q#T", using_decl, t);
error (" because of local method %q+#D with same name",
OVL_CURRENT (old_value));
return;
}
}
else if (!DECL_ARTIFICIAL (old_value))
{
error ("%q+D invalid in %q#T", using_decl, t);
error (" because of local member %q+#D with same name", old_value);
return;
}
if (flist)
for (; flist; flist = OVL_NEXT (flist))
{
add_method (t, OVL_CURRENT (flist), using_decl);
alter_access (t, OVL_CURRENT (flist), access);
}
else
alter_access (t, decl, access);
}
static void
check_bases (tree t,
int* cant_have_const_ctor_p,
int* no_const_asn_ref_p)
{
int i;
int seen_non_virtual_nearly_empty_base_p;
tree base_binfo;
tree binfo;
seen_non_virtual_nearly_empty_base_p = 0;
for (binfo = TYPE_BINFO (t), i = 0;
BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
{
tree basetype = TREE_TYPE (base_binfo);
gcc_assert (COMPLETE_TYPE_P (basetype));
if (!TYPE_POLYMORPHIC_P (basetype))
warning (OPT_Weffc__,
"base class %q#T has a non-virtual destructor", basetype);
if (! TYPE_HAS_CONST_INIT_REF (basetype))
*cant_have_const_ctor_p = 1;
if (TYPE_HAS_ASSIGN_REF (basetype)
&& !TYPE_HAS_CONST_ASSIGN_REF (basetype))
*no_const_asn_ref_p = 1;
if (BINFO_VIRTUAL_P (base_binfo))
;
else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
{
if (seen_non_virtual_nearly_empty_base_p)
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
else
seen_non_virtual_nearly_empty_base_p = 1;
}
else if (!is_empty_class (basetype))
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
|= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
if (CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (basetype)
|| CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (basetype))
CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (t) = 1;
TYPE_HAS_COMPLEX_ASSIGN_REF (t)
|= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
|= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
}
}
static void
determine_primary_bases (tree t)
{
unsigned i;
tree primary = NULL_TREE;
tree type_binfo = TYPE_BINFO (t);
tree base_binfo;
for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
base_binfo = TREE_CHAIN (base_binfo))
{
tree primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (base_binfo));
if (!BINFO_VIRTUAL_P (base_binfo))
{
tree parent = BINFO_INHERITANCE_CHAIN (base_binfo);
tree parent_primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (parent));
if (parent_primary
&& SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
BINFO_TYPE (parent_primary)))
BINFO_PRIMARY_P (base_binfo) = 1;
}
if (primary && BINFO_VIRTUAL_P (primary))
{
tree this_primary = copied_binfo (primary, base_binfo);
if (BINFO_PRIMARY_P (this_primary))
BINFO_LOST_PRIMARY_P (base_binfo) = 1;
else
{
tree delta;
BINFO_PRIMARY_P (this_primary) = 1;
BINFO_INHERITANCE_CHAIN (this_primary) = base_binfo;
delta = size_diffop (convert (ssizetype,
BINFO_OFFSET (base_binfo)),
convert (ssizetype,
BINFO_OFFSET (this_primary)));
propagate_binfo_offsets (this_primary, delta);
}
}
}
for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, base_binfo); i++)
{
tree basetype = BINFO_TYPE (base_binfo);
if (TYPE_CONTAINS_VPTR_P (basetype) && !BINFO_VIRTUAL_P (base_binfo))
{
primary = base_binfo;
goto found;
}
}
for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
base_binfo = TREE_CHAIN (base_binfo))
if (BINFO_VIRTUAL_P (base_binfo)
&& CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (base_binfo)))
{
if (!BINFO_PRIMARY_P (base_binfo))
{
primary = base_binfo;
goto found;
}
else if (!primary)
primary = base_binfo;
}
found:
if (primary)
{
tree basetype = BINFO_TYPE (primary);
CLASSTYPE_PRIMARY_BINFO (t) = primary;
if (BINFO_PRIMARY_P (primary))
BINFO_LOST_PRIMARY_P (BINFO_INHERITANCE_CHAIN (primary)) = 1;
BINFO_PRIMARY_P (primary) = 1;
if (BINFO_VIRTUAL_P (primary))
{
tree delta;
BINFO_INHERITANCE_CHAIN (primary) = type_binfo;
delta = size_diffop (ssize_int (0),
convert (ssizetype, BINFO_OFFSET (primary)));
propagate_binfo_offsets (primary, delta);
}
primary = TYPE_BINFO (basetype);
TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
BINFO_VTABLE (type_binfo) = BINFO_VTABLE (primary);
BINFO_VIRTUALS (type_binfo) = BINFO_VIRTUALS (primary);
}
}
static void
finish_struct_bits (tree t)
{
tree variants;
for (variants = TYPE_NEXT_VARIANT (t);
variants;
variants = TYPE_NEXT_VARIANT (variants))
{
TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variants)
= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (variants) =
CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (t);
CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (variants) =
CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (t);
TYPE_POLYMORPHIC_P (variants) = TYPE_POLYMORPHIC_P (t);
TYPE_BINFO (variants) = TYPE_BINFO (t);
TYPE_VFIELD (variants) = TYPE_VFIELD (t);
TYPE_METHODS (variants) = TYPE_METHODS (t);
TYPE_FIELDS (variants) = TYPE_FIELDS (t);
}
if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) && TYPE_POLYMORPHIC_P (t))
get_pure_virtuals (t);
if (! TYPE_HAS_TRIVIAL_INIT_REF (t) || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
{
tree variants;
DECL_MODE (TYPE_MAIN_DECL (t)) = BLKmode;
for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
{
TYPE_MODE (variants) = BLKmode;
TREE_ADDRESSABLE (variants) = 1;
}
}
}
static void
maybe_warn_about_overly_private_class (tree t)
{
int has_member_fn = 0;
int has_nonprivate_method = 0;
tree fn;
if (!warn_ctor_dtor_privacy
|| (CLASSTYPE_FRIEND_CLASSES (t)
|| DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
|| CLASSTYPE_TEMPLATE_INSTANTIATION (t))
return;
for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
if (!DECL_ARTIFICIAL (fn))
{
if (!TREE_PRIVATE (fn))
{
if (DECL_STATIC_FUNCTION_P (fn))
return;
has_nonprivate_method = 1;
}
else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
has_member_fn = 1;
}
if (!has_nonprivate_method && has_member_fn)
{
unsigned i;
tree binfo = TYPE_BINFO (t);
for (i = 0; i != BINFO_N_BASE_BINFOS (binfo); i++)
if (BINFO_BASE_ACCESS (binfo, i) != access_private_node)
{
has_nonprivate_method = 1;
break;
}
if (!has_nonprivate_method)
{
warning (OPT_Wctor_dtor_privacy,
"all member functions in class %qT are private", t);
return;
}
}
fn = CLASSTYPE_DESTRUCTORS (t);
if (fn && TREE_PRIVATE (fn))
{
warning (OPT_Wctor_dtor_privacy,
"%q#T only defines a private destructor and has no friends",
t);
return;
}
if (TYPE_HAS_CONSTRUCTOR (t)
&& (!CLASSTYPE_LAZY_DEFAULT_CTOR (t)
|| !CLASSTYPE_LAZY_COPY_CTOR (t)))
{
int nonprivate_ctor = 0;
if (!TYPE_HAS_INIT_REF (t))
nonprivate_ctor = 1;
else
for (fn = CLASSTYPE_CONSTRUCTORS (t); fn; fn = OVL_NEXT (fn))
{
tree ctor = OVL_CURRENT (fn);
if (! TREE_PRIVATE (ctor))
{
nonprivate_ctor = 1;
break;
}
}
if (nonprivate_ctor == 0)
{
warning (OPT_Wctor_dtor_privacy,
"%q#T only defines private constructors and has no friends",
t);
return;
}
}
}
static struct {
gt_pointer_operator new_value;
void *cookie;
} resort_data;
static int
method_name_cmp (const void* m1_p, const void* m2_p)
{
const tree *const m1 = (const tree *) m1_p;
const tree *const m2 = (const tree *) m2_p;
if (*m1 == NULL_TREE && *m2 == NULL_TREE)
return 0;
if (*m1 == NULL_TREE)
return -1;
if (*m2 == NULL_TREE)
return 1;
if (DECL_NAME (OVL_CURRENT (*m1)) < DECL_NAME (OVL_CURRENT (*m2)))
return -1;
return 1;
}
static int
resort_method_name_cmp (const void* m1_p, const void* m2_p)
{
const tree *const m1 = (const tree *) m1_p;
const tree *const m2 = (const tree *) m2_p;
if (*m1 == NULL_TREE && *m2 == NULL_TREE)
return 0;
if (*m1 == NULL_TREE)
return -1;
if (*m2 == NULL_TREE)
return 1;
{
tree d1 = DECL_NAME (OVL_CURRENT (*m1));
tree d2 = DECL_NAME (OVL_CURRENT (*m2));
resort_data.new_value (&d1, resort_data.cookie);
resort_data.new_value (&d2, resort_data.cookie);
if (d1 < d2)
return -1;
}
return 1;
}
void
resort_type_method_vec (void* obj,
void* orig_obj ATTRIBUTE_UNUSED ,
gt_pointer_operator new_value,
void* cookie)
{
VEC(tree,gc) *method_vec = (VEC(tree,gc) *) obj;
int len = VEC_length (tree, method_vec);
size_t slot;
tree fn;
for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
VEC_iterate (tree, method_vec, slot, fn);
++slot)
if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
break;
if (len - slot > 1)
{
resort_data.new_value = new_value;
resort_data.cookie = cookie;
qsort (VEC_address (tree, method_vec) + slot, len - slot, sizeof (tree),
resort_method_name_cmp);
}
}
static void
finish_struct_methods (tree t)
{
tree fn_fields;
VEC(tree,gc) *method_vec;
int slot, len;
method_vec = CLASSTYPE_METHOD_VEC (t);
if (!method_vec)
return;
len = VEC_length (tree, method_vec);
for (fn_fields = TYPE_METHODS (t); fn_fields;
fn_fields = TREE_CHAIN (fn_fields))
DECL_IN_AGGR_P (fn_fields) = 0;
maybe_warn_about_overly_private_class (t);
for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
VEC_iterate (tree, method_vec, slot, fn_fields);
++slot)
if (!DECL_CONV_FN_P (OVL_CURRENT (fn_fields)))
break;
if (len - slot > 1)
qsort (VEC_address (tree, method_vec) + slot,
len-slot, sizeof (tree), method_name_cmp);
}
static void
layout_vtable_decl (tree binfo, int n)
{
tree atype;
tree vtable;
int n_entries = n;
if (TARGET_KEXTABI)
n_entries += 1;
atype = build_cplus_array_type (vtable_entry_type,
build_index_type (size_int (n_entries - 1)));
layout_type (atype);
vtable = get_vtbl_decl_for_binfo (binfo);
if (!same_type_p (TREE_TYPE (vtable), atype))
{
TREE_TYPE (vtable) = atype;
DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE;
layout_decl (vtable, 0);
}
}
int
same_signature_p (tree fndecl, tree base_fndecl)
{
if (DECL_DESTRUCTOR_P (base_fndecl) && DECL_DESTRUCTOR_P (fndecl)
&& special_function_p (base_fndecl) == special_function_p (fndecl))
return 1;
if (DECL_DESTRUCTOR_P (base_fndecl) || DECL_DESTRUCTOR_P (fndecl))
return 0;
if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl)
|| (DECL_CONV_FN_P (fndecl)
&& DECL_CONV_FN_P (base_fndecl)
&& same_type_p (DECL_CONV_FN_TYPE (fndecl),
DECL_CONV_FN_TYPE (base_fndecl))))
{
tree types, base_types;
types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
if ((TYPE_QUALS (TREE_TYPE (TREE_VALUE (base_types)))
== TYPE_QUALS (TREE_TYPE (TREE_VALUE (types))))
&& compparms (TREE_CHAIN (base_types), TREE_CHAIN (types)))
return 1;
}
return 0;
}
static bool
base_derived_from (tree derived, tree base)
{
tree probe;
for (probe = base; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
{
if (probe == derived)
return true;
else if (BINFO_VIRTUAL_P (probe))
return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (derived))
!= NULL_TREE);
}
return false;
}
typedef struct find_final_overrider_data_s {
tree fn;
tree declaring_base;
tree candidates;
VEC(tree,heap) *path;
} find_final_overrider_data;
static bool
dfs_find_final_overrider_1 (tree binfo,
find_final_overrider_data *ffod,
unsigned depth)
{
tree method;
if (depth)
{
depth--;
if (dfs_find_final_overrider_1
(VEC_index (tree, ffod->path, depth), ffod, depth))
return true;
}
method = look_for_overrides_here (BINFO_TYPE (binfo), ffod->fn);
if (method)
{
tree *candidate = &ffod->candidates;
while (*candidate)
{
if (base_derived_from (TREE_VALUE (*candidate), binfo))
return true;
if (base_derived_from (binfo, TREE_VALUE (*candidate)))
*candidate = TREE_CHAIN (*candidate);
else
candidate = &TREE_CHAIN (*candidate);
}
ffod->candidates = tree_cons (method, binfo, ffod->candidates);
return true;
}
return false;
}
static tree
dfs_find_final_overrider_pre (tree binfo, void *data)
{
find_final_overrider_data *ffod = (find_final_overrider_data *) data;
if (binfo == ffod->declaring_base)
dfs_find_final_overrider_1 (binfo, ffod, VEC_length (tree, ffod->path));
VEC_safe_push (tree, heap, ffod->path, binfo);
return NULL_TREE;
}
static tree
dfs_find_final_overrider_post (tree binfo ATTRIBUTE_UNUSED, void *data)
{
find_final_overrider_data *ffod = (find_final_overrider_data *) data;
VEC_pop (tree, ffod->path);
return NULL_TREE;
}
static tree
find_final_overrider (tree derived, tree binfo, tree fn)
{
find_final_overrider_data ffod;
if (DECL_THUNK_P (fn))
fn = THUNK_TARGET (fn);
ffod.fn = fn;
ffod.declaring_base = binfo;
ffod.candidates = NULL_TREE;
ffod.path = VEC_alloc (tree, heap, 30);
dfs_walk_all (derived, dfs_find_final_overrider_pre,
dfs_find_final_overrider_post, &ffod);
VEC_free (tree, heap, ffod.path);
if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
return error_mark_node;
return ffod.candidates;
}
static tree
get_vcall_index (tree fn, tree type)
{
VEC(tree_pair_s,gc) *indices = CLASSTYPE_VCALL_INDICES (type);
tree_pair_p p;
unsigned ix;
for (ix = 0; VEC_iterate (tree_pair_s, indices, ix, p); ix++)
if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (p->purpose))
|| same_signature_p (fn, p->purpose))
return p->value;
gcc_unreachable ();
}
static void
update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
unsigned ix)
{
tree b;
tree overrider;
tree delta;
tree virtual_base;
tree first_defn;
tree overrider_fn, overrider_target;
tree target_fn = DECL_THUNK_P (fn) ? THUNK_TARGET (fn) : fn;
tree over_return, base_return;
bool lost = false;
for (b = binfo; ; b = get_primary_binfo (b))
{
gcc_assert (b);
if (look_for_overrides_here (BINFO_TYPE (b), target_fn))
break;
if (BINFO_LOST_PRIMARY_P (b))
lost = true;
}
first_defn = b;
overrider = find_final_overrider (TYPE_BINFO (t), b, target_fn);
if (overrider == error_mark_node)
{
error ("no unique final overrider for %qD in %qT", target_fn, t);
return;
}
overrider_target = overrider_fn = TREE_PURPOSE (overrider);
over_return = TREE_TYPE (TREE_TYPE (overrider_target));
base_return = TREE_TYPE (TREE_TYPE (target_fn));
if (POINTER_TYPE_P (over_return)
&& TREE_CODE (over_return) == TREE_CODE (base_return)
&& CLASS_TYPE_P (TREE_TYPE (over_return))
&& CLASS_TYPE_P (TREE_TYPE (base_return))
&& !DECL_INVALID_OVERRIDER_P (overrider_target))
{
tree fixed_offset, virtual_offset;
over_return = TREE_TYPE (over_return);
base_return = TREE_TYPE (base_return);
if (DECL_THUNK_P (fn))
{
gcc_assert (DECL_RESULT_THUNK_P (fn));
fixed_offset = ssize_int (THUNK_FIXED_OFFSET (fn));
virtual_offset = THUNK_VIRTUAL_OFFSET (fn);
}
else
fixed_offset = virtual_offset = NULL_TREE;
if (virtual_offset)
virtual_offset = binfo_for_vbase (BINFO_TYPE (virtual_offset),
over_return);
else if (!same_type_ignoring_top_level_qualifiers_p
(over_return, base_return))
{
tree thunk_binfo, base_binfo;
for (base_binfo = TYPE_BINFO (base_return),
thunk_binfo = TYPE_BINFO (over_return);
thunk_binfo;
thunk_binfo = TREE_CHAIN (thunk_binfo))
if (SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo),
BINFO_TYPE (base_binfo)))
break;
for (virtual_offset = thunk_binfo;
virtual_offset;
virtual_offset = BINFO_INHERITANCE_CHAIN (virtual_offset))
if (BINFO_VIRTUAL_P (virtual_offset))
break;
if (virtual_offset
|| (thunk_binfo && !BINFO_OFFSET_ZEROP (thunk_binfo)))
{
tree offset = convert (ssizetype, BINFO_OFFSET (thunk_binfo));
if (virtual_offset)
{
offset = size_diffop
(offset, convert
(ssizetype, BINFO_OFFSET (virtual_offset)));
}
if (fixed_offset)
fixed_offset = size_binop (PLUS_EXPR, fixed_offset, offset);
else
fixed_offset = offset;
}
}
if (fixed_offset || virtual_offset)
overrider_fn = make_thunk (overrider_target, 0,
fixed_offset, virtual_offset);
}
else
gcc_assert (!DECL_THUNK_P (fn));
virtual_base = NULL_TREE;
for (; b; b = BINFO_INHERITANCE_CHAIN (b))
{
if (SAME_BINFO_TYPE_P (BINFO_TYPE (b),
BINFO_TYPE (TREE_VALUE (overrider))))
break;
if (BINFO_VIRTUAL_P (b))
{
virtual_base = b;
break;
}
}
if (overrider_fn != overrider_target && !virtual_base)
{
tree probe = first_defn;
while ((probe = get_primary_binfo (probe))
&& (unsigned) list_length (BINFO_VIRTUALS (probe)) > ix)
if (BINFO_VIRTUAL_P (probe))
virtual_base = probe;
if (virtual_base)
goto virtual_covariant;
}
if (virtual_base)
delta = size_diffop (convert (ssizetype, BINFO_OFFSET (virtual_base)),
convert (ssizetype, BINFO_OFFSET (first_defn)));
else if (lost)
delta = size_zero_node;
else
virtual_covariant:
delta = size_diffop (convert (ssizetype,
BINFO_OFFSET (TREE_VALUE (overrider))),
convert (ssizetype, BINFO_OFFSET (binfo)));
modify_vtable_entry (t, binfo, overrider_fn, delta, virtuals);
if (virtual_base)
BV_VCALL_INDEX (*virtuals)
= get_vcall_index (overrider_target, BINFO_TYPE (virtual_base));
else
BV_VCALL_INDEX (*virtuals) = NULL_TREE;
}
static tree
dfs_modify_vtables (tree binfo, void* data)
{
tree t = (tree) data;
tree virtuals;
tree old_virtuals;
unsigned ix;
if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
return dfs_skip_bases;
if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t)
&& !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
return NULL_TREE;
if (BINFO_PRIMARY_P (binfo) && !BINFO_VIRTUAL_P (binfo))
return NULL_TREE;
make_new_vtable (t, binfo);
for (ix = 0, virtuals = BINFO_VIRTUALS (binfo),
old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
virtuals;
ix++, virtuals = TREE_CHAIN (virtuals),
old_virtuals = TREE_CHAIN (old_virtuals))
update_vtable_entry_for_fn (t,
binfo,
BV_FN (old_virtuals),
&virtuals, ix);
return NULL_TREE;
}
static tree
modify_all_vtables (tree t, tree virtuals)
{
tree binfo = TYPE_BINFO (t);
tree *fnsp;
dfs_walk_once (binfo, dfs_modify_vtables, NULL, t);
for (fnsp = &virtuals; *fnsp; )
{
tree fn = TREE_VALUE (*fnsp);
if (!value_member (fn, BINFO_VIRTUALS (binfo))
|| DECL_VINDEX (fn) == error_mark_node)
{
BV_DELTA (*fnsp) = integer_zero_node;
BV_VCALL_INDEX (*fnsp) = NULL_TREE;
fnsp = &TREE_CHAIN (*fnsp);
}
else
*fnsp = TREE_CHAIN (*fnsp);
}
return virtuals;
}
static tree
get_basefndecls (tree name, tree t)
{
tree methods;
tree base_fndecls = NULL_TREE;
int n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t));
int i;
i = lookup_fnfields_1 (t, name);
if (i != -1)
for (methods = VEC_index (tree, CLASSTYPE_METHOD_VEC (t), i);
methods;
methods = OVL_NEXT (methods))
{
tree method = OVL_CURRENT (methods);
if (TREE_CODE (method) == FUNCTION_DECL
&& DECL_VINDEX (method))
base_fndecls = tree_cons (NULL_TREE, method, base_fndecls);
}
if (base_fndecls)
return base_fndecls;
for (i = 0; i < n_baseclasses; i++)
{
tree basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t), i));
base_fndecls = chainon (get_basefndecls (name, basetype),
base_fndecls);
}
return base_fndecls;
}
void
check_for_override (tree decl, tree ctype)
{
if (TREE_CODE (decl) == TEMPLATE_DECL)
return;
if ((DECL_DESTRUCTOR_P (decl)
|| IDENTIFIER_VIRTUAL_P (DECL_NAME (decl))
|| DECL_CONV_FN_P (decl))
&& look_for_overrides (ctype, decl)
&& !DECL_STATIC_FUNCTION_P (decl))
DECL_VINDEX (decl) = decl;
if (DECL_VIRTUAL_P (decl))
{
if (!DECL_VINDEX (decl))
DECL_VINDEX (decl) = error_mark_node;
IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
if (DECL_DLLIMPORT_P (decl))
{
DECL_DLLIMPORT_P (decl) = 0;
DECL_ATTRIBUTES (decl)
= remove_attribute ("dllimport", DECL_ATTRIBUTES (decl));
}
}
}
static void
warn_hidden (tree t)
{
VEC(tree,gc) *method_vec = CLASSTYPE_METHOD_VEC (t);
tree fns;
size_t i;
for (i = CLASSTYPE_FIRST_CONVERSION_SLOT;
VEC_iterate (tree, method_vec, i, fns);
++i)
{
tree fn;
tree name;
tree fndecl;
tree base_fndecls;
tree base_binfo;
tree binfo;
int j;
name = DECL_NAME (OVL_CURRENT (fns));
base_fndecls = NULL_TREE;
for (binfo = TYPE_BINFO (t), j = 0;
BINFO_BASE_ITERATE (binfo, j, base_binfo); j++)
{
tree basetype = BINFO_TYPE (base_binfo);
base_fndecls = chainon (get_basefndecls (name, basetype),
base_fndecls);
}
if (!base_fndecls)
continue;
for (fn = fns; fn; fn = OVL_NEXT (fn))
{
fndecl = OVL_CURRENT (fn);
if (DECL_VINDEX (fndecl))
{
tree *prev = &base_fndecls;
while (*prev)
if (same_signature_p (fndecl, TREE_VALUE (*prev)))
*prev = TREE_CHAIN (*prev);
else
prev = &TREE_CHAIN (*prev);
}
}
while (base_fndecls)
{
warning (0, "%q+D was hidden", TREE_VALUE (base_fndecls));
warning (0, " by %q+D", fns);
base_fndecls = TREE_CHAIN (base_fndecls);
}
}
}
static void
finish_struct_anon (tree t)
{
tree field;
for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
{
if (TREE_STATIC (field))
continue;
if (TREE_CODE (field) != FIELD_DECL)
continue;
if (DECL_NAME (field) == NULL_TREE
&& ANON_AGGR_TYPE_P (TREE_TYPE (field)))
{
tree elt = TYPE_FIELDS (TREE_TYPE (field));
for (; elt; elt = TREE_CHAIN (elt))
{
if (DECL_ARTIFICIAL (elt)
&& (!DECL_IMPLICIT_TYPEDEF_P (elt)
|| TYPE_ANONYMOUS_P (TREE_TYPE (elt))))
continue;
if (TREE_CODE (elt) != FIELD_DECL)
{
pedwarn ("%q+#D invalid; an anonymous union can "
"only have non-static data members", elt);
continue;
}
if (TREE_PRIVATE (elt))
pedwarn ("private member %q+#D in anonymous union", elt);
else if (TREE_PROTECTED (elt))
pedwarn ("protected member %q+#D in anonymous union", elt);
TREE_PRIVATE (elt) = TREE_PRIVATE (field);
TREE_PROTECTED (elt) = TREE_PROTECTED (field);
}
}
}
}
void
maybe_add_class_template_decl_list (tree type, tree t, int friend_p)
{
if (CLASSTYPE_TEMPLATE_INFO (type))
CLASSTYPE_DECL_LIST (type)
= tree_cons (friend_p ? NULL_TREE : type,
t, CLASSTYPE_DECL_LIST (type));
}
static void
add_implicitly_declared_members (tree t,
int cant_have_const_cctor,
int cant_have_const_assignment)
{
if (!CLASSTYPE_DESTRUCTORS (t))
{
CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
{
bool lazy_p = true;
CLASSTYPE_DESTRUCTOR_NONTRIVIAL_BECAUSE_OF_BASE (t) = 1;
if (TYPE_FOR_JAVA (t))
lazy_p = false;
else
{
tree binfo;
tree base_binfo;
int ix;
binfo = TYPE_BINFO (t);
for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
{
tree base_type;
tree dtor;
base_type = BINFO_TYPE (base_binfo);
dtor = CLASSTYPE_DESTRUCTORS (base_type);
if (dtor && DECL_VIRTUAL_P (dtor))
{
lazy_p = false;
break;
}
}
}
if (!lazy_p)
lazily_declare_fn (sfk_destructor, t);
}
}
if (! TYPE_HAS_CONSTRUCTOR (t))
{
TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 1;
CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1;
}
if (! TYPE_HAS_INIT_REF (t) && ! TYPE_FOR_JAVA (t))
{
TYPE_HAS_INIT_REF (t) = 1;
TYPE_HAS_CONST_INIT_REF (t) = !cant_have_const_cctor;
CLASSTYPE_LAZY_COPY_CTOR (t) = 1;
TYPE_HAS_CONSTRUCTOR (t) = 1;
}
if (!TYPE_HAS_ASSIGN_REF (t) && !TYPE_FOR_JAVA (t))
{
TYPE_HAS_ASSIGN_REF (t) = 1;
TYPE_HAS_CONST_ASSIGN_REF (t) = !cant_have_const_assignment;
CLASSTYPE_LAZY_ASSIGNMENT_OP (t) = 1;
}
}
static int
count_fields (tree fields)
{
tree x;
int n_fields = 0;
for (x = fields; x; x = TREE_CHAIN (x))
{
if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
n_fields += count_fields (TYPE_FIELDS (TREE_TYPE (x)));
else
n_fields += 1;
}
return n_fields;
}
static int
add_fields_to_record_type (tree fields, struct sorted_fields_type *field_vec, int idx)
{
tree x;
for (x = fields; x; x = TREE_CHAIN (x))
{
if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
idx = add_fields_to_record_type (TYPE_FIELDS (TREE_TYPE (x)), field_vec, idx);
else
field_vec->elts[idx++] = x;
}
return idx;
}
static void
check_bitfield_decl (tree field)
{
tree type = TREE_TYPE (field);
tree w;
w = DECL_INITIAL (field);
gcc_assert (w != NULL_TREE);
DECL_INITIAL (field) = NULL_TREE;
if (!INTEGRAL_TYPE_P (type))
{
error ("bit-field %q+#D with non-integral type", field);
TREE_TYPE (field) = error_mark_node;
w = error_mark_node;
}
else
{
STRIP_NOPS (w);
w = integral_constant_value (w);
if (TREE_CODE (w) != INTEGER_CST)
{
error ("bit-field %q+D width not an integer constant", field);
w = error_mark_node;
}
else if (tree_int_cst_sgn (w) < 0)
{
error ("negative width in bit-field %q+D", field);
w = error_mark_node;
}
else if (integer_zerop (w) && DECL_NAME (field) != 0)
{
error ("zero width for bit-field %q+D", field);
w = error_mark_node;
}
else if (compare_tree_int (w, TYPE_PRECISION (type)) > 0
&& TREE_CODE (type) != ENUMERAL_TYPE
&& TREE_CODE (type) != BOOLEAN_TYPE)
warning (0, "width of %q+D exceeds its type", field);
else if (TREE_CODE (type) == ENUMERAL_TYPE
&& (0 > compare_tree_int (w,
min_precision (TYPE_MIN_VALUE (type),
TYPE_UNSIGNED (type)))
|| 0 > compare_tree_int (w,
min_precision
(TYPE_MAX_VALUE (type),
TYPE_UNSIGNED (type)))))
warning (0, "%q+D is too small to hold all values of %q#T", field, type);
}
if (w != error_mark_node)
{
DECL_SIZE (field) = convert (bitsizetype, w);
DECL_BIT_FIELD (field) = 1;
}
else
{
DECL_BIT_FIELD (field) = 0;
CLEAR_DECL_C_BIT_FIELD (field);
}
}
static void
check_field_decl (tree field,
tree t,
int* cant_have_const_ctor,
int* no_const_asn_ref,
int* any_default_members)
{
tree type = strip_array_types (TREE_TYPE (field));
if (ANON_UNION_TYPE_P (type))
;
else if (ANON_AGGR_TYPE_P (type))
{
tree fields;
for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
if (TREE_CODE (fields) == FIELD_DECL && !DECL_C_BIT_FIELD (field))
check_field_decl (fields, t, cant_have_const_ctor,
no_const_asn_ref, any_default_members);
}
else if (CLASS_TYPE_P (type))
{
abstract_virtuals_error (field, type);
if (TREE_CODE (t) == UNION_TYPE)
{
if (TYPE_NEEDS_CONSTRUCTING (type))
error ("member %q+#D with constructor not allowed in union",
field);
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
error ("member %q+#D with destructor not allowed in union", field);
if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
error ("member %q+#D with copy assignment operator not allowed in union",
field);
}
else
{
TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
|= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
}
if (!TYPE_HAS_CONST_INIT_REF (type))
*cant_have_const_ctor = 1;
if (!TYPE_HAS_CONST_ASSIGN_REF (type))
*no_const_asn_ref = 1;
}
if (DECL_INITIAL (field) != NULL_TREE)
{
if (TREE_CODE (t) == UNION_TYPE && any_default_members != 0)
error ("multiple fields in union %qT initialized", t);
*any_default_members = 1;
}
}
static void
check_field_decls (tree t, tree *access_decls,
int *cant_have_const_ctor_p,
int *no_const_asn_ref_p)
{
tree *field;
tree *next;
bool has_pointers;
int any_default_members;
int cant_pack = 0;
*access_decls = NULL_TREE;
has_pointers = false;
any_default_members = 0;
for (field = &TYPE_FIELDS (t); *field; field = next)
{
tree x = *field;
tree type = TREE_TYPE (x);
next = &TREE_CHAIN (x);
if (TREE_CODE (x) == USING_DECL)
{
*field = TREE_CHAIN (x);
*access_decls = tree_cons (NULL_TREE, x, *access_decls);
next = field;
continue;
}
if (TREE_CODE (x) == TYPE_DECL
|| TREE_CODE (x) == TEMPLATE_DECL)
continue;
DECL_CONTEXT (x) = t;
DECL_NONLOCAL (x) = 1;
if (TREE_CODE (t) == UNION_TYPE)
{
if (TREE_CODE (x) == VAR_DECL)
{
error ("%q+D may not be static because it is a member of a union", x);
continue;
}
if (TREE_CODE (type) == REFERENCE_TYPE)
{
error ("%q+D may not have reference type %qT because"
" it is a member of a union",
x, type);
continue;
}
}
if (TREE_CODE (type) == FUNCTION_TYPE)
{
error ("field %q+D invalidly declared function type", x);
type = build_pointer_type (type);
TREE_TYPE (x) = type;
}
else if (TREE_CODE (type) == METHOD_TYPE)
{
error ("field %q+D invalidly declared method type", x);
type = build_pointer_type (type);
TREE_TYPE (x) = type;
}
if (type == error_mark_node)
continue;
if (TREE_CODE (x) == CONST_DECL || TREE_CODE (x) == VAR_DECL)
continue;
if (TREE_PRIVATE (x) || TREE_PROTECTED (x))
CLASSTYPE_NON_AGGREGATE (t) = 1;
if (TREE_CODE (type) == REFERENCE_TYPE)
{
CLASSTYPE_NON_POD_P (t) = 1;
if (DECL_INITIAL (x) == NULL_TREE)
SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
if (! TYPE_HAS_CONSTRUCTOR (t) && CLASSTYPE_NON_AGGREGATE (t)
&& extra_warnings)
warning (OPT_Wextra, "non-static reference %q+#D in class without a constructor", x);
}
type = strip_array_types (type);
if (TYPE_PACKED (t))
{
if (!pod_type_p (type) && !TYPE_PACKED (type))
{
warning
(0,
"ignoring packed attribute because of unpacked non-POD field %q+#D",
x);
cant_pack = 1;
}
else if (TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)
DECL_PACKED (x) = 1;
}
if (DECL_C_BIT_FIELD (x) && integer_zerop (DECL_INITIAL (x)))
;
else
{
CLASSTYPE_EMPTY_P (t) = 0;
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
if (CLASS_TYPE_P (type)
&& CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
}
if (TYPE_PTR_P (type)
&& !TYPE_PTRFN_P (type)
&& !TYPE_PTR_TO_MEMBER_P (type))
has_pointers = true;
if (CLASS_TYPE_P (type))
{
if (CLASSTYPE_REF_FIELDS_NEED_INIT (type))
SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (type))
SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
}
if (DECL_MUTABLE_P (x) || TYPE_HAS_MUTABLE_P (type))
CLASSTYPE_HAS_MUTABLE (t) = 1;
if (! pod_type_p (type))
CLASSTYPE_NON_POD_P (t) = 1;
if (! zero_init_p (type))
CLASSTYPE_NON_ZERO_INIT_P (t) = 1;
if (CP_TYPE_CONST_P (type))
{
C_TYPE_FIELDS_READONLY (t) = 1;
if (DECL_INITIAL (x) == NULL_TREE)
SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
if (! TYPE_HAS_CONSTRUCTOR (t) && CLASSTYPE_NON_AGGREGATE (t)
&& extra_warnings)
warning (OPT_Wextra, "non-static const member %q+#D in class without a constructor", x);
}
else if (CLASS_TYPE_P (type))
{
C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type);
SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t,
CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
| CLASSTYPE_READONLY_FIELDS_NEED_INIT (type));
}
if (constructor_name_p (DECL_NAME (x), t) && TYPE_HAS_CONSTRUCTOR (t))
pedwarn ("field %q+#D with same name as class", x);
if (DECL_C_BIT_FIELD (x))
check_bitfield_decl (x);
else
check_field_decl (x, t,
cant_have_const_ctor_p,
no_const_asn_ref_p,
&any_default_members);
}
if (warn_ecpp
&& has_pointers
&& TYPE_HAS_CONSTRUCTOR (t)
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
&& !(TYPE_HAS_INIT_REF (t) && TYPE_HAS_ASSIGN_REF (t)))
{
warning (OPT_Weffc__, "%q#T has pointer data members", t);
if (! TYPE_HAS_INIT_REF (t))
{
warning (OPT_Weffc__,
" but does not override %<%T(const %T&)%>", t, t);
if (!TYPE_HAS_ASSIGN_REF (t))
warning (OPT_Weffc__, " or %<operator=(const %T&)%>", t);
}
else if (! TYPE_HAS_ASSIGN_REF (t))
warning (OPT_Weffc__,
" but does not override %<operator=(const %T&)%>", t);
}
if (cant_pack)
TYPE_PACKED (t) = 0;
finish_struct_anon (t);
*access_decls = nreverse (*access_decls);
}
static int
record_subobject_offset (tree type, tree offset, splay_tree offsets)
{
splay_tree_node n;
if (!is_empty_class (type))
return 0;
n = splay_tree_lookup (offsets, (splay_tree_key) offset);
if (!n)
n = splay_tree_insert (offsets,
(splay_tree_key) offset,
(splay_tree_value) NULL_TREE);
n->value = ((splay_tree_value)
tree_cons (NULL_TREE,
type,
(tree) n->value));
return 0;
}
static int
check_subobject_offset (tree type, tree offset, splay_tree offsets)
{
splay_tree_node n;
tree t;
if (!is_empty_class (type))
return 0;
n = splay_tree_lookup (offsets, (splay_tree_key) offset);
if (!n)
return 0;
for (t = (tree) n->value; t; t = TREE_CHAIN (t))
if (same_type_p (TREE_VALUE (t), type))
return 1;
return 0;
}
static int
walk_subobject_offsets (tree type,
subobject_offset_fn f,
tree offset,
splay_tree offsets,
tree max_offset,
int vbases_p)
{
int r = 0;
tree type_binfo = NULL_TREE;
if (max_offset && INT_CST_LT (max_offset, offset))
return 0;
if (type == error_mark_node)
return 0;
if (!TYPE_P (type))
{
if (abi_version_at_least (2))
type_binfo = type;
type = BINFO_TYPE (type);
}
if (CLASS_TYPE_P (type))
{
tree field;
tree binfo;
int i;
if (!CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
return 0;
r = (*f) (type, offset, offsets);
if (r)
return r;
if (!type_binfo)
type_binfo = TYPE_BINFO (type);
for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, binfo); i++)
{
tree binfo_offset;
if (abi_version_at_least (2)
&& BINFO_VIRTUAL_P (binfo))
continue;
if (!vbases_p
&& BINFO_VIRTUAL_P (binfo)
&& !BINFO_PRIMARY_P (binfo))
continue;
if (!abi_version_at_least (2))
binfo_offset = size_binop (PLUS_EXPR,
offset,
BINFO_OFFSET (binfo));
else
{
tree orig_binfo;
orig_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
binfo_offset = size_binop (PLUS_EXPR,
offset,
BINFO_OFFSET (orig_binfo));
}
r = walk_subobject_offsets (binfo,
f,
binfo_offset,
offsets,
max_offset,
(abi_version_at_least (2)
? 0 : vbases_p));
if (r)
return r;
}
if (abi_version_at_least (2) && CLASSTYPE_VBASECLASSES (type))
{
unsigned ix;
VEC(tree,gc) *vbases;
if (vbases_p)
for (vbases = CLASSTYPE_VBASECLASSES (type), ix = 0;
VEC_iterate (tree, vbases, ix, binfo); ix++)
{
r = walk_subobject_offsets (binfo,
f,
size_binop (PLUS_EXPR,
offset,
BINFO_OFFSET (binfo)),
offsets,
max_offset,
0);
if (r)
return r;
}
else
{
tree vbase = get_primary_binfo (type_binfo);
if (vbase && BINFO_VIRTUAL_P (vbase)
&& BINFO_PRIMARY_P (vbase)
&& BINFO_INHERITANCE_CHAIN (vbase) == type_binfo)
{
r = (walk_subobject_offsets
(vbase, f, offset,
offsets, max_offset, 0));
if (r)
return r;
}
}
}
for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL && !DECL_ARTIFICIAL (field))
{
tree field_offset;
if (abi_version_at_least (2))
field_offset = byte_position (field);
else
field_offset = DECL_FIELD_OFFSET (field);
r = walk_subobject_offsets (TREE_TYPE (field),
f,
size_binop (PLUS_EXPR,
offset,
field_offset),
offsets,
max_offset,
1);
if (r)
return r;
}
}
else if (TREE_CODE (type) == ARRAY_TYPE)
{
tree element_type = strip_array_types (type);
tree domain = TYPE_DOMAIN (type);
tree index;
if (!CLASS_TYPE_P (element_type)
|| !CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type))
return 0;
for (index = size_zero_node;
(abi_version_at_least (2)
? !INT_CST_LT (TYPE_MAX_VALUE (domain), index)
: INT_CST_LT (index, TYPE_MAX_VALUE (domain)));
index = size_binop (PLUS_EXPR, index, size_one_node))
{
r = walk_subobject_offsets (TREE_TYPE (type),
f,
offset,
offsets,
max_offset,
1);
if (r)
return r;
offset = size_binop (PLUS_EXPR, offset,
TYPE_SIZE_UNIT (TREE_TYPE (type)));
if (max_offset && INT_CST_LT (max_offset, offset))
break;
}
}
return 0;
}
static void
record_subobject_offsets (tree type,
tree offset,
splay_tree offsets,
bool is_data_member)
{
tree max_offset;
if (is_data_member
|| !is_empty_class (BINFO_TYPE (type)))
max_offset = sizeof_biggest_empty_class;
else
max_offset = NULL_TREE;
walk_subobject_offsets (type, record_subobject_offset, offset,
offsets, max_offset, is_data_member);
}
static int
layout_conflict_p (tree type,
tree offset,
splay_tree offsets,
int vbases_p)
{
splay_tree_node max_node;
max_node = splay_tree_max (offsets);
if (!max_node)
return 0;
return walk_subobject_offsets (type, check_subobject_offset, offset,
offsets, (tree) (max_node->key),
vbases_p);
}
static void
layout_nonempty_base_or_field (record_layout_info rli,
tree decl,
tree binfo,
splay_tree offsets)
{
tree offset = NULL_TREE;
bool field_p;
tree type;
if (binfo)
{
type = TREE_TYPE (binfo);
field_p = false;
}
else
{
type = TREE_TYPE (decl);
field_p = true;
}
while (1)
{
struct record_layout_info_s old_rli = *rli;
place_field (rli, decl);
offset = byte_position (decl);
if (TREE_CODE (rli->t) == UNION_TYPE)
break;
if (!abi_version_at_least (2) && binfo && BINFO_VIRTUAL_P (binfo))
break;
if (layout_conflict_p (field_p ? type : binfo, offset,
offsets, field_p))
{
*rli = old_rli;
rli->bitpos
= size_binop (PLUS_EXPR, rli->bitpos,
bitsize_int (binfo
? CLASSTYPE_ALIGN (type)
: TYPE_ALIGN (type)));
normalize_rli (rli);
}
else
break;
}
if (binfo && CLASS_TYPE_P (BINFO_TYPE (binfo)))
propagate_binfo_offsets (binfo,
size_diffop (convert (ssizetype, offset),
convert (ssizetype,
BINFO_OFFSET (binfo))));
}
static int
empty_base_at_nonzero_offset_p (tree type,
tree offset,
splay_tree offsets ATTRIBUTE_UNUSED)
{
return is_empty_class (type) && !integer_zerop (offset);
}
static bool
layout_empty_base (tree binfo, tree eoc, splay_tree offsets)
{
tree alignment;
tree basetype = BINFO_TYPE (binfo);
bool atend = false;
gcc_assert (is_empty_class (basetype));
alignment = ssize_int (CLASSTYPE_ALIGN_UNIT (basetype));
if (!integer_zerop (BINFO_OFFSET (binfo)))
{
if (abi_version_at_least (2))
propagate_binfo_offsets
(binfo, size_diffop (size_zero_node, BINFO_OFFSET (binfo)));
else
warning (OPT_Wabi,
"offset of empty base %qT may not be ABI-compliant and may"
"change in a future version of GCC",
BINFO_TYPE (binfo));
}
if (layout_conflict_p (binfo,
BINFO_OFFSET (binfo),
offsets,
0))
{
atend = true;
propagate_binfo_offsets (binfo, convert (ssizetype, eoc));
while (1)
{
if (!layout_conflict_p (binfo,
BINFO_OFFSET (binfo),
offsets,
0))
break;
propagate_binfo_offsets (binfo, alignment);
}
}
return atend;
}
static tree *
build_base_field (record_layout_info rli, tree binfo,
splay_tree offsets, tree *next_field)
{
tree t = rli->t;
tree basetype = BINFO_TYPE (binfo);
if (!COMPLETE_TYPE_P (basetype))
return next_field;
if (!is_empty_class (basetype))
{
tree decl;
CLASSTYPE_EMPTY_P (t) = 0;
decl = build_decl (FIELD_DECL, NULL_TREE, CLASSTYPE_AS_BASE (basetype));
DECL_ARTIFICIAL (decl) = 1;
DECL_IGNORED_P (decl) = 1;
DECL_FIELD_CONTEXT (decl) = t;
DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
DECL_ALIGN (decl) = CLASSTYPE_ALIGN (basetype);
DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
DECL_MODE (decl) = TYPE_MODE (basetype);
DECL_FIELD_IS_BASE (decl) = 1;
layout_nonempty_base_or_field (rli, decl, binfo, offsets);
TREE_CHAIN (decl) = *next_field;
*next_field = decl;
next_field = &TREE_CHAIN (decl);
}
else
{
tree eoc;
bool atend;
eoc = round_up (rli_size_unit_so_far (rli),
CLASSTYPE_ALIGN_UNIT (basetype));
atend = layout_empty_base (binfo, eoc, offsets);
if (!BINFO_VIRTUAL_P (binfo) && CLASSTYPE_NEARLY_EMPTY_P (t))
{
if (atend)
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
else if (walk_subobject_offsets (basetype,
empty_base_at_nonzero_offset_p,
size_zero_node,
NULL,
NULL_TREE,
true))
{
if (abi_version_at_least (2))
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
else
warning (OPT_Wabi,
"class %qT will be considered nearly empty in a "
"future version of GCC", t);
}
}
}
record_subobject_offsets (binfo,
BINFO_OFFSET (binfo),
offsets,
false);
return next_field;
}
static void
build_base_fields (record_layout_info rli,
splay_tree offsets, tree *next_field)
{
tree t = rli->t;
int n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t));
int i;
if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
next_field = build_base_field (rli, CLASSTYPE_PRIMARY_BINFO (t),
offsets, next_field);
for (i = 0; i < n_baseclasses; ++i)
{
tree base_binfo;
base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (t), i);
if (base_binfo == CLASSTYPE_PRIMARY_BINFO (t))
continue;
if (BINFO_VIRTUAL_P (base_binfo))
continue;
next_field = build_base_field (rli, base_binfo,
offsets, next_field);
}
}
static void
check_methods (tree t)
{
tree x;
for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
{
check_for_override (x, t);
if (DECL_PURE_VIRTUAL_P (x) && ! DECL_VINDEX (x))
error ("initializer specified for non-virtual method %q+D", x);
if (DECL_VINDEX (x))
{
TYPE_POLYMORPHIC_P (t) = 1;
if (DECL_PURE_VIRTUAL_P (x))
VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (t), x);
}
if (DECL_DESTRUCTOR_P (x))
{
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = 1;
CLASSTYPE_HAS_NONTRIVIAL_DESTRUCTOR_BODY (t) = 1;
}
}
}
static tree
build_clone (tree fn, tree name)
{
tree parms;
tree clone;
clone = copy_decl (fn);
DECL_CLONED_FUNCTION (clone) = fn;
DECL_ABSTRACT_ORIGIN (clone) = fn;
DECL_NAME (clone) = name;
SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
DECL_PENDING_INLINE_INFO (clone) = NULL;
DECL_PENDING_INLINE_P (clone) = 0;
DECL_DEFERRED_FN (clone) = 0;
if (name == base_dtor_identifier)
{
DECL_VIRTUAL_P (clone) = 0;
if (TREE_CODE (clone) != TEMPLATE_DECL)
DECL_VINDEX (clone) = NULL_TREE;
}
if (DECL_HAS_IN_CHARGE_PARM_P (clone))
{
tree basetype;
tree parmtypes;
tree exceptions;
exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (clone));
basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
parmtypes = TREE_CHAIN (parmtypes);
parmtypes = TREE_CHAIN (parmtypes);
if (DECL_HAS_VTT_PARM_P (fn)
&& ! DECL_NEEDS_VTT_PARM_P (clone))
parmtypes = TREE_CHAIN (parmtypes);
TREE_TYPE (clone)
= build_method_type_directly (basetype,
TREE_TYPE (TREE_TYPE (clone)),
parmtypes);
if (exceptions)
TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone),
exceptions);
TREE_TYPE (clone)
= cp_build_type_attribute_variant (TREE_TYPE (clone),
TYPE_ATTRIBUTES (TREE_TYPE (fn)));
}
if (TREE_CODE (clone) != TEMPLATE_DECL)
{
DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
if (DECL_HAS_IN_CHARGE_PARM_P (clone))
{
TREE_CHAIN (DECL_ARGUMENTS (clone))
= TREE_CHAIN (TREE_CHAIN (DECL_ARGUMENTS (clone)));
DECL_HAS_IN_CHARGE_PARM_P (clone) = 0;
}
if (DECL_HAS_VTT_PARM_P (fn))
{
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))
{
DECL_CONTEXT (parms) = clone;
cxx_dup_lang_specific_decl (parms);
}
}
SET_DECL_RTL (clone, NULL_RTX);
rest_of_decl_compilation (clone, 1, at_eof);
TREE_CHAIN (clone) = TREE_CHAIN (fn);
TREE_CHAIN (fn) = clone;
if (TREE_CODE (clone) == TEMPLATE_DECL)
{
tree result;
DECL_TEMPLATE_RESULT (clone)
= build_clone (DECL_TEMPLATE_RESULT (clone), name);
result = DECL_TEMPLATE_RESULT (clone);
DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
DECL_TI_TEMPLATE (result) = clone;
}
else if (pch_file)
note_decl_for_pch (clone);
return clone;
}
void
clone_function_decl (tree fn, int update_method_vec_p)
{
tree clone;
if (TREE_CHAIN (fn)
&& DECL_CLONED_FUNCTION (TREE_CHAIN (fn)))
return;
if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
{
clone = build_clone (fn, complete_ctor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
clone = build_clone (fn, base_ctor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
}
else
{
gcc_assert (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn));
if (DECL_VIRTUAL_P (fn))
{
clone = build_clone (fn, deleting_dtor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
}
if (TARGET_KEXTABI != 1
|| ! has_apple_kext_compatibility_attr_p (DECL_CONTEXT (fn)))
{
clone = build_clone (fn, complete_dtor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
}
clone = build_clone (fn, base_dtor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
}
DECL_ABSTRACT (fn) = 1;
}
void
adjust_clone_args (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;
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))
{
gcc_assert (same_type_p (TREE_TYPE (decl_parms),
TREE_TYPE (clone_parms)));
if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms))
{
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_method_type_directly (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;
}
}
gcc_assert (!clone_parms);
}
}
static void
clone_constructors_and_destructors (tree t)
{
tree fns;
if (!CLASSTYPE_METHOD_VEC (t))
return;
for (fns = CLASSTYPE_CONSTRUCTORS (t); fns; fns = OVL_NEXT (fns))
clone_function_decl (OVL_CURRENT (fns), 1);
for (fns = CLASSTYPE_DESTRUCTORS (t); fns; fns = OVL_NEXT (fns))
clone_function_decl (OVL_CURRENT (fns), 1);
}
static void
remove_zero_width_bit_fields (tree t)
{
tree *fieldsp;
fieldsp = &TYPE_FIELDS (t);
while (*fieldsp)
{
if (TREE_CODE (*fieldsp) == FIELD_DECL
&& DECL_C_BIT_FIELD (*fieldsp)
&& DECL_INITIAL (*fieldsp))
*fieldsp = TREE_CHAIN (*fieldsp);
else
fieldsp = &TREE_CHAIN (*fieldsp);
}
}
static bool
type_requires_array_cookie (tree type)
{
tree fns;
bool has_two_argument_delete_p = false;
gcc_assert (CLASS_TYPE_P (type));
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
return true;
fns = lookup_fnfields (TYPE_BINFO (type),
ansi_opname (VEC_DELETE_EXPR),
0);
if (!fns || fns == error_mark_node)
return false;
for (fns = BASELINK_FUNCTIONS (fns); fns; fns = OVL_NEXT (fns))
{
tree fn;
tree second_parm;
fn = OVL_CURRENT (fns);
second_parm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)));
if (second_parm == void_list_node)
return false;
if (TREE_CHAIN (second_parm) == void_list_node
&& same_type_p (TREE_VALUE (second_parm), sizetype))
has_two_argument_delete_p = true;
}
return has_two_argument_delete_p;
}
static void
check_bases_and_members (tree t)
{
int cant_have_const_ctor;
int no_const_asn_ref;
tree access_decls;
cant_have_const_ctor = 0;
no_const_asn_ref = 0;
check_bases (t, &cant_have_const_ctor,
&no_const_asn_ref);
check_methods (t);
check_field_decls (t, &access_decls,
&cant_have_const_ctor,
&no_const_asn_ref);
if (!TYPE_CONTAINS_VPTR_P (t))
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
TYPE_HAS_COMPLEX_INIT_REF (t)
|= (TYPE_HAS_INIT_REF (t) || TYPE_CONTAINS_VPTR_P (t));
TYPE_NEEDS_CONSTRUCTING (t)
|= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_CONTAINS_VPTR_P (t));
CLASSTYPE_NON_AGGREGATE (t)
|= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_POLYMORPHIC_P (t));
CLASSTYPE_NON_POD_P (t)
|= (CLASSTYPE_NON_AGGREGATE (t)
|| TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
|| TYPE_HAS_ASSIGN_REF (t));
TYPE_HAS_COMPLEX_ASSIGN_REF (t)
|= TYPE_HAS_ASSIGN_REF (t) || TYPE_CONTAINS_VPTR_P (t);
add_implicitly_declared_members (t,
cant_have_const_ctor,
no_const_asn_ref);
clone_constructors_and_destructors (t);
for (; access_decls; access_decls = TREE_CHAIN (access_decls))
handle_using_decl (TREE_VALUE (access_decls), t);
finish_struct_methods (t);
TYPE_LANG_SPECIFIC (t)->u.c.vec_new_uses_cookie
= type_requires_array_cookie (t);
}
static tree
create_vtable_ptr (tree t, tree* virtuals_p)
{
tree fn;
for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
if (DECL_VINDEX (fn) && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)
&& TREE_CODE (DECL_VINDEX (fn)) != INTEGER_CST)
{
tree new_virtual = make_node (TREE_LIST);
BV_FN (new_virtual) = fn;
BV_DELTA (new_virtual) = integer_zero_node;
BV_VCALL_INDEX (new_virtual) = NULL_TREE;
TREE_CHAIN (new_virtual) = *virtuals_p;
*virtuals_p = new_virtual;
}
if (!TYPE_VFIELD (t) && (*virtuals_p || TYPE_CONTAINS_VPTR_P (t)))
{
tree field;
field = build_decl (FIELD_DECL, get_vfield_name (t), vtbl_ptr_type_node);
DECL_VIRTUAL_P (field) = 1;
DECL_ARTIFICIAL (field) = 1;
DECL_FIELD_CONTEXT (field) = t;
DECL_FCONTEXT (field) = t;
TYPE_VFIELD (t) = field;
CLASSTYPE_EMPTY_P (t) = 0;
return field;
}
return NULL_TREE;
}
static void
fixup_pending_inline (tree fn)
{
if (DECL_PENDING_INLINE_INFO (fn))
{
tree args = DECL_ARGUMENTS (fn);
while (args)
{
DECL_CONTEXT (args) = fn;
args = TREE_CHAIN (args);
}
}
}
static void
fixup_inline_methods (tree type)
{
tree method = TYPE_METHODS (type);
VEC(tree,gc) *friends;
unsigned ix;
if (method && TREE_CODE (method) == TREE_VEC)
{
if (TREE_VEC_ELT (method, 1))
method = TREE_VEC_ELT (method, 1);
else if (TREE_VEC_ELT (method, 0))
method = TREE_VEC_ELT (method, 0);
else
method = TREE_VEC_ELT (method, 2);
}
for (; method; method = TREE_CHAIN (method))
fixup_pending_inline (method);
for (friends = CLASSTYPE_INLINE_FRIENDS (type), ix = 0;
VEC_iterate (tree, friends, ix, method); ix++)
fixup_pending_inline (method);
CLASSTYPE_INLINE_FRIENDS (type) = NULL;
}
static void
propagate_binfo_offsets (tree binfo, tree offset)
{
int i;
tree primary_binfo;
tree base_binfo;
BINFO_OFFSET (binfo)
= convert (sizetype,
size_binop (PLUS_EXPR,
convert (ssizetype, BINFO_OFFSET (binfo)),
offset));
primary_binfo = get_primary_binfo (binfo);
if (primary_binfo && BINFO_INHERITANCE_CHAIN (primary_binfo) == binfo)
propagate_binfo_offsets (primary_binfo, offset);
for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
{
if (base_binfo == primary_binfo)
continue;
if (BINFO_VIRTUAL_P (base_binfo))
continue;
propagate_binfo_offsets (base_binfo, offset);
}
}
static void
layout_virtual_bases (record_layout_info rli, splay_tree offsets)
{
tree vbase;
tree t = rli->t;
bool first_vbase = true;
tree *next_field;
if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) == 0)
return;
if (!abi_version_at_least(2))
{
finish_record_layout (rli, false);
#ifdef STRUCTURE_SIZE_BOUNDARY
if (! TYPE_PACKED (t))
TYPE_ALIGN (t) = MAX (TYPE_ALIGN (t), (unsigned) STRUCTURE_SIZE_BOUNDARY);
#endif
rli->offset = TYPE_SIZE_UNIT (t);
rli->bitpos = bitsize_zero_node;
rli->record_align = TYPE_ALIGN (t);
}
next_field = &TYPE_FIELDS (t);
while (*next_field)
next_field = &TREE_CHAIN (*next_field);
for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
{
if (!BINFO_VIRTUAL_P (vbase))
continue;
if (!BINFO_PRIMARY_P (vbase))
{
tree basetype = TREE_TYPE (vbase);
next_field = build_base_field (rli, vbase,
offsets, next_field);
if (warn_abi
&& first_vbase
&& (tree_int_cst_lt
(size_binop (CEIL_DIV_EXPR,
round_up (CLASSTYPE_SIZE (t),
CLASSTYPE_ALIGN (basetype)),
bitsize_unit_node),
BINFO_OFFSET (vbase))))
warning (OPT_Wabi,
"offset of virtual base %qT is not ABI-compliant and "
"may change in a future version of GCC",
basetype);
first_vbase = false;
}
}
}
static tree
end_of_base (tree binfo)
{
tree size;
if (is_empty_class (BINFO_TYPE (binfo)))
size = TYPE_SIZE_UNIT (BINFO_TYPE (binfo));
else
size = CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo));
return size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), size);
}
static tree
end_of_class (tree t, int include_virtuals_p)
{
tree result = size_zero_node;
VEC(tree,gc) *vbases;
tree binfo;
tree base_binfo;
tree offset;
int i;
for (binfo = TYPE_BINFO (t), i = 0;
BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
{
if (!include_virtuals_p
&& BINFO_VIRTUAL_P (base_binfo)
&& (!BINFO_PRIMARY_P (base_binfo)
|| BINFO_INHERITANCE_CHAIN (base_binfo) != TYPE_BINFO (t)))
continue;
offset = end_of_base (base_binfo);
if (INT_CST_LT_UNSIGNED (result, offset))
result = offset;
}
if (abi_version_at_least (2) && include_virtuals_p)
for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
VEC_iterate (tree, vbases, i, base_binfo); i++)
{
offset = end_of_base (base_binfo);
if (INT_CST_LT_UNSIGNED (result, offset))
result = offset;
}
return result;
}
static void
warn_about_ambiguous_bases (tree t)
{
int i;
VEC(tree,gc) *vbases;
tree basetype;
tree binfo;
tree base_binfo;
if (!CLASSTYPE_REPEATED_BASE_P (t))
return;
for (binfo = TYPE_BINFO (t), i = 0;
BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
{
basetype = BINFO_TYPE (base_binfo);
if (!lookup_base (t, basetype, ba_unique | ba_quiet, NULL))
warning (0, "direct base %qT inaccessible in %qT due to ambiguity",
basetype, t);
}
if (extra_warnings)
for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
VEC_iterate (tree, vbases, i, binfo); i++)
{
basetype = BINFO_TYPE (binfo);
if (!lookup_base (t, basetype, ba_unique | ba_quiet, NULL))
warning (OPT_Wextra, "virtual base %qT inaccessible in %qT due to ambiguity",
basetype, t);
}
}
static int
splay_tree_compare_integer_csts (splay_tree_key k1, splay_tree_key k2)
{
return tree_int_cst_compare ((tree) k1, (tree) k2);
}
static void
include_empty_classes (record_layout_info rli)
{
tree eoc;
tree rli_size;
eoc = end_of_class (rli->t,
CLASSTYPE_AS_BASE (rli->t) != NULL_TREE);
rli_size = rli_size_unit_so_far (rli);
if (TREE_CODE (rli_size) == INTEGER_CST
&& INT_CST_LT_UNSIGNED (rli_size, eoc))
{
if (!abi_version_at_least (2))
rli->bitpos = round_down (rli->bitpos, BITS_PER_UNIT);
else
gcc_assert (tree_int_cst_equal
(rli->bitpos, round_down (rli->bitpos, BITS_PER_UNIT)));
rli->bitpos
= size_binop (PLUS_EXPR,
rli->bitpos,
size_binop (MULT_EXPR,
convert (bitsizetype,
size_binop (MINUS_EXPR,
eoc, rli_size)),
bitsize_int (BITS_PER_UNIT)));
normalize_rli (rli);
}
}
static void
layout_class_type (tree t, tree *virtuals_p)
{
tree non_static_data_members;
tree field;
tree vptr;
record_layout_info rli;
splay_tree empty_base_offsets;
bool last_field_was_bitfield = false;
tree *next_field;
tree base_t;
non_static_data_members = TYPE_FIELDS (t);
rli = start_record_layout (t);
determine_primary_bases (t);
vptr = create_vtable_ptr (t, virtuals_p);
if (vptr)
{
TREE_CHAIN (vptr) = TYPE_FIELDS (t);
TYPE_FIELDS (t) = vptr;
next_field = &TREE_CHAIN (vptr);
place_field (rli, vptr);
}
else
next_field = &TYPE_FIELDS (t);
empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
NULL, NULL);
build_base_fields (rli, empty_base_offsets, next_field);
for (field = non_static_data_members; field; field = TREE_CHAIN (field))
{
tree type;
tree padding;
if (TREE_CODE (field) != FIELD_DECL)
{
place_field (rli, field);
if (TREE_CODE (field) == VAR_DECL)
{
maybe_register_incomplete_var (field);
determine_visibility (field);
}
continue;
}
if (c_dialect_objc ())
objc_checkon_weak_attribute (field);
type = TREE_TYPE (field);
if (type == error_mark_node)
continue;
padding = NULL_TREE;
if (DECL_C_BIT_FIELD (field)
&& INT_CST_LT (TYPE_SIZE (type), DECL_SIZE (field)))
{
integer_type_kind itk;
tree integer_type;
bool was_unnamed_p = false;
for (itk = itk_char; itk != itk_none; ++itk)
if (INT_CST_LT (DECL_SIZE (field),
TYPE_SIZE (integer_types[itk])))
break;
integer_type = integer_types[itk - 1];
if (!abi_version_at_least (2)
|| INT_CST_LT (TYPE_SIZE (integer_type), DECL_SIZE (field)))
{
if (abi_version_at_least (2) && TREE_CODE (t) == UNION_TYPE)
padding = DECL_SIZE (field);
else
{
if (TREE_CODE (t) == UNION_TYPE)
warning (OPT_Wabi, "size assigned to %qT may not be "
"ABI-compliant and may change in a future "
"version of GCC",
t);
padding = size_binop (MINUS_EXPR, DECL_SIZE (field),
TYPE_SIZE (integer_type));
}
}
#ifdef PCC_BITFIELD_TYPE_MATTERS
if (PCC_BITFIELD_TYPE_MATTERS && !DECL_NAME (field))
{
was_unnamed_p = true;
DECL_NAME (field) = make_anon_name ();
}
#endif
DECL_SIZE (field) = TYPE_SIZE (integer_type);
DECL_ALIGN (field) = TYPE_ALIGN (integer_type);
DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type);
layout_nonempty_base_or_field (rli, field, NULL_TREE,
empty_base_offsets);
if (was_unnamed_p)
DECL_NAME (field) = NULL_TREE;
DECL_SIZE (field) = TYPE_SIZE (type);
if (abi_version_at_least (2))
DECL_MODE (field) = TYPE_MODE (type);
else if (warn_abi
&& DECL_MODE (field) != TYPE_MODE (type))
warning (OPT_Wabi,
"the offset of %qD may not be ABI-compliant and may "
"change in a future version of GCC", field);
}
else
layout_nonempty_base_or_field (rli, field, NULL_TREE,
empty_base_offsets);
if (abi_version_at_least (2))
record_subobject_offsets (TREE_TYPE (field),
byte_position(field),
empty_base_offsets,
true);
if (warn_abi
&& DECL_C_BIT_FIELD (field)
&& !TREE_NO_WARNING (field)
&& !last_field_was_bitfield
&& !integer_zerop (size_binop (TRUNC_MOD_EXPR,
DECL_FIELD_BIT_OFFSET (field),
bitsize_unit_node)))
warning (OPT_Wabi, "offset of %q+D is not ABI-compliant and may "
"change in a future version of GCC", field);
if (warn_abi
&& !tree_int_cst_equal (DECL_FIELD_OFFSET (field),
byte_position (field))
&& contains_empty_class_p (TREE_TYPE (field)))
warning (OPT_Wabi, "%q+D contains empty classes which may cause base "
"classes to be placed at different locations in a "
"future version of GCC", field);
if (DECL_C_BIT_FIELD (field))
{
tree ftype;
unsigned HOST_WIDE_INT width;
ftype = TREE_TYPE (field);
width = tree_low_cst (DECL_SIZE (field), 1);
if (width != TYPE_PRECISION (ftype))
TREE_TYPE (field)
= c_build_bitfield_integer_type (width,
TYPE_UNSIGNED (ftype));
}
if (padding)
{
tree padding_field;
padding_field = build_decl (FIELD_DECL,
NULL_TREE,
char_type_node);
DECL_BIT_FIELD (padding_field) = 1;
DECL_SIZE (padding_field) = padding;
DECL_CONTEXT (padding_field) = t;
DECL_ARTIFICIAL (padding_field) = 1;
DECL_IGNORED_P (padding_field) = 1;
layout_nonempty_base_or_field (rli, padding_field,
NULL_TREE,
empty_base_offsets);
}
last_field_was_bitfield = DECL_C_BIT_FIELD (field);
}
if (abi_version_at_least (2) && !integer_zerop (rli->bitpos))
{
rli->bitpos = round_up (rli->bitpos, BITS_PER_UNIT);
normalize_rli (rli);
}
if (!abi_version_at_least (2))
include_empty_classes(rli);
remove_zero_width_bit_fields (t);
if (CLASSTYPE_NON_POD_P (t) || CLASSTYPE_EMPTY_P (t))
{
base_t = make_node (TREE_CODE (t));
if (!abi_version_at_least (2) && CLASSTYPE_EMPTY_P (t))
{
TYPE_SIZE (base_t) = bitsize_zero_node;
TYPE_SIZE_UNIT (base_t) = size_zero_node;
if (warn_abi && !integer_zerop (rli_size_unit_so_far (rli)))
warning (OPT_Wabi,
"layout of classes derived from empty class %qT "
"may change in a future version of GCC",
t);
}
else
{
tree eoc;
eoc = end_of_class (t, 0);
TYPE_SIZE_UNIT (base_t)
= size_binop (MAX_EXPR,
convert (sizetype,
size_binop (CEIL_DIV_EXPR,
rli_size_so_far (rli),
bitsize_int (BITS_PER_UNIT))),
eoc);
TYPE_SIZE (base_t)
= size_binop (MAX_EXPR,
rli_size_so_far (rli),
size_binop (MULT_EXPR,
convert (bitsizetype, eoc),
bitsize_int (BITS_PER_UNIT)));
}
TYPE_ALIGN (base_t) = rli->record_align;
TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t);
next_field = &TYPE_FIELDS (base_t);
for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL)
{
*next_field = build_decl (FIELD_DECL,
DECL_NAME (field),
TREE_TYPE (field));
DECL_CONTEXT (*next_field) = base_t;
DECL_FIELD_OFFSET (*next_field) = DECL_FIELD_OFFSET (field);
DECL_FIELD_BIT_OFFSET (*next_field)
= DECL_FIELD_BIT_OFFSET (field);
DECL_SIZE (*next_field) = DECL_SIZE (field);
DECL_MODE (*next_field) = DECL_MODE (field);
next_field = &TREE_CHAIN (*next_field);
}
CLASSTYPE_AS_BASE (t) = base_t;
TYPE_CONTEXT (base_t) = t;
}
else
CLASSTYPE_AS_BASE (t) = t;
if (CLASSTYPE_EMPTY_P (t))
CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
layout_decl (TYPE_MAIN_DECL (t), 0);
layout_virtual_bases (rli, empty_base_offsets);
include_empty_classes(rli);
if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
place_field (rli,
build_decl (FIELD_DECL, NULL_TREE, char_type_node));
finish_record_layout (rli, true);
warn_about_ambiguous_bases (t);
for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
if (DECL_ARTIFICIAL (field) && IS_FAKE_BASE_TYPE (TREE_TYPE (field)))
TREE_TYPE (field) = TYPE_CONTEXT (TREE_TYPE (field));
splay_tree_delete (empty_base_offsets);
if (CLASSTYPE_EMPTY_P (t)
&& tree_int_cst_lt (sizeof_biggest_empty_class,
TYPE_SIZE_UNIT (t)))
sizeof_biggest_empty_class = TYPE_SIZE_UNIT (t);
}
void
determine_key_method (tree type)
{
tree method;
if (TYPE_FOR_JAVA (type)
|| processing_template_decl
|| CLASSTYPE_TEMPLATE_INSTANTIATION (type)
|| CLASSTYPE_INTERFACE_KNOWN (type))
return;
for (method = TYPE_METHODS (type); method != NULL_TREE;
method = TREE_CHAIN (method))
if (DECL_VINDEX (method) != NULL_TREE
&& ! DECL_DECLARED_INLINE_P (method)
&& ! DECL_PURE_VIRTUAL_P (method))
{
CLASSTYPE_KEY_METHOD (type) = method;
break;
}
return;
}
void
finish_struct_1 (tree t)
{
tree x;
tree virtuals = NULL_TREE;
int n_fields = 0;
if (COMPLETE_TYPE_P (t))
{
gcc_assert (IS_AGGR_TYPE (t));
error ("redefinition of %q#T", t);
popclass ();
return;
}
TYPE_SIZE (t) = NULL_TREE;
CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
fixup_inline_methods (t);
CLASSTYPE_EMPTY_P (t) = 1;
CLASSTYPE_NEARLY_EMPTY_P (t) = 1;
CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 0;
check_bases_and_members (t);
if (TYPE_CONTAINS_VPTR_P (t))
{
if (targetm.cxx.key_method_may_be_inline ())
determine_key_method (t);
if (CLASSTYPE_KEY_METHOD (t) == NULL_TREE)
keyed_classes = tree_cons (NULL_TREE, t, keyed_classes);
}
layout_class_type (t, &virtuals);
if (CLASSTYPE_AS_BASE (t) != t)
compute_record_mode (CLASSTYPE_AS_BASE (t));
virtuals = modify_all_vtables (t, nreverse (virtuals));
if (virtuals || TYPE_CONTAINS_VPTR_P (t))
{
if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
build_primary_vtable (NULL_TREE, t);
else if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
build_primary_vtable (CLASSTYPE_PRIMARY_BINFO (t), t);
}
if (TYPE_CONTAINS_VPTR_P (t))
{
int vindex;
tree fn;
if (BINFO_VTABLE (TYPE_BINFO (t)))
gcc_assert (DECL_VIRTUAL_P (BINFO_VTABLE (TYPE_BINFO (t))));
if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
gcc_assert (BINFO_VIRTUALS (TYPE_BINFO (t)) == NULL_TREE);
BINFO_VIRTUALS (TYPE_BINFO (t))
= chainon (BINFO_VIRTUALS (TYPE_BINFO (t)), virtuals);
for (vindex = 0, fn = BINFO_VIRTUALS (TYPE_BINFO (t));
fn;
fn = TREE_CHAIN (fn),
vindex += (TARGET_VTABLE_USES_DESCRIPTORS
? TARGET_VTABLE_USES_DESCRIPTORS : 1))
{
tree fndecl = BV_FN (fn);
if (DECL_THUNK_P (fndecl))
DECL_VINDEX (fndecl) = NULL_TREE;
else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
DECL_VINDEX (fndecl) = build_int_cst (NULL_TREE, vindex);
}
}
finish_struct_bits (t);
for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x))
if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
&& TREE_TYPE (x) != error_mark_node
&& same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t))
DECL_MODE (x) = TYPE_MODE (t);
n_fields = count_fields (TYPE_FIELDS (t));
if (n_fields > 7)
{
struct sorted_fields_type *field_vec = GGC_NEWVAR
(struct sorted_fields_type,
sizeof (struct sorted_fields_type) + n_fields * sizeof (tree));
field_vec->len = n_fields;
add_fields_to_record_type (TYPE_FIELDS (t), field_vec, 0);
qsort (field_vec->elts, n_fields, sizeof (tree),
field_decl_cmp);
if (! DECL_LANG_SPECIFIC (TYPE_MAIN_DECL (t)))
retrofit_lang_decl (TYPE_MAIN_DECL (t));
DECL_SORTED_FIELDS (TYPE_MAIN_DECL (t)) = field_vec;
}
constrain_class_visibility (t);
finish_vtbls (t);
build_vtt (t);
if (!TYPE_FOR_JAVA (t) && warn_nonvdtor && TYPE_POLYMORPHIC_P (t))
{
tree dtor;
dtor = CLASSTYPE_DESTRUCTORS (t);
if (
!dtor
|| (!DECL_VINDEX (dtor)
&& (!TREE_PRIVATE (dtor)
|| CLASSTYPE_FRIEND_CLASSES (t)
|| DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))))
warning (0, "%q#T has virtual functions but non-virtual destructor",
t);
}
complete_vars (t);
if (warn_overloaded_virtual)
warn_hidden (t);
targetm.cxx.adjust_class_at_definition (t);
maybe_suppress_debug_info (t);
dump_class_hierarchy (t);
cp_set_decl_ignore_flag (t, 1);
rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
cp_set_decl_ignore_flag (t, 0);
}
void
unreverse_member_declarations (tree t)
{
tree next;
tree prev;
tree x;
TYPE_METHODS (t) = nreverse (TYPE_METHODS (t));
CLASSTYPE_DECL_LIST (t) = nreverse (CLASSTYPE_DECL_LIST (t));
prev = NULL_TREE;
for (x = TYPE_FIELDS (t);
x && TREE_CODE (x) != TYPE_DECL;
x = next)
{
next = TREE_CHAIN (x);
TREE_CHAIN (x) = prev;
prev = x;
}
if (prev)
{
TREE_CHAIN (TYPE_FIELDS (t)) = x;
if (prev)
TYPE_FIELDS (t) = prev;
}
}
tree
finish_struct (tree t, tree attributes)
{
location_t saved_loc = input_location;
unreverse_member_declarations (t);
cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
input_location = DECL_SOURCE_LOCATION (TYPE_NAME (t));
if (processing_template_decl)
{
tree x;
finish_struct_methods (t);
TYPE_SIZE (t) = bitsize_zero_node;
TYPE_SIZE_UNIT (t) = size_zero_node;
CLASSTYPE_PURE_VIRTUALS (t) = NULL;
for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
if (DECL_PURE_VIRTUAL_P (x))
VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (t), x);
complete_vars (t);
}
else
finish_struct_1 (t);
input_location = saved_loc;
TYPE_BEING_DEFINED (t) = 0;
if (current_class_type)
popclass ();
else
error ("trying to finish struct, but kicked out due to previous parse errors");
if (processing_template_decl && at_function_scope_p ())
add_stmt (build_min (TAG_DEFN, t));
return t;
}
static tree
fixed_type_or_null (tree instance, int* nonnull, int* cdtorp)
{
switch (TREE_CODE (instance))
{
case INDIRECT_REF:
if (POINTER_TYPE_P (TREE_TYPE (instance)))
return NULL_TREE;
else
return fixed_type_or_null (TREE_OPERAND (instance, 0),
nonnull, cdtorp);
case CALL_EXPR:
if (TREE_HAS_CONSTRUCTOR (instance))
{
if (nonnull)
*nonnull = 1;
return TREE_TYPE (instance);
}
return NULL_TREE;
case SAVE_EXPR:
if (TREE_HAS_CONSTRUCTOR (instance))
{
if (nonnull)
*nonnull = 1;
return TREE_TYPE (instance);
}
return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
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)
return 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, cdtorp);
case ADDR_EXPR:
instance = TREE_OPERAND (instance, 0);
if (nonnull)
{
tree t = get_base_address (instance);
if (t && DECL_P (t))
*nonnull = 1;
}
return fixed_type_or_null (instance, nonnull, cdtorp);
case COMPONENT_REF:
if (DECL_FIELD_IS_BASE (TREE_OPERAND (instance, 1)))
return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull, cdtorp);
case VAR_DECL:
case FIELD_DECL:
if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
&& IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
{
if (nonnull)
*nonnull = 1;
return TREE_TYPE (TREE_TYPE (instance));
}
case TARGET_EXPR:
case PARM_DECL:
case RESULT_DECL:
if (IS_AGGR_TYPE (TREE_TYPE (instance)))
{
if (nonnull)
*nonnull = 1;
return TREE_TYPE (instance);
}
else if (instance == current_class_ptr)
{
if (nonnull)
*nonnull = 1;
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)
{
static htab_t ht;
if (!ht)
ht = htab_create (37,
htab_hash_pointer,
htab_eq_pointer,
NULL);
if (nonnull)
*nonnull = 1;
if (TREE_CODE (instance) == VAR_DECL
&& DECL_INITIAL (instance)
&& !htab_find (ht, instance))
{
tree type;
void **slot;
slot = htab_find_slot (ht, instance, INSERT);
*slot = instance;
type = fixed_type_or_null (DECL_INITIAL (instance),
nonnull, cdtorp);
htab_remove_elt (ht, instance);
return type;
}
}
return NULL_TREE;
default:
return NULL_TREE;
}
}
int
resolves_to_fixed_type_p (tree instance, int* nonnull)
{
tree t = TREE_TYPE (instance);
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);
if (!same_type_ignoring_top_level_qualifiers_p (t, fixed))
return 0;
return cdtorp ? -1 : 1;
}
void
init_class_processing (void)
{
current_class_depth = 0;
current_class_stack_size = 10;
current_class_stack
= XNEWVEC (struct class_stack_node, current_class_stack_size);
local_classes = VEC_alloc (tree, gc, 8);
sizeof_biggest_empty_class = size_zero_node;
ridpointers[(int) RID_PUBLIC] = access_public_node;
ridpointers[(int) RID_PRIVATE] = access_private_node;
ridpointers[(int) RID_PROTECTED] = access_protected_node;
}
static void
restore_class_cache (void)
{
tree type;
push_binding_level (previous_class_level);
class_binding_level = previous_class_level;
for (type = class_binding_level->type_shadowed;
type;
type = TREE_CHAIN (type))
SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (type), TREE_TYPE (type));
}
void
pushclass (tree type)
{
class_stack_node_t csn;
type = TYPE_MAIN_VARIANT (type);
if (current_class_depth + 1 >= current_class_stack_size)
{
current_class_stack_size *= 2;
current_class_stack
= XRESIZEVEC (struct class_stack_node, current_class_stack,
current_class_stack_size);
}
csn = current_class_stack + current_class_depth;
csn->name = current_class_name;
csn->type = current_class_type;
csn->access = current_access_specifier;
csn->names_used = 0;
csn->hidden = 0;
current_class_depth++;
current_class_name = TYPE_NAME (type);
if (TREE_CODE (current_class_name) == TYPE_DECL)
current_class_name = DECL_NAME (current_class_name);
current_class_type = type;
current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
? access_private_node
: access_public_node);
if (previous_class_level
&& type != previous_class_level->this_entity
&& current_class_depth == 1)
{
invalidate_class_lookup_cache ();
}
if (!previous_class_level
|| type != previous_class_level->this_entity
|| current_class_depth > 1)
pushlevel_class ();
else
restore_class_cache ();
}
void
invalidate_class_lookup_cache (void)
{
previous_class_level = NULL;
}
void
popclass (void)
{
poplevel_class ();
current_class_depth--;
current_class_name = current_class_stack[current_class_depth].name;
current_class_type = current_class_stack[current_class_depth].type;
current_access_specifier = current_class_stack[current_class_depth].access;
if (current_class_stack[current_class_depth].names_used)
splay_tree_delete (current_class_stack[current_class_depth].names_used);
}
void
push_class_stack (void)
{
if (current_class_depth)
++current_class_stack[current_class_depth - 1].hidden;
}
void
pop_class_stack (void)
{
if (current_class_depth)
--current_class_stack[current_class_depth - 1].hidden;
}
bool
currently_open_class (tree t)
{
int i;
for (i = current_class_depth; i > 0; --i)
{
tree c;
if (i == current_class_depth)
c = current_class_type;
else
{
if (current_class_stack[i].hidden)
break;
c = current_class_stack[i].type;
}
if (!c)
continue;
if (same_type_p (c, t))
return true;
}
return false;
}
tree
currently_open_derived_class (tree t)
{
int i;
if (dependent_type_p (t))
return NULL_TREE;
if (!current_class_type)
return NULL_TREE;
if (DERIVED_FROM_P (t, current_class_type))
return current_class_type;
for (i = current_class_depth - 1; i > 0; --i)
{
if (current_class_stack[i].hidden)
break;
if (DERIVED_FROM_P (t, current_class_stack[i].type))
return current_class_stack[i].type;
}
return NULL_TREE;
}
void
push_nested_class (tree type)
{
tree context;
if (type == NULL_TREE
|| type == error_mark_node
|| TREE_CODE (type) == NAMESPACE_DECL
|| ! IS_AGGR_TYPE (type)
|| TREE_CODE (type) == TEMPLATE_TYPE_PARM
|| TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM)
return;
context = DECL_CONTEXT (TYPE_MAIN_DECL (type));
if (context && CLASS_TYPE_P (context))
push_nested_class (context);
pushclass (type);
}
void
pop_nested_class (void)
{
tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
popclass ();
if (context && CLASS_TYPE_P (context))
pop_nested_class ();
}
int
current_lang_depth (void)
{
return VEC_length (tree, current_lang_base);
}
void
push_lang_context (tree name)
{
VEC_safe_push (tree, gc, current_lang_base, current_lang_name);
if (name == lang_name_cplusplus)
{
current_lang_name = name;
}
else if (name == lang_name_java)
{
current_lang_name = name;
DECL_IGNORED_P (TYPE_NAME (java_byte_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_short_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_int_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_long_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_float_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_double_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_char_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_boolean_type_node)) = 0;
}
else if (name == lang_name_c)
{
current_lang_name = name;
}
else
error ("language string %<\"%E\"%> not recognized", name);
}
void
pop_lang_context (void)
{
current_lang_name = VEC_pop (tree, current_lang_base);
}
static tree
resolve_address_of_overloaded_function (tree target_type,
tree overload,
tsubst_flags_t flags,
bool template_only,
tree explicit_targs,
tree access_path)
{
int is_ptrmem = 0;
int is_reference = 0;
tree matches = NULL_TREE;
tree fn;
gcc_assert (TREE_CODE (target_type) != POINTER_TYPE
|| TREE_CODE (TREE_TYPE (target_type)) != METHOD_TYPE);
gcc_assert (is_overloaded_fn (overload));
if (TYPE_PTRFN_P (target_type))
;
else if (TYPE_PTRMEMFUNC_P (target_type))
is_ptrmem = 1;
else if (TREE_CODE (target_type) == FUNCTION_TYPE)
{
target_type = build_reference_type (target_type);
is_reference = 1;
}
else
{
if (flags & tf_error)
error ("cannot resolve overloaded function %qD based on"
" conversion to type %qT",
DECL_NAME (OVL_FUNCTION (overload)), target_type);
return error_mark_node;
}
if (!template_only)
{
tree fns;
for (fns = overload; fns; fns = OVL_NEXT (fns))
{
tree fn = OVL_CURRENT (fns);
tree fntype;
if (TREE_CODE (fn) == TEMPLATE_DECL)
continue;
if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
!= is_ptrmem)
continue;
if (DECL_ANTICIPATED (fn))
continue;
fntype = TREE_TYPE (fn);
if (is_ptrmem)
fntype = build_ptrmemfunc_type (build_pointer_type (fntype));
else if (!is_reference)
fntype = build_pointer_type (fntype);
if (can_convert_arg (target_type, fntype, fn, LOOKUP_NORMAL))
matches = tree_cons (fn, NULL_TREE, matches);
}
}
if (!matches)
{
tree target_fn_type;
tree target_arg_types;
tree target_ret_type;
tree fns;
if (is_ptrmem)
target_fn_type
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (target_type));
else
target_fn_type = TREE_TYPE (target_type);
target_arg_types = TYPE_ARG_TYPES (target_fn_type);
target_ret_type = TREE_TYPE (target_fn_type);
if (TREE_CODE (target_fn_type) == METHOD_TYPE)
target_arg_types = TREE_CHAIN (target_arg_types);
for (fns = overload; fns; fns = OVL_NEXT (fns))
{
tree fn = OVL_CURRENT (fns);
tree instantiation;
tree instantiation_type;
tree targs;
if (TREE_CODE (fn) != TEMPLATE_DECL)
continue;
if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
!= is_ptrmem)
continue;
targs = make_tree_vec (DECL_NTPARMS (fn));
if (fn_type_unification (fn, explicit_targs, targs,
target_arg_types, target_ret_type,
DEDUCE_EXACT, LOOKUP_NORMAL))
continue;
instantiation = instantiate_template (fn, targs, flags);
if (instantiation == error_mark_node)
continue;
instantiation_type = TREE_TYPE (instantiation);
if (is_ptrmem)
instantiation_type =
build_ptrmemfunc_type (build_pointer_type (instantiation_type));
else if (!is_reference)
instantiation_type = build_pointer_type (instantiation_type);
if (can_convert_arg (target_type, instantiation_type, instantiation,
LOOKUP_NORMAL))
matches = tree_cons (instantiation, fn, matches);
}
if (matches)
{
tree match = most_specialized_instantiation (matches);
if (match != error_mark_node)
matches = tree_cons (TREE_PURPOSE (match),
NULL_TREE,
NULL_TREE);
}
}
if (matches == NULL_TREE)
{
if (flags & tf_error)
{
error ("no matches converting function %qD to type %q#T",
DECL_NAME (OVL_FUNCTION (overload)),
target_type);
for (; overload; overload = OVL_NEXT (overload))
matches = tree_cons (NULL_TREE, OVL_CURRENT (overload),
matches);
print_candidates (matches);
}
return error_mark_node;
}
else if (TREE_CHAIN (matches))
{
if (flags & tf_error)
{
tree match;
error ("converting overloaded function %qD to type %q#T is ambiguous",
DECL_NAME (OVL_FUNCTION (overload)),
target_type);
for (match = matches; match; match = TREE_CHAIN (match))
TREE_VALUE (match) = TREE_PURPOSE (match);
print_candidates (matches);
}
return error_mark_node;
}
fn = TREE_PURPOSE (matches);
if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
&& !(flags & tf_ptrmem_ok) && !flag_ms_extensions)
{
static int explained;
if (!(flags & tf_error))
return error_mark_node;
pedwarn ("assuming pointer to member %qD", fn);
if (!explained)
{
pedwarn ("(a pointer to member can only be formed with %<&%E%>)", fn);
explained = 1;
}
}
if (!(flags & tf_conv))
{
mark_used (fn);
if (DECL_FUNCTION_MEMBER_P (fn))
{
gcc_assert (access_path);
perform_or_defer_access_check (access_path, fn, fn);
}
}
if (TYPE_PTRFN_P (target_type) || TYPE_PTRMEMFUNC_P (target_type))
return build_unary_op (ADDR_EXPR, fn, 0);
else
{
cxx_mark_addressable (fn);
return fn;
}
}
tree
instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
{
tsubst_flags_t flags_in = flags;
tree access_path = NULL_TREE;
flags &= ~tf_ptrmem_ok;
if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
{
if (flags & tf_error)
error ("not enough type information");
return error_mark_node;
}
if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
{
if (same_type_p (lhstype, TREE_TYPE (rhs)))
return rhs;
if (flag_ms_extensions
&& TYPE_PTRMEMFUNC_P (lhstype)
&& !TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs)))
;
else
{
if (flags & tf_error)
error ("argument of type %qT does not match %qT",
TREE_TYPE (rhs), lhstype);
return error_mark_node;
}
}
if (TREE_CODE (rhs) == BASELINK)
{
access_path = BASELINK_ACCESS_BINFO (rhs);
rhs = BASELINK_FUNCTIONS (rhs);
}
if (TREE_CODE (rhs) == NON_DEPENDENT_EXPR)
{
if (flags & tf_error)
error ("not enough type information");
return error_mark_node;
}
gcc_assert (TREE_CODE (rhs) == ADDR_EXPR
|| TREE_CODE (rhs) == COMPONENT_REF
|| TREE_CODE (rhs) == COMPOUND_EXPR
|| really_overloaded_fn (rhs));
if (TREE_CODE (rhs) != OVERLOAD)
rhs = copy_node (rhs);
switch (TREE_CODE (rhs))
{
case COMPONENT_REF:
{
tree member = TREE_OPERAND (rhs, 1);
member = instantiate_type (lhstype, member, flags);
if (member != error_mark_node
&& TREE_SIDE_EFFECTS (TREE_OPERAND (rhs, 0)))
return build2 (COMPOUND_EXPR, TREE_TYPE (member),
TREE_OPERAND (rhs, 0), member);
return member;
}
case OFFSET_REF:
rhs = TREE_OPERAND (rhs, 1);
if (BASELINK_P (rhs))
return instantiate_type (lhstype, rhs, flags_in);
gcc_assert (TREE_CODE (rhs) == TEMPLATE_ID_EXPR);
case TEMPLATE_ID_EXPR:
{
tree fns = TREE_OPERAND (rhs, 0);
tree args = TREE_OPERAND (rhs, 1);
return
resolve_address_of_overloaded_function (lhstype, fns, flags_in,
true,
args, access_path);
}
case OVERLOAD:
case FUNCTION_DECL:
return
resolve_address_of_overloaded_function (lhstype, rhs, flags_in,
false,
NULL_TREE,
access_path);
case COMPOUND_EXPR:
TREE_OPERAND (rhs, 0)
= instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
if (TREE_OPERAND (rhs, 0) == error_mark_node)
return error_mark_node;
TREE_OPERAND (rhs, 1)
= instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
if (TREE_OPERAND (rhs, 1) == error_mark_node)
return error_mark_node;
TREE_TYPE (rhs) = lhstype;
return rhs;
case ADDR_EXPR:
{
if (PTRMEM_OK_P (rhs))
flags |= tf_ptrmem_ok;
return instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
}
case ERROR_MARK:
return error_mark_node;
default:
gcc_unreachable ();
}
return error_mark_node;
}
static tree
get_vfield_name (tree type)
{
tree binfo, base_binfo;
char *buf;
for (binfo = TYPE_BINFO (type);
BINFO_N_BASE_BINFOS (binfo);
binfo = base_binfo)
{
base_binfo = BINFO_BASE_BINFO (binfo, 0);
if (BINFO_VIRTUAL_P (base_binfo)
|| !TYPE_CONTAINS_VPTR_P (BINFO_TYPE (base_binfo)))
break;
}
type = BINFO_TYPE (binfo);
buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
+ TYPE_NAME_LENGTH (type) + 2);
sprintf (buf, VFIELD_NAME_FORMAT,
IDENTIFIER_POINTER (constructor_name (type)));
return get_identifier (buf);
}
void
print_class_statistics (void)
{
#ifdef GATHER_STATISTICS
fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
if (n_vtables)
{
fprintf (stderr, "vtables = %d; vtable searches = %d\n",
n_vtables, n_vtable_searches);
fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
n_vtable_entries, n_vtable_elems);
}
#endif
}
void
build_self_reference (void)
{
tree name = constructor_name (current_class_type);
tree value = build_lang_decl (TYPE_DECL, name, current_class_type);
tree saved_cas;
DECL_NONLOCAL (value) = 1;
DECL_CONTEXT (value) = current_class_type;
DECL_ARTIFICIAL (value) = 1;
SET_DECL_SELF_REFERENCE_P (value);
if (processing_template_decl)
value = push_template_decl (value);
saved_cas = current_access_specifier;
current_access_specifier = access_public_node;
finish_member_declaration (value);
current_access_specifier = saved_cas;
}
int
is_empty_class (tree type)
{
if (type == error_mark_node)
return 0;
if (! IS_AGGR_TYPE (type))
return 0;
if (abi_version_at_least (2))
return CLASSTYPE_EMPTY_P (type);
else
return integer_zerop (CLASSTYPE_SIZE (type));
}
static bool
contains_empty_class_p (tree type)
{
if (is_empty_class (type))
return true;
if (CLASS_TYPE_P (type))
{
tree field;
tree binfo;
tree base_binfo;
int i;
for (binfo = TYPE_BINFO (type), i = 0;
BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
if (contains_empty_class_p (BINFO_TYPE (base_binfo)))
return true;
for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL
&& !DECL_ARTIFICIAL (field)
&& is_empty_class (TREE_TYPE (field)))
return true;
}
else if (TREE_CODE (type) == ARRAY_TYPE)
return contains_empty_class_p (TREE_TYPE (type));
return false;
}
void
maybe_note_name_used_in_class (tree name, tree decl)
{
splay_tree names_used;
if (!(innermost_scope_kind() == sk_class
&& TYPE_BEING_DEFINED (current_class_type)))
return;
if (lookup_member (current_class_type, name,
0, false))
return;
if (!current_class_stack[current_class_depth - 1].names_used)
current_class_stack[current_class_depth - 1].names_used
= splay_tree_new (splay_tree_compare_pointers, 0, 0);
names_used = current_class_stack[current_class_depth - 1].names_used;
splay_tree_insert (names_used,
(splay_tree_key) name,
(splay_tree_value) decl);
}
void
note_name_declared_in_class (tree name, tree decl)
{
splay_tree names_used;
splay_tree_node n;
names_used
= current_class_stack[current_class_depth - 1].names_used;
if (!names_used)
return;
n = splay_tree_lookup (names_used, (splay_tree_key) name);
if (n)
{
error ("declaration of %q#D", decl);
error ("changes meaning of %qD from %q+#D",
DECL_NAME (OVL_CURRENT (decl)), (tree) n->value);
}
}
tree
get_vtbl_decl_for_binfo (tree binfo)
{
tree decl;
decl = BINFO_VTABLE (binfo);
if (decl && TREE_CODE (decl) == PLUS_EXPR)
{
gcc_assert (TREE_CODE (TREE_OPERAND (decl, 0)) == ADDR_EXPR);
decl = TREE_OPERAND (TREE_OPERAND (decl, 0), 0);
}
if (decl)
gcc_assert (TREE_CODE (decl) == VAR_DECL);
return decl;
}
static tree
get_primary_binfo (tree binfo)
{
tree primary_base;
primary_base = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (binfo));
if (!primary_base)
return NULL_TREE;
return copied_binfo (primary_base, binfo);
}
static int
maybe_indent_hierarchy (FILE * stream, int indent, int indented_p)
{
if (!indented_p)
fprintf (stream, "%*s", indent, "");
return 1;
}
static tree
dump_class_hierarchy_r (FILE *stream,
int flags,
tree binfo,
tree igo,
int indent)
{
int indented = 0;
tree base_binfo;
int i;
indented = maybe_indent_hierarchy (stream, indent, 0);
fprintf (stream, "%s (0x%lx) ",
type_as_string (BINFO_TYPE (binfo), TFF_PLAIN_IDENTIFIER),
(unsigned long) binfo);
if (binfo != igo)
{
fprintf (stream, "alternative-path\n");
return igo;
}
igo = TREE_CHAIN (binfo);
fprintf (stream, HOST_WIDE_INT_PRINT_DEC,
tree_low_cst (BINFO_OFFSET (binfo), 0));
if (is_empty_class (BINFO_TYPE (binfo)))
fprintf (stream, " empty");
else if (CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (binfo)))
fprintf (stream, " nearly-empty");
if (BINFO_VIRTUAL_P (binfo))
fprintf (stream, " virtual");
fprintf (stream, "\n");
indented = 0;
if (BINFO_PRIMARY_P (binfo))
{
indented = maybe_indent_hierarchy (stream, indent + 3, indented);
fprintf (stream, " primary-for %s (0x%lx)",
type_as_string (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo)),
TFF_PLAIN_IDENTIFIER),
(unsigned long)BINFO_INHERITANCE_CHAIN (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; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
igo = dump_class_hierarchy_r (stream, flags, base_binfo, igo, indent + 2);
return igo;
}
static void
dump_class_hierarchy_1 (FILE *stream, int flags, tree t)
{
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));
fprintf (stream, " base size=%lu base align=%lu\n",
(unsigned long)(tree_low_cst (TYPE_SIZE (CLASSTYPE_AS_BASE (t)), 0)
/ BITS_PER_UNIT),
(unsigned long)(TYPE_ALIGN (CLASSTYPE_AS_BASE (t))
/ BITS_PER_UNIT));
dump_class_hierarchy_r (stream, flags, TYPE_BINFO (t), TYPE_BINFO (t), 0);
fprintf (stream, "\n");
}
void
debug_class (tree t)
{
dump_class_hierarchy_1 (stderr, TDF_SLIM, t);
}
static void
dump_class_hierarchy (tree t)
{
int flags;
FILE *stream = dump_begin (TDI_class, &flags);
if (stream)
{
dump_class_hierarchy_1 (stream, flags, t);
dump_end (TDI_class, stream);
}
}
static void
dump_array (FILE * stream, tree decl)
{
tree value;
unsigned HOST_WIDE_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_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)),
ix, value)
fprintf (stream, "%-4ld %s\n", (long)(ix * elt),
expr_as_string (value, TFF_PLAIN_IDENTIFIER));
}
static void
dump_vtable (tree t, tree binfo, tree vtable)
{
int flags;
FILE *stream = dump_begin (TDI_class, &flags);
if (!stream)
return;
if (!(flags & TDF_SLIM))
{
int ctor_vtbl_p = TYPE_BINFO (t) != binfo;
fprintf (stream, "%s for %s",
ctor_vtbl_p ? "Construction vtable" : "Vtable",
type_as_string (BINFO_TYPE (binfo), TFF_PLAIN_IDENTIFIER));
if (ctor_vtbl_p)
{
if (!BINFO_VIRTUAL_P (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");
}
dump_end (TDI_class, stream);
}
static void
dump_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);
}
static void
dump_thunk (FILE *stream, int indent, tree thunk)
{
static const char spaces[] = " ";
tree name = DECL_NAME (thunk);
tree thunks;
fprintf (stream, "%.*s%p %s %s", indent, spaces,
(void *)thunk,
!DECL_THUNK_P (thunk) ? "function"
: DECL_THIS_THUNK_P (thunk) ? "this-thunk" : "covariant-thunk",
name ? IDENTIFIER_POINTER (name) : "<unset>");
if (DECL_THUNK_P (thunk))
{
HOST_WIDE_INT fixed_adjust = THUNK_FIXED_OFFSET (thunk);
tree virtual_adjust = THUNK_VIRTUAL_OFFSET (thunk);
fprintf (stream, " fixed=" HOST_WIDE_INT_PRINT_DEC, fixed_adjust);
if (!virtual_adjust)
;
else if (DECL_THIS_THUNK_P (thunk))
fprintf (stream, " vcall=" HOST_WIDE_INT_PRINT_DEC,
tree_low_cst (virtual_adjust, 0));
else
fprintf (stream, " vbase=" HOST_WIDE_INT_PRINT_DEC "(%s)",
tree_low_cst (BINFO_VPTR_FIELD (virtual_adjust), 0),
type_as_string (BINFO_TYPE (virtual_adjust), TFF_SCOPE));
if (THUNK_ALIAS (thunk))
fprintf (stream, " alias to %p", (void *)THUNK_ALIAS (thunk));
}
fprintf (stream, "\n");
for (thunks = DECL_THUNKS (thunk); thunks; thunks = TREE_CHAIN (thunks))
dump_thunk (stream, indent + 2, thunks);
}
void
debug_thunks (tree fn)
{
dump_thunk (stderr, 0, fn);
}
static void
finish_vtbls (tree t)
{
tree list;
tree vbase;
list = build_tree_list (BINFO_VTABLE (TYPE_BINFO (t)), NULL_TREE);
accumulate_vtbl_inits (TYPE_BINFO (t), TYPE_BINFO (t),
TYPE_BINFO (t), t, list);
for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
{
if (!BINFO_VIRTUAL_P (vbase))
continue;
accumulate_vtbl_inits (vbase, vbase, TYPE_BINFO (t), t, list);
}
if (BINFO_VTABLE (TYPE_BINFO (t)))
initialize_vtable (TYPE_BINFO (t), TREE_VALUE (list));
}
static void
initialize_vtable (tree binfo, tree inits)
{
tree decl;
layout_vtable_decl (binfo, list_length (inits));
decl = get_vtbl_decl_for_binfo (binfo);
initialize_artificial_var (decl, inits);
dump_vtable (BINFO_TYPE (binfo), binfo, decl);
}
static void
build_vtt (tree t)
{
tree inits;
tree type;
tree vtt;
tree index;
inits = NULL_TREE;
index = size_zero_node;
build_vtt_inits (TYPE_BINFO (t), t, &inits, &index);
if (!inits)
return;
type = build_index_type (size_int (list_length (inits) - 1));
type = build_cplus_array_type (const_ptr_type_node, type);
vtt = build_vtable (t, mangle_vtt_for_type (t), type);
initialize_artificial_var (vtt, inits);
TREE_CHAIN (vtt) = TREE_CHAIN (CLASSTYPE_VTABLES (t));
TREE_CHAIN (CLASSTYPE_VTABLES (t)) = vtt;
dump_vtt (t, vtt);
}
static tree
binfo_ctor_vtable (tree binfo)
{
tree vt;
while (1)
{
vt = BINFO_VTABLE (binfo);
if (TREE_CODE (vt) == TREE_LIST)
vt = TREE_VALUE (vt);
if (TREE_CODE (vt) == TREE_BINFO)
binfo = vt;
else
break;
}
return vt;
}
typedef struct secondary_vptr_vtt_init_data_s
{
bool top_level_p;
tree index;
tree inits;
tree type_being_constructed;
} secondary_vptr_vtt_init_data;
static tree *
build_vtt_inits (tree binfo, tree t, tree *inits, tree *index)
{
int i;
tree b;
tree init;
tree secondary_vptrs;
secondary_vptr_vtt_init_data data;
int top_level_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
return inits;
if (!top_level_p)
{
build_ctor_vtbl_group (binfo, t);
BINFO_SUBVTT_INDEX (binfo) = *index;
}
init = binfo_ctor_vtable (binfo);
*inits = build_tree_list (NULL_TREE, init);
inits = &TREE_CHAIN (*inits);
if (top_level_p)
{
gcc_assert (!BINFO_VPTR_INDEX (binfo));
BINFO_VPTR_INDEX (binfo) = *index;
}
*index = size_binop (PLUS_EXPR, *index, TYPE_SIZE_UNIT (ptr_type_node));
for (i = 0; BINFO_BASE_ITERATE (binfo, i, b); ++i)
if (!BINFO_VIRTUAL_P (b))
inits = build_vtt_inits (b, t, inits, index);
data.top_level_p = top_level_p;
data.index = *index;
data.inits = NULL;
data.type_being_constructed = BINFO_TYPE (binfo);
dfs_walk_once (binfo, dfs_build_secondary_vptr_vtt_inits, NULL, &data);
*index = data.index;
secondary_vptrs = data.inits;
if (secondary_vptrs)
{
*inits = nreverse (secondary_vptrs);
inits = &TREE_CHAIN (secondary_vptrs);
gcc_assert (*inits == NULL_TREE);
}
if (top_level_p)
for (b = TYPE_BINFO (BINFO_TYPE (binfo)); b; b = TREE_CHAIN (b))
{
if (!BINFO_VIRTUAL_P (b))
continue;
inits = build_vtt_inits (b, t, inits, index);
}
else
dfs_walk_all (binfo, dfs_fixup_binfo_vtbls, NULL, binfo);
return inits;
}
static tree
dfs_build_secondary_vptr_vtt_inits (tree binfo, void *data_)
{
secondary_vptr_vtt_init_data *data = (secondary_vptr_vtt_init_data *)data_;
if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
return dfs_skip_bases;
if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->type_being_constructed))
return NULL_TREE;
if (!(CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
|| binfo_via_virtual (binfo, data->type_being_constructed)))
return dfs_skip_bases;
if (!BINFO_VIRTUAL_P (binfo) && BINFO_PRIMARY_P (binfo))
return NULL_TREE;
if (data->top_level_p)
{
gcc_assert (!BINFO_VPTR_INDEX (binfo));
BINFO_VPTR_INDEX (binfo) = data->index;
if (BINFO_VIRTUAL_P (binfo))
{
while (BINFO_PRIMARY_P (binfo))
binfo = BINFO_INHERITANCE_CHAIN (binfo);
}
}
data->inits = tree_cons (NULL_TREE, binfo_ctor_vtable (binfo), data->inits);
data->index = size_binop (PLUS_EXPR, data->index,
TYPE_SIZE_UNIT (ptr_type_node));
return NULL_TREE;
}
static tree
dfs_fixup_binfo_vtbls (tree binfo, void* data)
{
tree vtable = BINFO_VTABLE (binfo);
if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
return dfs_skip_bases;
if (!vtable)
return NULL_TREE;
if (TREE_CODE (vtable) == TREE_LIST
&& (TREE_PURPOSE (vtable) == (tree) data))
BINFO_VTABLE (binfo) = TREE_CHAIN (vtable);
return NULL_TREE;
}
static void
build_ctor_vtbl_group (tree binfo, tree t)
{
tree list;
tree type;
tree vtbl;
tree inits;
tree id;
tree vbase;
id = mangle_ctor_vtbl_for_type (t, binfo);
if (IDENTIFIER_GLOBAL_VALUE (id))
return;
gcc_assert (!SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t));
vtbl = build_vtable (t, id, ptr_type_node);
DECL_CONSTRUCTION_VTABLE_P (vtbl) = 1;
list = build_tree_list (vtbl, NULL_TREE);
accumulate_vtbl_inits (binfo, TYPE_BINFO (TREE_TYPE (binfo)),
binfo, t, list);
for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
vbase;
vbase = TREE_CHAIN (vbase))
{
tree b;
if (!BINFO_VIRTUAL_P (vbase))
continue;
b = copied_binfo (vbase, binfo);
accumulate_vtbl_inits (b, vbase, binfo, t, list);
}
inits = TREE_VALUE (list);
type = build_index_type (size_int (list_length (inits) - 1));
type = build_cplus_array_type (vtable_entry_type, type);
TREE_TYPE (vtbl) = type;
CLASSTYPE_VTABLES (t) = chainon (CLASSTYPE_VTABLES (t), vtbl);
initialize_artificial_var (vtbl, inits);
dump_vtable (t, binfo, vtbl);
}
static void
accumulate_vtbl_inits (tree binfo,
tree orig_binfo,
tree rtti_binfo,
tree t,
tree inits)
{
int i;
tree base_binfo;
int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (orig_binfo)));
if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
return;
if (ctor_vtbl_p
&& !CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
&& !binfo_via_virtual (orig_binfo, BINFO_TYPE (rtti_binfo)))
return;
TREE_VALUE (inits)
= chainon (TREE_VALUE (inits),
dfs_accumulate_vtbl_inits (binfo, orig_binfo,
rtti_binfo, t, inits));
for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
{
if (BINFO_VIRTUAL_P (base_binfo))
continue;
accumulate_vtbl_inits (base_binfo,
BINFO_BASE_BINFO (orig_binfo, i),
rtti_binfo, t,
inits);
}
}
static tree
dfs_accumulate_vtbl_inits (tree binfo,
tree orig_binfo,
tree rtti_binfo,
tree t,
tree l)
{
tree inits = NULL_TREE;
tree vtbl = NULL_TREE;
int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
if (ctor_vtbl_p
&& BINFO_VIRTUAL_P (orig_binfo) && BINFO_PRIMARY_P (orig_binfo))
{
tree b;
tree last = NULL_TREE;
b = binfo;
while (BINFO_PRIMARY_P (b))
{
b = BINFO_INHERITANCE_CHAIN (b);
last = b;
if (BINFO_VIRTUAL_P (b) || b == rtti_binfo)
goto found;
}
for (b = last; b; b = BINFO_INHERITANCE_CHAIN (b))
if (BINFO_VIRTUAL_P (b) || b == rtti_binfo)
break;
found:
if (b == rtti_binfo
|| (b && binfo_for_vbase (BINFO_TYPE (b), BINFO_TYPE (rtti_binfo))))
vtbl = last;
}
else if (!BINFO_NEW_VTABLE_MARKED (orig_binfo))
return inits;
if (!vtbl)
{
tree index;
int non_fn_entries;
inits = build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo,
&non_fn_entries);
vtbl = TREE_PURPOSE (l);
vtbl = build_address (vtbl);
gcc_assert (TREE_CODE (vtbl) == ADDR_EXPR);
TREE_TYPE (vtbl) = vtbl_ptr_type_node;
index = size_binop (PLUS_EXPR,
size_int (non_fn_entries),
size_int (list_length (TREE_VALUE (l))));
index = size_binop (MULT_EXPR,
TYPE_SIZE_UNIT (vtable_entry_type),
index);
#ifdef VPTR_INITIALIZER_ADJUSTMENT
if (TARGET_KEXTABI == 1 && !ctor_vtbl_p && ! BINFO_PRIMARY_P (binfo)
&& TREE_CODE (index) == INTEGER_CST
&& TREE_INT_CST_LOW (index) >= VPTR_INITIALIZER_ADJUSTMENT
&& TREE_INT_CST_HIGH (index) == 0)
index = fold (build2 (MINUS_EXPR,
TREE_TYPE (index), index,
size_int (VPTR_INITIALIZER_ADJUSTMENT)));
#endif
vtbl = build2 (PLUS_EXPR, TREE_TYPE (vtbl), vtbl, index);
}
if (ctor_vtbl_p)
BINFO_VTABLE (binfo) = tree_cons (rtti_binfo, vtbl, BINFO_VTABLE (binfo));
else if (BINFO_PRIMARY_P (binfo) && BINFO_VIRTUAL_P (binfo))
inits = NULL_TREE;
else
BINFO_VTABLE (binfo) = vtbl;
return inits;
}
static GTY(()) tree abort_fndecl_addr;
static tree
build_vtbl_initializer (tree binfo,
tree orig_binfo,
tree t,
tree rtti_binfo,
int* non_fn_entries_p)
{
tree v, b;
tree vfun_inits;
vtbl_init_data vid;
unsigned ix;
tree vbinfo;
VEC(tree,gc) *vbases;
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 = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
vid.ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
vid.generate_vcall_entries = true;
vid.index = ssize_int(-3 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
build_rtti_vtbl_entries (binfo, &vid);
vid.fns = VEC_alloc (tree, gc, 32);
build_vcall_and_vbase_vtbl_entries (binfo, &vid);
for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
VEC_iterate (tree, vbases, ix, vbinfo); ix++)
BINFO_VTABLE_PATH_MARKED (vbinfo) = 0;
if (TARGET_VTABLE_DATA_ENTRY_DISTANCE > 1)
{
tree cur, *prev;
for (prev = &vid.inits; (cur = *prev); prev = &TREE_CHAIN (cur))
{
tree add = cur;
int i;
for (i = 1; i < TARGET_VTABLE_DATA_ENTRY_DISTANCE; ++i)
add = tree_cons (NULL_TREE,
build1 (NOP_EXPR, vtable_entry_type,
null_pointer_node),
add);
*prev = add;
}
}
if (non_fn_entries_p)
*non_fn_entries_p = list_length (vid.inits);
vfun_inits = NULL_TREE;
for (v = BINFO_VIRTUALS (orig_binfo); v; v = TREE_CHAIN (v))
{
tree delta;
tree vcall_index;
tree fn, fn_original;
tree init = NULL_TREE;
fn = BV_FN (v);
fn_original = fn;
if (DECL_THUNK_P (fn))
{
if (!DECL_NAME (fn))
finish_thunk (fn);
if (THUNK_ALIAS (fn))
{
fn = THUNK_ALIAS (fn);
BV_FN (v) = fn;
}
fn_original = THUNK_TARGET (fn);
}
for (b = binfo; ; b = get_primary_binfo (b))
{
if (look_for_overrides_here (BINFO_TYPE (b), fn_original))
break;
if (BINFO_LOST_PRIMARY_P (b))
{
init = size_zero_node;
break;
}
}
if (! init)
{
delta = BV_DELTA (v);
vcall_index = BV_VCALL_INDEX (v);
gcc_assert (TREE_CODE (delta) == INTEGER_CST);
gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
if (DECL_PURE_VIRTUAL_P (fn_original))
{
fn = abort_fndecl;
if (abort_fndecl_addr == NULL)
abort_fndecl_addr = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
init = abort_fndecl_addr;
}
else
{
if (!integer_zerop (delta) || vcall_index)
{
fn = make_thunk (fn, 1, delta, vcall_index);
if (!DECL_NAME (fn))
finish_thunk (fn);
}
init = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
}
}
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 = build2 (FDESC_EXPR, vfunc_ptr_type_node,
TREE_OPERAND (init, 0),
build_int_cst (NULL_TREE, i));
TREE_CONSTANT (fdesc) = 1;
TREE_INVARIANT (fdesc) = 1;
vfun_inits = tree_cons (NULL_TREE, fdesc, vfun_inits);
}
}
else
vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
}
vfun_inits = nreverse (vfun_inits);
vid.inits = nreverse (vid.inits);
return chainon (vid.inits, vfun_inits);
}
static void
build_vcall_and_vbase_vtbl_entries (tree binfo, vtbl_init_data* vid)
{
tree b;
b = get_primary_binfo (binfo);
if (b)
build_vcall_and_vbase_vtbl_entries (b, vid);
build_vbase_offset_vtbl_entries (binfo, vid);
build_vcall_offset_vtbl_entries (binfo, vid);
}
static void
build_vbase_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
{
tree vbase;
tree t;
tree non_primary_binfo;
if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
return;
t = vid->derived;
non_primary_binfo = binfo;
while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
{
tree b;
if (BINFO_VIRTUAL_P (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;
}
for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
vbase;
vbase = TREE_CHAIN (vbase))
{
tree b;
tree delta;
if (!BINFO_VIRTUAL_P (vbase))
continue;
b = copied_binfo (vbase, binfo);
if (BINFO_VTABLE_PATH_MARKED (b))
continue;
BINFO_VTABLE_PATH_MARKED (b) = 1;
delta = size_binop (MULT_EXPR,
vid->index,
convert (ssizetype,
TYPE_SIZE_UNIT (vtable_entry_type)));
if (vid->primary_vtbl_p)
BINFO_VPTR_FIELD (b) = delta;
if (binfo != TYPE_BINFO (t))
gcc_assert (tree_int_cst_equal (delta, BINFO_VPTR_FIELD (vbase)));
vid->index = size_binop (MINUS_EXPR, vid->index,
ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
delta = size_diffop (BINFO_OFFSET (b), BINFO_OFFSET (non_primary_binfo));
*vid->last_init
= build_tree_list (NULL_TREE,
fold_build1 (NOP_EXPR,
vtable_entry_type,
delta));
vid->last_init = &TREE_CHAIN (*vid->last_init);
}
}
static void
build_vcall_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
{
if (BINFO_VIRTUAL_P (binfo) || binfo == TYPE_BINFO (vid->derived))
{
vid->vbase = binfo;
if (!BINFO_VIRTUAL_P (binfo))
vid->generate_vcall_entries = false;
add_vcall_offset_vtbl_entries_r (binfo, vid);
}
}
static void
add_vcall_offset_vtbl_entries_r (tree binfo, vtbl_init_data* vid)
{
int i;
tree primary_binfo;
tree base_binfo;
if (BINFO_VIRTUAL_P (binfo) && vid->vbase != binfo)
return;
primary_binfo = get_primary_binfo (binfo);
if (primary_binfo)
add_vcall_offset_vtbl_entries_r (primary_binfo, vid);
add_vcall_offset_vtbl_entries_1 (binfo, vid);
for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
if (base_binfo != primary_binfo)
add_vcall_offset_vtbl_entries_r (base_binfo, vid);
}
static void
add_vcall_offset_vtbl_entries_1 (tree binfo, vtbl_init_data* vid)
{
if (abi_version_at_least (2))
{
tree orig_fn;
for (orig_fn = TYPE_METHODS (BINFO_TYPE (binfo));
orig_fn;
orig_fn = TREE_CHAIN (orig_fn))
if (DECL_VINDEX (orig_fn))
add_vcall_offset (orig_fn, binfo, vid);
}
else
{
tree derived_virtuals;
tree base_virtuals;
tree orig_virtuals;
tree non_primary_binfo;
non_primary_binfo = binfo;
while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
{
tree b;
if (BINFO_VIRTUAL_P (non_primary_binfo))
{
gcc_assert (non_primary_binfo == vid->vbase);
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;
}
if (vid->ctor_vtbl_p)
non_primary_binfo
= original_binfo (non_primary_binfo, vid->rtti_binfo);
for (base_virtuals = BINFO_VIRTUALS (binfo),
derived_virtuals = BINFO_VIRTUALS (non_primary_binfo),
orig_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
base_virtuals;
base_virtuals = TREE_CHAIN (base_virtuals),
derived_virtuals = TREE_CHAIN (derived_virtuals),
orig_virtuals = TREE_CHAIN (orig_virtuals))
{
tree orig_fn;
orig_fn = BV_FN (orig_virtuals);
if (!SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), DECL_CONTEXT (orig_fn)))
continue;
add_vcall_offset (orig_fn, binfo, vid);
}
}
}
static void
add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
{
size_t i;
tree vcall_offset;
tree derived_entry;
for (i = 0; VEC_iterate (tree, vid->fns, i, derived_entry); ++i)
{
if (same_signature_p (derived_entry, orig_fn)
|| (DECL_DESTRUCTOR_P (derived_entry)
&& DECL_DESTRUCTOR_P (orig_fn)))
return;
}
if (vid->binfo == TYPE_BINFO (vid->derived))
{
tree_pair_p elt = VEC_safe_push (tree_pair_s, gc,
CLASSTYPE_VCALL_INDICES (vid->derived),
NULL);
elt->purpose = orig_fn;
elt->value = vid->index;
}
vid->index = size_binop (MINUS_EXPR, vid->index,
ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
VEC_safe_push (tree, gc, vid->fns, orig_fn);
if (vid->generate_vcall_entries)
{
tree base;
tree fn;
fn = find_final_overrider (vid->rtti_binfo, binfo, orig_fn);
if (fn == error_mark_node)
vcall_offset = build1 (NOP_EXPR, vtable_entry_type,
integer_zero_node);
else
{
base = TREE_VALUE (fn);
vcall_offset = size_diffop (BINFO_OFFSET (base),
BINFO_OFFSET (vid->binfo));
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);
}
}
static void
build_rtti_vtbl_entries (tree binfo, vtbl_init_data* vid)
{
tree b;
tree t;
tree basetype;
tree offset;
tree decl;
tree init;
basetype = BINFO_TYPE (binfo);
t = BINFO_TYPE (vid->rtti_binfo);
b = binfo;
while (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (b))
&& !BINFO_LOST_PRIMARY_P (b))
{
tree primary_base;
primary_base = get_primary_binfo (b);
gcc_assert (BINFO_PRIMARY_P (primary_base)
&& BINFO_INHERITANCE_CHAIN (primary_base) == b);
b = primary_base;
}
offset = size_diffop (BINFO_OFFSET (vid->rtti_binfo), BINFO_OFFSET (b));
if (flag_rtti)
decl = build_address (get_tinfo_decl (t));
else
decl = integer_zero_node;
init = build_nop (vfunc_ptr_type_node, decl);
*vid->last_init = build_tree_list (NULL_TREE, init);
vid->last_init = &TREE_CHAIN (*vid->last_init);
init = build_nop (vfunc_ptr_type_node, offset);
*vid->last_init = build_tree_list (NULL_TREE, init);
vid->last_init = &TREE_CHAIN (*vid->last_init);
}
tree
cp_fold_obj_type_ref (tree ref, tree known_type)
{
HOST_WIDE_INT index = tree_low_cst (OBJ_TYPE_REF_TOKEN (ref), 1);
HOST_WIDE_INT i = 0;
tree v = BINFO_VIRTUALS (TYPE_BINFO (known_type));
tree fndecl;
while (i != index)
{
i += (TARGET_VTABLE_USES_DESCRIPTORS
? TARGET_VTABLE_USES_DESCRIPTORS : 1);
v = TREE_CHAIN (v);
}
fndecl = BV_FN (v);
#ifdef ENABLE_CHECKING
gcc_assert (tree_int_cst_equal (OBJ_TYPE_REF_TOKEN (ref),
DECL_VINDEX (fndecl)));
#endif
cgraph_node (fndecl)->local.vtable_method = true;
return build_address (fndecl);
}
#ifndef TARGET_SUPPORTS_KEXTABI1
#define TARGET_SUPPORTS_KEXTABI1 0
#endif
int
has_apple_kext_compatibility_attr_p (tree class)
{
if (! TARGET_SUPPORTS_KEXTABI1)
return 0;
while (class != NULL)
{
tree base_binfo;
if (TREE_CODE (class) == ARRAY_TYPE)
{
class = TREE_TYPE (class);
continue;
}
if (BINFO_N_BASE_BINFOS (TYPE_BINFO (class)) > 1)
return 0;
if (lookup_attribute ("apple_kext_compatibility",
TYPE_ATTRIBUTES (class)))
return 1;
if (BINFO_N_BASE_BINFOS (TYPE_BINFO (class)) < 1)
break;
base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (class), 0);
if (base_binfo
&& ! BINFO_VIRTUAL_P (base_binfo))
class = BINFO_TYPE (base_binfo);
else
break;
}
return 0;
}
static int
compound_body_is_empty_p (tree t)
{
while (t && t != error_mark_node)
{
enum tree_code tc = TREE_CODE (t);
if (tc == BIND_EXPR)
{
if (BIND_EXPR_VARS (t) == 0
&& compound_body_is_empty_p (BIND_EXPR_BODY (t)))
t = TREE_CHAIN (t);
else
return 0;
}
else if (tc == STATEMENT_LIST)
{
tree_stmt_iterator iter;
for (iter = tsi_start (t); !tsi_end_p (iter); tsi_next (&iter))
if (! compound_body_is_empty_p (tsi_stmt (iter)))
return 0;
return 1;
}
else
return 0;
}
return 1;
}
int
has_empty_operator_delete_p (tree class)
{
if (! class)
return 0;
if (BINFO_N_BASE_BINFOS (TYPE_BINFO (class)) > 1)
return 0;
if (TYPE_GETS_DELETE (class))
{
tree f = lookup_fnfields (TYPE_BINFO (class),
ansi_opname (DELETE_EXPR), 0);
if (f == error_mark_node)
return 0;
if (BASELINK_P (f))
f = BASELINK_FUNCTIONS (f);
if (OVL_CURRENT (f))
{
f = OVL_CURRENT (f);
if (TREE_SIDE_EFFECTS (f))
return 1;
if (DECL_SAVED_TREE (f))
return compound_body_is_empty_p (DECL_SAVED_TREE (f));
}
}
return 0;
}
void cp_set_decl_ignore_flag (tree type, int value)
{
tree m;
tree methods = TYPE_METHODS (type);
if (!flag_limit_debug_info)
return;
if (methods == NULL_TREE)
return;
if (TREE_CODE (methods) != TREE_VEC)
m = methods;
else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
m = TREE_VEC_ELT (methods, 0);
else
m = TREE_VEC_ELT (methods, 1);
for (; m; m = TREE_CHAIN (m))
{
if (DECL_NAME (m) == base_ctor_identifier
|| DECL_NAME (m) == complete_ctor_identifier
|| DECL_NAME (m) == complete_dtor_identifier
|| DECL_NAME (m) == base_dtor_identifier
|| DECL_NAME (m) == deleting_dtor_identifier)
DECL_IGNORED_P (m) = value;
}
}
#include "gt-cp-class.h"