This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB 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]

PATCH: Fix v3 and virtual function calling


Been meaning to commit this for a long time now.  When we call a virtual
function, ``this'' should be cast to the type the function expects.  Fixes
the rest of the virtfunc.exp testcases for v3.

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer

2002-02-01  Daniel Jacobowitz  <drow@mvista.com>

        * gnu-v3-abi.c (gnuv3_virtual_fn_field): Update comments.
        Update ``this'' pointer when calling virtual functions.

Index: gnu-v3-abi.c
===================================================================
RCS file: /cvs/src/src/gdb/gnu-v3-abi.c,v
retrieving revision 1.6
diff -u -p -r1.6 gnu-v3-abi.c
--- gnu-v3-abi.c	2002/01/04 18:20:19	1.6
+++ gnu-v3-abi.c	2002/02/01 23:59:04
@@ -317,7 +317,9 @@ gnuv3_virtual_fn_field (struct value **v
   /* Now value is an object of the appropriate base type.  Fetch its
      virtual table.  */
   /* It might be possible to do this cast at the same time as the above.
-     Does multiple inheritance affect this?  */
+     Does multiple inheritance affect this?
+     Can this even trigger, or is TYPE_VPTR_BASETYPE idempotent?
+  */
   if (TYPE_VPTR_BASETYPE (vfn_base) != vfn_base)
     value = value_cast (TYPE_VPTR_BASETYPE (vfn_base), value);
   vtable_address
@@ -335,6 +337,10 @@ gnuv3_virtual_fn_field (struct value **v
   /* Cast the function pointer to the appropriate type.  */
   vfn = value_cast (lookup_pointer_type (TYPE_FN_FIELD_TYPE (f, j)),
                     vfn);
+
+  /* Is (type)value always numerically the same as (vfn_base)value?
+     If so we can spare this cast and use one of the ones above.  */
+  *value_p = value_addr (value_cast (type, *value_p));
 
   return vfn;
 }


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