This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Fix PR 5682


Hi,
This fixes 5682, and ICE when building secondary vtables.
BINFO_PRIMARY_P is also set within the non-canonical parts of
the hierarchy.

built & tested on i686-pc-linux-gnu, ok for 3.1 & mainline?

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2002-03-17  Nathan Sidwell  <nathan@codesourcery.com>

	* cp-tree.h (BINFO_PRIMARY_P): Explain meaning better.
	* search.c (get_shared_vbase_if_not_primary): Non-canonical binfos
	might have BINFO_PRIMARY_P set.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.691
diff -c -3 -p -r1.691 cp-tree.h
*** cp-tree.h	2002/03/16 18:30:11	1.691
--- cp-tree.h	2002/03/17 13:41:01
*************** struct lang_type
*** 1637,1648 ****
  #define SET_BINFO_PUSHDECLS_MARKED(NODE) SET_BINFO_VTABLE_PATH_MARKED (NODE)
  #define CLEAR_BINFO_PUSHDECLS_MARKED(NODE) CLEAR_BINFO_VTABLE_PATH_MARKED (NODE)
  
! /* Nonzero if this BINFO is a primary base class.
  
-    In the TYPE_BINFO hierarchy, this flag is never set for a base
-    class of a non-primary virtual base.  This flag is only valid for
-    paths (given by BINFO_INHERITANCE_CHAIN) that really exist in the
-    final object.  */
  #define BINFO_PRIMARY_P(NODE) \
    (BINFO_PRIMARY_BASE_OF (NODE) != NULL_TREE)
  
--- 1637,1646 ----
  #define SET_BINFO_PUSHDECLS_MARKED(NODE) SET_BINFO_VTABLE_PATH_MARKED (NODE)
  #define CLEAR_BINFO_PUSHDECLS_MARKED(NODE) CLEAR_BINFO_VTABLE_PATH_MARKED (NODE)
  
! /* Nonzero if this BINFO is a primary base class.  Note, this can be
!    set for non-canononical virtual bases. For a virtual primary base
!    you might also need to check whether it is canonical.  */
  
  #define BINFO_PRIMARY_P(NODE) \
    (BINFO_PRIMARY_BASE_OF (NODE) != NULL_TREE)
  
Index: cp/search.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/search.c,v
retrieving revision 1.225
diff -c -3 -p -r1.225 search.c
*** search.c	2002/03/16 18:30:14	1.225
--- search.c	2002/03/17 13:41:08
*************** dfs_skip_nonprimary_vbases_markedp (binf
*** 1980,2007 ****
    return markedp (binfo, NULL);
  }
  
! /* If BINFO is a non-primary virtual baseclass (in the hierarchy
!    dominated by TYPE), and no primary copy appears anywhere in the
!    hierarchy, return the shared copy.  If a primary copy appears
!    elsewhere, return NULL_TREE.  Otherwise, return BINFO itself; it is
!    either a non-virtual base or a primary virtual base.  */
  
  static tree
  get_shared_vbase_if_not_primary (binfo, data)
       tree binfo;
       void *data;
  {
!   if (TREE_VIA_VIRTUAL (binfo) && !BINFO_PRIMARY_P (binfo))
      {
        tree type = (tree) data;
  
        if (TREE_CODE (type) == TREE_LIST)
  	type = TREE_PURPOSE (type);
  
        /* This is a non-primary virtual base.  If there is no primary
  	 version, get the shared version.  */
!       binfo = binfo_for_vbase (BINFO_TYPE (binfo), type);
!       if (BINFO_PRIMARY_P (binfo))
  	return NULL_TREE;
      }
  
--- 1980,2011 ----
    return markedp (binfo, NULL);
  }
  
! /* If BINFO is non-virtual, return it. If BINFO is virtual, find the
!    shared copy.  Return the shared copy if it is, in fact, BINFO, or
!    it is non-primary. Should the shared copy be primary, return
!    NULL_TREE.  */
  
  static tree
  get_shared_vbase_if_not_primary (binfo, data)
       tree binfo;
       void *data;
  {
!   if (TREE_VIA_VIRTUAL (binfo))
      {
        tree type = (tree) data;
+       tree shared_binfo;
  
        if (TREE_CODE (type) == TREE_LIST)
  	type = TREE_PURPOSE (type);
  
        /* This is a non-primary virtual base.  If there is no primary
  	 version, get the shared version.  */
!       shared_binfo = binfo_for_vbase (BINFO_TYPE (binfo), type);
!       if (!BINFO_PRIMARY_P (shared_binfo))
! 	return shared_binfo;
!       else if (shared_binfo == binfo)
! 	return binfo;
!       else
  	return NULL_TREE;
      }
  
// { dg-do compile }

// Copyright (C) 2002 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 17 Mar 2002 <nathan@codesourcery.com>
// Origin: Jakub Jelinek <jakub@redhat.com>

// PR 5681. ICE in build_secondary_vtable

struct A {
  virtual int f1 ();
};

struct B : virtual A {};

struct C {
  virtual int f2 ();
};

struct E : A {};

struct D : E,  B {};

struct F : virtual D {};

struct G : virtual F,  C {};

struct H : virtual F {};

struct I : G,  H {};

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]