[RFA] Allow casting of object pointers for method calls

Daniel Jacobowitz
2001-12-03T15:41:45Z

I'd like to commit this.

From the comment on value_virtual_fn_field:
VALUEP is a pointer to a pointer to a value, holding the object
whose virtual function we want to invoke. If the ABI requires a
virtual function's caller to adjust the `this' pointer by an amount
retrieved from the vtable before invoking the function (i.e., we're
not using "vtable thunks" to do the adjustment automatically), then
this function may set *VALUEP to point to a new object with an
appropriately tweaked address.

find_overload_match went out of its way to prevent this from working. The
cast at the end is unpleasant but, as far as I can see, correct;
value_find_oload_method_list tends to dereference pointers, and if we don't
return this rather than *this things die.

With this patch, all virtfunc tests other than:
XFAIL: gdb.c++/virtfunc.exp: print pEe->D::vg()

pass using g++ 2.95. No other regressions. I'll submit a separate patch to
remove their XFAILs. This is also necessary for my g++ 3.0 support stuff,
which is pretty trivial after Jason's gcc work and this values patchs.

Anyone, comments? I think the hack is (for now at least, maybe with a
FIXME) tolerable.

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

2001-12-03 Daniel Jacobowitz <drow@mvista.com>

* valops.c (find_overload_match): Accept obj as a
reference parameter. Update it before returning.
* value.h (find_overload_match): Update prototype.
* eval.c (evaluate_subexp_standard): Pass object to
find_overload_match by reference.

Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.16
diff -u -p -r1.16 eval.c
--- eval.c 2001/11/12 21:20:18 1.16
+++ eval.c 2001/12/03 15:27:58
@@ -845,7 +845,7 @@ evaluate_subexp_standard (struct type *e

(void) find_overload_match (arg_types, nargs, tstr,
1 /* method */ , 0 /* strict match */ ,
- arg2 /* the object */ , NULL,
+ &arg2 /* the object */ , NULL,
&valp, NULL, &static_memfuncp);

Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.41
diff -u -p -r1.41 valops.c
--- valops.c 2001/11/13 16:44:13 1.41
+++ valops.c 2001/12/03 15:27:58
@@ -2618,12 +2618,13 @@ value_find_oload_method_list (value_ptr

int
find_overload_match (struct type **arg_types, int nargs, char *name, int method,
- int lax, value_ptr obj, struct symbol *fsym,
+ int lax, value_ptr *objp, struct symbol *fsym,
value_ptr *valp, struct symbol **symp, int *staticp)
{
int nparms;
struct type **parm_types;
int champ_nparms = 0;
+ struct value *obj = (objp ? *objp : NULL);

short oload_champ = -1; /* Index of best overloaded function */
short oload_ambiguous = 0; /* Current ambiguity state for overload resolution */
@@ -2847,6 +2848,15 @@ find_overload_match (struct type **arg_t
xfree (func_name);
}

+ if (objp)
+ {
+ if (TYPE_CODE (VALUE_TYPE (temp)) != TYPE_CODE_PTR
+ && TYPE_CODE (VALUE_TYPE (*objp)) == TYPE_CODE_PTR)
+ {
+ temp = value_addr (temp);
+ }
+ *objp = temp;
+ }
return oload_incompatible ? 100 : (oload_non_standard ? 10 : 0);
}

Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.22
diff -u -p -r1.22 value.h
--- value.h 2001/10/16 01:58:07 1.22
+++ value.h 2001/12/03 15:27:58
@@ -386,7 +386,7 @@ extern struct fn_field *value_find_oload

extern int find_overload_match (struct type **arg_types, int nargs,
char *name, int method, int lax,
- value_ptr obj, struct symbol *fsym,
+ value_ptr *obj, struct symbol *fsym,
value_ptr * valp, struct symbol **symp,
int *staticp);