aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2020-06-01 16:20:38 -0400
committerJason Merrill <jason@redhat.com>2020-06-01 16:52:47 -0400
commit172f2c42a10fd470c93f1e84575de9766c157591 (patch)
treee169f2fb75548db8a27b015516eb95f0f97ce9b4 /gcc/cp/class.c
parent832c1192eba6dd100e2f757e30ea6373f782ff55 (diff)
downloadgcc-172f2c42a10fd470c93f1e84575de9766c157591.zip
gcc-172f2c42a10fd470c93f1e84575de9766c157591.tar.gz
gcc-172f2c42a10fd470c93f1e84575de9766c157591.tar.bz2
c++: vptr ubsan and object of known type [PR95466]
Another case where we can't find the OBJ_TYPE_REF_OBJECT in the OBJ_TYPE_REF_EXPR. So let's just evaluate the sanitize call first. gcc/cp/ChangeLog: PR c++/95466 PR c++/95311 PR c++/95221 * class.c (build_vfn_ref): Revert 95311 change. * cp-ubsan.c (cp_ubsan_maybe_instrument_member_call): Build a COMPOUND_EXPR. gcc/testsuite/ChangeLog: PR c++/95466 * g++.dg/ubsan/vptr-17.C: New test.
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r--gcc/cp/class.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index c818826..757e010 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -729,13 +729,9 @@ build_vtbl_ref (tree instance, tree idx)
tree
build_vfn_ref (tree instance_ptr, tree idx)
{
- tree obtype = TREE_TYPE (TREE_TYPE (instance_ptr));
-
- /* Leave the INDIRECT_REF unfolded so cp_ubsan_maybe_instrument_member_call
- can find instance_ptr. */
- tree ind = build1 (INDIRECT_REF, obtype, instance_ptr);
+ tree aref;
- tree aref = build_vtbl_ref (ind, idx);
+ aref = build_vtbl_ref (cp_build_fold_indirect_ref (instance_ptr), idx);
/* When using function descriptors, the address of the
vtable entry is treated as a function pointer. */