From 394fd77650dde63ff946c46b7918839b9ff93d5a Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 14 Feb 2001 10:49:27 +0000 Subject: [PATCH] Kill remnants of this is variable. cp: Kill remnants of this is variable. * cp-tree.h (flag_this_is_variable): Remove. * decl2.c (flag_this_is_variable): Remove. * class.c (fixed_type_or_null): Add cdtor parm. Adjust. (build_vbase_path): The path is non-static, even in a cdtor. (resolves_to_fixed_type_p): Add additional return value. * search.c (init_vbase_pointers): Adjust. * tree.c (lvalue_p_1): Adjust. * typeck.c (mark_addressable): Adjust. From-SVN: r39676 --- gcc/cp/ChangeLog | 12 +++++++++ gcc/cp/class.c | 68 +++++++++++++++++++++++++++++------------------- gcc/cp/cp-tree.h | 4 --- gcc/cp/decl2.c | 5 ---- gcc/cp/search.c | 3 --- gcc/cp/tree.c | 2 +- gcc/cp/typeck.c | 3 +-- 7 files changed, 55 insertions(+), 42 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 880e100b753..8cbbe7ce9d9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,15 @@ +2001-02-14 Nathan Sidwell + + Kill remnants of this is variable. + * cp-tree.h (flag_this_is_variable): Remove. + * decl2.c (flag_this_is_variable): Remove. + * class.c (fixed_type_or_null): Add cdtor parm. Adjust. + (build_vbase_path): The path is non-static, even in a cdtor. + (resolves_to_fixed_type_p): Add additional return value. + * search.c (init_vbase_pointers): Adjust. + * tree.c (lvalue_p_1): Adjust. + * typeck.c (mark_addressable): Adjust. + 2001-02-14 Nathan Sidwell * pt.c (unify): Don't check cv quals of array types. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 2d8ab83dee2..55bac3711ea 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -131,7 +131,7 @@ static void maybe_warn_about_overly_private_class PARAMS ((tree)); static int field_decl_cmp PARAMS ((const tree *, const tree *)); static int method_name_cmp PARAMS ((const tree *, const tree *)); static tree add_implicitly_declared_members PARAMS ((tree, int, int, int)); -static tree fixed_type_or_null PARAMS ((tree, int *)); +static tree fixed_type_or_null PARAMS ((tree, int *, int *)); static tree resolve_address_of_overloaded_function PARAMS ((tree, tree, int, int, int, tree)); static void build_vtable_entry_ref PARAMS ((tree, tree, tree)); @@ -381,6 +381,9 @@ build_vbase_path (code, type, expr, path, nonnull) convert back to the type we want. Until that is done, we only optimize if the complete type is the same type as expr has. */ fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull); + if (fixed_type_p < 0) + /* Virtual base layout is not fixed, even in ctors and dtors. */ + fixed_type_p = 0; if (!fixed_type_p && TREE_SIDE_EFFECTS (expr)) expr = save_expr (expr); @@ -5370,9 +5373,10 @@ finish_struct (t, attributes) before this function is called. */ static tree -fixed_type_or_null (instance, nonnull) +fixed_type_or_null (instance, nonnull, cdtorp) tree instance; int *nonnull; + int *cdtorp; { switch (TREE_CODE (instance)) { @@ -5400,31 +5404,31 @@ fixed_type_or_null (instance, nonnull) *nonnull = 1; return TREE_TYPE (instance); } - return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull); + return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp); case RTL_EXPR: return NULL_TREE; case PLUS_EXPR: case MINUS_EXPR: + if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR) + return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp); if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST) /* Propagate nonnull. */ - fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull); - if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR) - return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull); + fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp); return NULL_TREE; case NOP_EXPR: case CONVERT_EXPR: - return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull); + return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp); case ADDR_EXPR: if (nonnull) *nonnull = 1; - return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull); + return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp); case COMPONENT_REF: - return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull); + return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull, cdtorp); case VAR_DECL: case FIELD_DECL: @@ -5444,21 +5448,25 @@ fixed_type_or_null (instance, nonnull) *nonnull = 1; return TREE_TYPE (instance); } - else if (nonnull) - { - if (instance == current_class_ptr - && flag_this_is_variable <= 0) - { - /* Normally, 'this' must be non-null. */ - if (flag_this_is_variable == 0) - *nonnull = 1; - - /* <0 means we're in a constructor and we know our type. */ - if (flag_this_is_variable < 0) - return TREE_TYPE (TREE_TYPE (instance)); - } - else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE) - /* Reference variables should be references to objects. */ + else if (instance == current_class_ptr) + { + if (nonnull) + *nonnull = 1; + + /* if we're in a ctor or dtor, we know our type. */ + if (DECL_LANG_SPECIFIC (current_function_decl) + && (DECL_CONSTRUCTOR_P (current_function_decl) + || DECL_DESTRUCTOR_P (current_function_decl))) + { + if (cdtorp) + *cdtorp = 1; + return TREE_TYPE (TREE_TYPE (instance)); + } + } + else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE) + { + /* Reference variables should be references to objects. */ + if (nonnull) *nonnull = 1; } return NULL_TREE; @@ -5470,7 +5478,9 @@ fixed_type_or_null (instance, nonnull) /* Return non-zero if the dynamic type of INSTANCE is known, and equivalent to the static type. We also handle the case where INSTANCE is really - a pointer. + a pointer. Return negative if this is a ctor/dtor. There the dynamic type + is known, but this might not be the most derived base of the original object, + and hence virtual bases may not be layed out according to this type. Used to determine whether the virtual function table is needed or not. @@ -5485,12 +5495,16 @@ resolves_to_fixed_type_p (instance, nonnull) int *nonnull; { tree t = TREE_TYPE (instance); - tree fixed = fixed_type_or_null (instance, nonnull); + int cdtorp = 0; + + tree fixed = fixed_type_or_null (instance, nonnull, &cdtorp); if (fixed == NULL_TREE) return 0; if (POINTER_TYPE_P (t)) t = TREE_TYPE (t); - return same_type_ignoring_top_level_qualifiers_p (t, fixed); + if (!same_type_ignoring_top_level_qualifiers_p (t, fixed)) + return 0; + return cdtorp ? -1 : 1; } diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 7881429dadf..17238730e6f 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3420,10 +3420,6 @@ extern varray_type local_classes; /* Things for handling inline functions. */ -/* Negative values means we know `this' to be of static type. */ - -extern int flag_this_is_variable; - /* Nonzero means do emit exported implementations of functions even if they can be inlined. */ diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 08960969781..5c2940c6dd5 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -346,11 +346,6 @@ int flag_labels_ok; int flag_ms_extensions; /* C++ specific flags. */ -/* Zero means that `this' is a *const. This gives nice behavior in the - 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior. - -2 means we're constructing an object and it has fixed type. */ - -int flag_this_is_variable; /* Nonzero means we should attempt to elide constructors when possible. */ diff --git a/gcc/cp/search.c b/gcc/cp/search.c index 8a6378d1d18..75d33e8e40b 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -2388,9 +2388,7 @@ init_vbase_pointers (type, decl_ptr) if (TYPE_USES_VIRTUAL_BASECLASSES (type)) { struct vbase_info vi; - int old_flag = flag_this_is_variable; tree binfo = TYPE_BINFO (type); - flag_this_is_variable = -2; /* Find all the virtual base classes, marking them for later initialization. */ @@ -2408,7 +2406,6 @@ init_vbase_pointers (type, decl_ptr) marked_vtable_pathp, NULL); - flag_this_is_variable = old_flag; return vi.inits; } diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index bd65fee987c..608602a555b 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -65,7 +65,7 @@ lvalue_p_1 (ref, treat_class_rvalues_as_lvalues) if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE) return clk_ordinary; - if (ref == current_class_ptr && flag_this_is_variable <= 0) + if (ref == current_class_ptr) return clk_none; switch (TREE_CODE (ref)) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 6cc1969a01b..3fd103f1c0b 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4886,8 +4886,7 @@ mark_addressable (exp) case PARM_DECL: if (x == current_class_ptr) { - if (! flag_this_is_variable) - error ("cannot take the address of `this', which is an ravlue expression"); + error ("cannot take the address of `this', which is an rvalue expression"); TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later */ return 1; } -- 2.30.2