search.c (binfo_for_vtable): Return least derived class, not most.
authorHans-Peter Nilsson <hp@bitrange.com>
Fri, 29 Dec 2000 02:41:05 +0000 (02:41 +0000)
committerHans-Peter Nilsson <hp@gcc.gnu.org>
Fri, 29 Dec 2000 02:41:05 +0000 (02:41 +0000)
* search.c (binfo_for_vtable): Return least derived class, not
most.  Handle secondary vtables.

From-SVN: r38521

gcc/cp/ChangeLog
gcc/cp/search.c

index 6054868d0d8bf34ba5252fe80a160ad9cae3cb32..92a8419ec7679ab38218c35bdb1a9e77cfeac504 100644 (file)
@@ -1,3 +1,8 @@
+2000-12-29  Hans-Peter Nilsson  <hp@bitrange.com>
+
+       * search.c (binfo_for_vtable): Return least derived class, not
+       most.  Handle secondary vtables.
+
 2000-12-22  Jason Merrill  <jason@redhat.com>
 
        * typeck.c (build_binary_op): Fix pmf comparison logic.
index 2f4a3e94671471a217886c56a1c5e505b99977c9..72f00901350ad8e2dbe722744ebbc2fab1e1c2b9 100644 (file)
@@ -3250,20 +3250,33 @@ types_overlap_p (empty_type, next_type)
   return oi.found_overlap;
 }
 
-/* Given a vtable VAR, determine which binfo it comes from.
+/* Given a vtable VAR, determine which of the inherited classes the vtable
+   inherits (in a loose sense) functions from.
 
-   FIXME What about secondary vtables?  */
+   FIXME: This does not work with the new ABI.  */
 
 tree
 binfo_for_vtable (var)
      tree var;
 {
-  tree binfo = TYPE_BINFO (DECL_CONTEXT (var));
+  tree main_binfo = TYPE_BINFO (DECL_CONTEXT (var));
+  tree binfos = TYPE_BINFO_BASETYPES (BINFO_TYPE (main_binfo));
+  int n_baseclasses = CLASSTYPE_N_BASECLASSES (BINFO_TYPE (main_binfo));
+  int i;
+
+  for (i = 0; i < n_baseclasses; i++)
+    {
+      tree base_binfo = TREE_VEC_ELT (binfos, i);
+      if (base_binfo != NULL_TREE && BINFO_VTABLE (base_binfo) == var)
+       return base_binfo;
+    }
 
-  while (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (binfo)))
-    binfo = get_primary_binfo (binfo);
+  /* If no secondary base classes matched, return the primary base, if
+     there is one.   */
+  if (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (main_binfo)))
+    return get_primary_binfo (main_binfo);
 
-  return binfo;
+  return main_binfo;
 }
 
 /* Returns the binfo of the first direct or indirect virtual base from