class.c (dfs_modify_vtables): Tweak calculation of functions to override.
authorMark Mitchell <mark@codesourcery.com>
Thu, 10 Feb 2000 08:24:15 +0000 (08:24 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Thu, 10 Feb 2000 08:24:15 +0000 (08:24 +0000)
* class.c (dfs_modify_vtables): Tweak calculation of functions to
override.

From-SVN: r31886

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/g++.old-deja/g++.other/vtbl2.C [new file with mode: 0644]

index e632672..bd471d2 100644 (file)
@@ -1,3 +1,8 @@
+2000-02-10  Mark Mitchell  <mark@codesourcery.com>
+
+       * class.c (dfs_modify_vtables): Tweak calculation of functions to
+       override.
+
 2000-02-08  Nathan Sidwell  <nathan@acm.org>
 
        * typeck.c (strip_all_pointer_quals): Use TYPE_MAIN_VARIANT, to
index 3f8e348..9b0bae5 100644 (file)
@@ -3009,9 +3009,9 @@ dfs_modify_vtables (binfo, data)
 
       t = (tree) data;
 
-      /* If we're support RTTI then we always need a new vtable to point
-        to the RTTI information.  Under the new ABI we may need a new
-        vtable to contain vcall and vbase offsets.  */
+      /* If we're supporting RTTI then we always need a new vtable to
+        point to the RTTI information.  Under the new ABI we may need
+        a new vtable to contain vcall and vbase offsets.  */
       if (flag_rtti || flag_new_abi)
        make_new_vtable (t, binfo);
       
@@ -3031,6 +3031,7 @@ dfs_modify_vtables (binfo, data)
          tree overrider;
          tree vindex;
          tree delta;
+         int i;
 
          /* Find the function which originally caused this vtable
             entry to be present.  */
@@ -3039,9 +3040,12 @@ dfs_modify_vtables (binfo, data)
          b = dfs_walk (binfo, dfs_find_base, NULL, DECL_VIRTUAL_CONTEXT (fn));
          fn = skip_rtti_stuff (TYPE_BINFO (BINFO_TYPE (b)),
                                BINFO_TYPE (b),
-                               NULL);
-         while (!tree_int_cst_equal (DECL_VINDEX (BV_FN (fn)), vindex))
-           fn = TREE_CHAIN (fn);
+                               &i);
+         while (i < TREE_INT_CST_LOW (vindex))
+           {
+             fn = TREE_CHAIN (fn);
+             ++i;
+           }
          fn = BV_FN (fn);
 
          /* Handle the case of a virtual function defined in BINFO
diff --git a/gcc/testsuite/g++.old-deja/g++.other/vtbl2.C b/gcc/testsuite/g++.old-deja/g++.other/vtbl2.C
new file mode 100644 (file)
index 0000000..c812d30
--- /dev/null
@@ -0,0 +1,76 @@
+// Copyright (C) 2000 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 8 Feb 2000 <nathan@acm.org>
+
+// vtable construction reorganisation broke this
+
+// execution test
+
+#include <stdio.h>
+
+static int fail = 0;
+
+void bad (char const *name)
+{
+  printf ("Bad %s\n", name);
+  fail = 1;
+}
+void ok (char const *name)
+{
+  printf ("Ok %s\n", name);
+}
+
+struct Core
+{
+  virtual ~Core ();
+  virtual void Wibble () {bad (__PRETTY_FUNCTION__);}
+  virtual void Wobble () {bad (__PRETTY_FUNCTION__);}
+  virtual void Bogus  () {bad (__PRETTY_FUNCTION__);}
+};
+struct Side
+{
+  virtual ~Side ();
+  virtual void Arfle () {bad (__PRETTY_FUNCTION__);}
+  virtual void Barfle () {bad (__PRETTY_FUNCTION__);}
+  virtual void Gloop () {bad (__PRETTY_FUNCTION__);}
+  virtual void Glorp () {bad (__PRETTY_FUNCTION__);}
+  virtual void Glump () {bad (__PRETTY_FUNCTION__);}
+  virtual void Bogus  () {bad (__PRETTY_FUNCTION__);}  
+};
+struct Base : Core
+{
+  virtual ~Base ();
+  virtual void Bink () {bad (__PRETTY_FUNCTION__);}
+  virtual void Bonk () {bad (__PRETTY_FUNCTION__);}
+  virtual void  Bogus () {bad (__PRETTY_FUNCTION__);}  
+};
+struct Multi : Base, Side
+{
+  virtual ~Multi ();
+  virtual void Stomped () {ok (__PRETTY_FUNCTION__);}
+  virtual void Bunk () {bad (__PRETTY_FUNCTION__);}
+  virtual void Bogus () {bad (__PRETTY_FUNCTION__);}  
+};
+struct Trail : Multi
+{
+  virtual ~Trail ();
+};
+Core::~Core () {}
+Side::~Side () {}
+Base::~Base () {}
+Multi::~Multi () {}
+Trail::~Trail () {}
+
+void foo (Multi *ptr)
+{
+  ptr->Stomped ();
+}
+
+int main ()
+{
+  Multi m;
+  Trail t;
+  
+  foo (&m);
+  foo (&t);
+  return fail != 0;
+}