aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/call.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-05-27 23:54:52 -0400
committerJason Merrill <jason@redhat.com>2021-05-28 08:56:42 -0400
commitf838e3ccf8d2849980e9d0f70aa60ecd2eb5772c (patch)
treee0f056341410f152dc66aa4d174ff5f2d5193aca /gcc/cp/call.c
parent359c0a86e2974a9f3036bc05b6e6c661f2c463cf (diff)
downloadgcc-f838e3ccf8d2849980e9d0f70aa60ecd2eb5772c.zip
gcc-f838e3ccf8d2849980e9d0f70aa60ecd2eb5772c.tar.gz
gcc-f838e3ccf8d2849980e9d0f70aa60ecd2eb5772c.tar.bz2
c++: 'this' adjustment for devirtualized call
My patch for 95719 made us do a better job of finding the actual virtual function we want to call, but didn't update the 'this' pointer adjustment to match. PR c++/100797 PR c++/95719 gcc/cp/ChangeLog: * call.c (build_over_call): Adjust base_binfo in resolves_to_fixed_type_p case. gcc/testsuite/ChangeLog: * g++.dg/inherit/virtual15.C: New test.
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r--gcc/cp/call.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 3076fe6..bf524b5 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -9152,18 +9152,32 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
if (base_binfo == error_mark_node)
return error_mark_node;
}
- tree converted_arg = build_base_path (PLUS_EXPR, arg,
- base_binfo, 1, complain);
/* If we know the dynamic type of the object, look up the final overrider
in the BINFO. */
if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0
&& resolves_to_fixed_type_p (arg))
{
- fn = lookup_vfn_in_binfo (DECL_VINDEX (fn), base_binfo);
- flags |= LOOKUP_NONVIRTUAL;
+ tree ov = lookup_vfn_in_binfo (DECL_VINDEX (fn), base_binfo);
+
+ /* And unwind base_binfo to match. If we don't find the type we're
+ looking for in BINFO_INHERITANCE_CHAIN, we're looking at diamond
+ inheritance; for now do a normal virtual call in that case. */
+ tree octx = DECL_CONTEXT (ov);
+ tree obinfo = base_binfo;
+ while (obinfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (obinfo), octx))
+ obinfo = BINFO_INHERITANCE_CHAIN (obinfo);
+ if (obinfo)
+ {
+ fn = ov;
+ base_binfo = obinfo;
+ flags |= LOOKUP_NONVIRTUAL;
+ }
}
+ tree converted_arg = build_base_path (PLUS_EXPR, arg,
+ base_binfo, 1, complain);
+
argarray[j++] = converted_arg;
parm = TREE_CHAIN (parm);
if (first_arg != NULL_TREE)