C++ PATCH for skip_rtti_stuff

Mark Mitchell mark@codesourcery.com
Sat Jan 1 20:05:00 GMT 2000


The `skip_rtti_stuff' interface was hazardous to callers -- it was too
easy to mangle BINFO_VIRTUALS accidentally.  This change swaps the
return value and one of the parameters, thereby making it far more
convenient to use.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-01-01  Mark Mitchell  <mark@codesourcery.com>

	* cp-tree.h (skip_rtti_stuff): Adjust prototype.
	* class.c (skip_rtti_stuff): Reorganize parameters and return value.
	(modify_one_vtable): Adjust.
	(fixup_vtable_deltas1): Likewise.
	(override_one_vtable): Likewise.
	* search.c (get_abstract_virtuals_1): Likewise.
	(get_pure_virtuals): Likewise.
	(expand_upcast_fixups): Likewise.
	* tree.c (debug_binfo): Likewise.
	
Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/class.c,v
retrieving revision 1.217
diff -c -p -r1.217 class.c
*** class.c	2000/01/02 02:13:53	1.217
--- class.c	2000/01/02 04:01:15
*************** get_class_offset (context, t, binfo, fnd
*** 2384,2422 ****
    return offset;
  }
  
! /* Skip RTTI information at the front of the virtual list.  */
  
! unsigned HOST_WIDE_INT
! skip_rtti_stuff (virtuals, t)
!      tree *virtuals, t;
  {
!   int n;
  
    if (CLASSTYPE_COM_INTERFACE (t))
      return 0;
  
!   n = 0;
!   if (*virtuals)
      {
        /* We always reserve a slot for the offset/tdesc entry.  */
!       ++n;
!       *virtuals = TREE_CHAIN (*virtuals);
      }
!   if (flag_vtable_thunks && *virtuals)
      {
        /* The second slot is reserved for the tdesc pointer when thunks
           are used.  */
!       ++n;
!       *virtuals = TREE_CHAIN (*virtuals);
      }
!   return n;
  }
  
  static void
  modify_one_vtable (binfo, t, fndecl)
       tree binfo, t, fndecl;
  {
!   tree virtuals = BINFO_VIRTUALS (binfo);
    unsigned HOST_WIDE_INT n;
    
    /* update rtti entry */
--- 2384,2431 ----
    return offset;
  }
  
! /* Return the BINFO_VIRTUALS list for BINFO, without the RTTI stuff at
!    the front.  If non-NULL, N is set to the number of entries
!    skipped.  */
  
! tree
! skip_rtti_stuff (binfo, t, n)
!      tree binfo;
!      tree t;
!      unsigned HOST_WIDE_INT *n;
  {
!   tree virtuals;
  
    if (CLASSTYPE_COM_INTERFACE (t))
      return 0;
  
!   if (n)
!     *n = 0;
!   virtuals = BINFO_VIRTUALS (binfo);
!   if (virtuals)
      {
        /* We always reserve a slot for the offset/tdesc entry.  */
!       if (n)
! 	++*n;
!       virtuals = TREE_CHAIN (virtuals);
      }
!   if (flag_vtable_thunks && virtuals)
      {
        /* The second slot is reserved for the tdesc pointer when thunks
           are used.  */
!       if (n)
! 	++*n;
!       virtuals = TREE_CHAIN (virtuals);
      }
! 
!   return virtuals;
  }
  
  static void
  modify_one_vtable (binfo, t, fndecl)
       tree binfo, t, fndecl;
  {
!   tree virtuals;
    unsigned HOST_WIDE_INT n;
    
    /* update rtti entry */
*************** modify_one_vtable (binfo, t, fndecl)
*** 2430,2436 ****
    if (fndecl == NULL_TREE)
      return;
  
!   n = skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
  
    while (virtuals)
      {
--- 2439,2445 ----
    if (fndecl == NULL_TREE)
      return;
  
!   virtuals = skip_rtti_stuff (binfo, BINFO_TYPE (binfo), &n);
  
    while (virtuals)
      {
*************** static void
*** 2519,2528 ****
  fixup_vtable_deltas1 (binfo, t)
       tree binfo, t;
  {
!   tree virtuals = BINFO_VIRTUALS (binfo);
    unsigned HOST_WIDE_INT n;
    
!   n = skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
  
    while (virtuals)
      {
--- 2528,2537 ----
  fixup_vtable_deltas1 (binfo, t)
       tree binfo, t;
  {
!   tree virtuals;
    unsigned HOST_WIDE_INT n;
    
!   virtuals = skip_rtti_stuff (binfo, BINFO_TYPE (binfo), &n);
  
    while (virtuals)
      {
*************** static void
*** 2677,2684 ****
  override_one_vtable (binfo, old, t)
       tree binfo, old, t;
  {
!   tree virtuals = BINFO_VIRTUALS (binfo);
!   tree old_virtuals = BINFO_VIRTUALS (old);
    enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED;
  
    /* If we have already committed to modifying it, then don't try and
--- 2686,2693 ----
  override_one_vtable (binfo, old, t)
       tree binfo, old, t;
  {
!   tree virtuals;
!   tree old_virtuals;
    enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED;
  
    /* If we have already committed to modifying it, then don't try and
*************** override_one_vtable (binfo, old, t)
*** 2686,2693 ****
    if (BINFO_NEW_VTABLE_MARKED (binfo))
      choose = NEITHER;
  
!   skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
!   skip_rtti_stuff (&old_virtuals, BINFO_TYPE (binfo));
  
    while (virtuals)
      {
--- 2695,2702 ----
    if (BINFO_NEW_VTABLE_MARKED (binfo))
      choose = NEITHER;
  
!   virtuals = skip_rtti_stuff (binfo, BINFO_TYPE (binfo), NULL);
!   old_virtuals = skip_rtti_stuff (old, BINFO_TYPE (binfo), NULL);
  
    while (virtuals)
      {
Index: cp-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.373
diff -c -p -r1.373 cp-tree.h
*** cp-tree.h	2000/01/01 03:04:27	1.373
--- cp-tree.h	2000/01/02 04:01:18
*************** extern void push_lang_context			PROTO((t
*** 3394,3400 ****
  extern void pop_lang_context			PROTO((void));
  extern tree instantiate_type			PROTO((tree, tree, int));
  extern void print_class_statistics		PROTO((void));
! extern unsigned HOST_WIDE_INT skip_rtti_stuff	PROTO((tree *, tree));
  extern void build_self_reference		PROTO((void));
  extern void warn_hidden				PROTO((tree));
  extern tree get_enclosing_class			PROTO((tree));
--- 3394,3400 ----
  extern void pop_lang_context			PROTO((void));
  extern tree instantiate_type			PROTO((tree, tree, int));
  extern void print_class_statistics		PROTO((void));
! extern tree skip_rtti_stuff	                PROTO((tree, tree, unsigned HOST_WIDE_INT *));
  extern void build_self_reference		PROTO((void));
  extern void warn_hidden				PROTO((tree));
  extern tree get_enclosing_class			PROTO((tree));
Index: search.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/search.c,v
retrieving revision 1.136
diff -c -p -r1.136 search.c
*** search.c	1999/12/31 20:26:07	1.136
--- search.c	2000/01/02 04:01:20
*************** get_abstract_virtuals_1 (binfo, do_self,
*** 2129,2137 ****
    /* Should we use something besides CLASSTYPE_VFIELDS? */
    if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
      {
!       tree virtuals = BINFO_VIRTUALS (binfo);
  
!       skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
  
        while (virtuals)
  	{
--- 2129,2137 ----
    /* Should we use something besides CLASSTYPE_VFIELDS? */
    if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
      {
!       tree virtuals;
  
!       virtuals = skip_rtti_stuff (binfo, BINFO_TYPE (binfo), NULL);
  
        while (virtuals)
  	{
*************** get_pure_virtuals (type)
*** 2160,2168 ****
  					       
    for (vbases = CLASSTYPE_VBASECLASSES (type); vbases; vbases = TREE_CHAIN (vbases))
      {
!       tree virtuals = BINFO_VIRTUALS (vbases);
  
!       skip_rtti_stuff (&virtuals, BINFO_TYPE (vbases));
  
        while (virtuals)
  	{
--- 2160,2168 ----
  					       
    for (vbases = CLASSTYPE_VBASECLASSES (type); vbases; vbases = TREE_CHAIN (vbases))
      {
!       tree virtuals;
  
!       virtuals = skip_rtti_stuff (vbases, BINFO_TYPE (vbases), NULL);
  
        while (virtuals)
  	{
*************** expand_upcast_fixups (binfo, addr, orig_
*** 2598,2604 ****
  		      vbase_offsets)
       tree binfo, addr, orig_addr, vbase, vbase_addr, t, *vbase_offsets;
  {
!   tree virtuals = BINFO_VIRTUALS (binfo);
    tree vc;
    tree delta;
    unsigned HOST_WIDE_INT n;
--- 2598,2604 ----
  		      vbase_offsets)
       tree binfo, addr, orig_addr, vbase, vbase_addr, t, *vbase_offsets;
  {
!   tree virtuals;
    tree vc;
    tree delta;
    unsigned HOST_WIDE_INT n;
*************** expand_upcast_fixups (binfo, addr, orig_
*** 2613,2619 ****
        *vbase_offsets = delta;
      }
  
!   n = skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
  
    while (virtuals)
      {
--- 2613,2619 ----
        *vbase_offsets = delta;
      }
  
!   virtuals = skip_rtti_stuff (binfo, BINFO_TYPE (binfo), &n);
  
    while (virtuals)
      {
Index: tree.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/tree.c,v
retrieving revision 1.173
diff -c -p -r1.173 tree.c
*** tree.c	1999/12/29 20:05:41	1.173
--- tree.c	2000/01/02 04:01:23
*************** debug_binfo (elem)
*** 1165,1173 ****
    else
      fprintf (stderr, "no vtable decl yet\n");
    fprintf (stderr, "virtuals:\n");
!   virtuals = BINFO_VIRTUALS (elem);
! 
!   n = skip_rtti_stuff (&virtuals, BINFO_TYPE (elem));
  
    while (virtuals)
      {
--- 1165,1171 ----
    else
      fprintf (stderr, "no vtable decl yet\n");
    fprintf (stderr, "virtuals:\n");
!   virtuals = skip_rtti_stuff (elem, BINFO_TYPE (elem), &n);
  
    while (virtuals)
      {


More information about the Gcc-patches mailing list