This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ patch] Fix TREE_USED flag in some cases
- From: Jan Hubicka <jh at suse dot cz>
- To: Jan Hubicka <hubicka at ucw dot cz>
- Cc: gcc-patches at gcc dot gnu dot org, mark at codesourcery dot com
- Date: Sun, 22 Jun 2003 00:51:17 +0200
- Subject: Re: [C++ patch] Fix TREE_USED flag in some cases
- References: <20030621190450.GE22092@kam.mff.cuni.cz>
> Hi,
> comment for get_tinfo_decl says:
>
> /* Return a VAR_DECL for the internal ABI defined type_info object for
> TYPE. You must arrange that the decl is mark_used, if actually use
> it --- decls in vtables are only used if the vtable is output. */
>
> however actually some callers do mark the decl as used, while others does not
> care to do so. This does not even happen for the output vtables. With my
> unit-at-a-time patch this makes rtti infos to be missing.
>
> Similarly cleanup functions are never marked used even tought they are used
> immediately after created.
>
> Lastly the RTTI names are never marged as used and never passed to
> cp_finish_decl so their size is never copmuted. This looks like an ommisin
Actually it is not ommision, it is desynchronization in between two
trees I use.
This hook:
> *************** tinfo_base_init (tree desc, tree target)
> *** 769,774 ****
> --- 776,783 ----
> SET_DECL_ASSEMBLER_NAME (name_decl,
> mangle_typeinfo_string_for_type (target));
> DECL_INITIAL (name_decl) = name_string;
> + TREE_USED (name_decl) = 1;
> + cp_finish_decl (name_decl, name_string, NULL_TREE, 0);
> pushdecl_top_level_and_finish (name_decl, name_string);
> }
>
Should read:
*************** tinfo_base_init (tree desc, tree target)
*** 769,774 ****
--- 776,782 ----
SET_DECL_ASSEMBLER_NAME (name_decl,
mangle_typeinfo_string_for_type (target));
DECL_INITIAL (name_decl) = name_string;
+ TREE_USED (name_decl) = 1;
pushdecl_top_level_and_finish (name_decl, name_string);
}
I've regtested/bootstrapped the attached patch
Sun Jun 22 00:49:11 CEST 2003 Jan Hubicka <jh@suse.cz>
* decl.c (strat_cleanup_fn): Mark as used.
* decl2.c (mark_vtable_entries): Skip casts.
* except.c (build_eh_type_type): Mark tinfo as used.
* rtti.c (get_tinfo_ptr, build_dynamic_cast_1): Likewise.
(tinfo_base_init): Mark name as used.
(emit_tinfo_decl): Mark decl as used.
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1069
diff -c -3 -p -r1.1069 decl.c
*** cp/decl.c 20 Jun 2003 02:40:33 -0000 1.1069
--- cp/decl.c 21 Jun 2003 17:50:50 -0000
*************** start_cleanup_fn (void)
*** 8415,8420 ****
--- 8415,8421 ----
it is only called via a function pointer, but we avoid unnecessary
emissions this way. */
DECL_INLINE (fndecl) = 1;
+ TREE_USED (fndecl) = 1;
/* Build the parameter. */
if (flag_use_cxa_atexit)
{
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.630
diff -c -3 -p -r1.630 decl2.c
*** cp/decl2.c 20 Jun 2003 00:48:40 -0000 1.630
--- cp/decl2.c 21 Jun 2003 17:50:50 -0000
*************** mark_vtable_entries (tree decl)
*** 1394,1399 ****
--- 1394,1403 ----
tree fnaddr = TREE_VALUE (entries);
tree fn;
+ /* RTTI entries are casted to vfunc_ptr_type_node. */
+ if (TREE_CODE (fnaddr) == NOP_EXPR)
+ fnaddr = TREE_OPERAND (fnaddr, 0);
+
if (TREE_CODE (fnaddr) != ADDR_EXPR
&& TREE_CODE (fnaddr) != FDESC_EXPR)
/* This entry is an offset: a virtual base class offset, a
Index: cp/except.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/except.c,v
retrieving revision 1.156
diff -c -3 -p -r1.156 except.c
*** cp/except.c 17 Jun 2003 05:07:59 -0000 1.156
--- cp/except.c 21 Jun 2003 17:50:50 -0000
*************** build_eh_type_type (tree type)
*** 130,136 ****
if (decl_is_java_type (type, 0))
exp = build_java_class_ref (TREE_TYPE (type));
else
! exp = get_tinfo_decl (type);
mark_used (exp);
exp = build1 (ADDR_EXPR, ptr_type_node, exp);
--- 130,139 ----
if (decl_is_java_type (type, 0))
exp = build_java_class_ref (TREE_TYPE (type));
else
! {
! exp = get_tinfo_decl (type);
! TREE_USED (exp) = 1;
! }
mark_used (exp);
exp = build1 (ADDR_EXPR, ptr_type_node, exp);
Index: cp/rtti.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/rtti.c,v
retrieving revision 1.164
diff -c -3 -p -r1.164 rtti.c
*** cp/rtti.c 20 Jun 2003 00:48:41 -0000 1.164
--- cp/rtti.c 21 Jun 2003 17:50:50 -0000
*************** get_tinfo_decl (tree type)
*** 387,394 ****
static tree
get_tinfo_ptr (tree type)
{
return build_nop (type_info_ptr_type,
! build_address (get_tinfo_decl (type)));
}
/* Return the type_info object for TYPE. */
--- 387,397 ----
static tree
get_tinfo_ptr (tree type)
{
+ tree decl = get_tinfo_decl (type);
+
+ TREE_USED (decl) = 1;
return build_nop (type_info_ptr_type,
! build_address (decl));
}
/* Return the type_info object for TYPE. */
*************** build_dynamic_cast_1 (tree type, tree ex
*** 612,619 ****
target_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
static_type = TYPE_MAIN_VARIANT (TREE_TYPE (exprtype));
! td2 = build_unary_op (ADDR_EXPR, get_tinfo_decl (target_type), 0);
! td3 = build_unary_op (ADDR_EXPR, get_tinfo_decl (static_type), 0);
/* Determine how T and V are related. */
boff = get_dynamic_cast_base_type (static_type, target_type);
--- 615,626 ----
target_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
static_type = TYPE_MAIN_VARIANT (TREE_TYPE (exprtype));
! td2 = get_tinfo_decl (target_type);
! TREE_USED (td2) = 1;
! td2 = build_unary_op (ADDR_EXPR, td2, 0);
! td3 = get_tinfo_decl (static_type);
! TREE_USED (td3) = 1;
! td3 = build_unary_op (ADDR_EXPR, td3, 0);
/* Determine how T and V are related. */
boff = get_dynamic_cast_base_type (static_type, target_type);
*************** tinfo_base_init (tree desc, tree target)
*** 769,774 ****
--- 776,782 ----
SET_DECL_ASSEMBLER_NAME (name_decl,
mangle_typeinfo_string_for_type (target));
DECL_INITIAL (name_decl) = name_string;
+ TREE_USED (name_decl) = 1;
pushdecl_top_level_and_finish (name_decl, name_string);
}
*************** emit_tinfo_decl (tree decl)
*** 1461,1466 ****
--- 1470,1476 ----
DECL_COMDAT (decl) = 0;
DECL_INITIAL (decl) = var_init;
+ TREE_USED (decl) = 1;
cp_finish_decl (decl, var_init, NULL_TREE, 0);
/* cp_finish_decl will have dealt with linkage. */