aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/call.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-08-25 07:19:41 +0200
committerJakub Jelinek <jakub@redhat.com>2020-08-25 07:19:41 +0200
commit61680cfaf1eef26a5953f36ab82a1cc13f9b2f2c (patch)
tree9f1f1aa3c1f1c81e02feef5969fc2efedad98709 /gcc/cp/call.c
parent9f2f79df19fbfaa1c4be313c2f2b5ce04646433e (diff)
downloadgcc-61680cfaf1eef26a5953f36ab82a1cc13f9b2f2c.zip
gcc-61680cfaf1eef26a5953f36ab82a1cc13f9b2f2c.tar.gz
gcc-61680cfaf1eef26a5953f36ab82a1cc13f9b2f2c.tar.bz2
c++: Fix up ptr.~PTR () handling [PR96721]
The following testcase is miscompiled, because build_trivial_dtor_call handles the case when instance is a pointer by adding a clobber to what the pointer points to (which is desirable e.g. for delete) rather than the pointer itself. That is I think always desirable behavior for references, but for pointers for the pseudo dtor case it is not. 2020-08-25 Jakub Jelinek <jakub@redhat.com> PR c++/96721 * cp-tree.h (build_trivial_dtor_call): Add bool argument defaulted to false. * call.c (build_trivial_dtor_call): Add NO_PTR_DEREF argument. If instance is a pointer and NO_PTR_DEREF is true, clobber the pointer rather than what it points to. * semantics.c (finish_call_expr): Call build_trivial_dtor_call with true as NO_PTR_DEREF. * g++.dg/opt/flifetime-dse8.C: New test.
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r--gcc/cp/call.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index c62d9e2..4726e57 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8430,10 +8430,12 @@ conv_binds_ref_to_prvalue (conversion *c)
}
/* Call the trivial destructor for INSTANCE, which can be either an lvalue of
- class type or a pointer to class type. */
+ class type or a pointer to class type. If NO_PTR_DEREF is true and
+ INSTANCE has pointer type, clobber the pointer rather than what it points
+ to. */
tree
-build_trivial_dtor_call (tree instance)
+build_trivial_dtor_call (tree instance, bool no_ptr_deref)
{
gcc_assert (!is_dummy_object (instance));
@@ -8443,7 +8445,8 @@ build_trivial_dtor_call (tree instance)
return fold_convert (void_type_node, instance);
}
- if (INDIRECT_TYPE_P (TREE_TYPE (instance)))
+ if (INDIRECT_TYPE_P (TREE_TYPE (instance))
+ && (!no_ptr_deref || TYPE_REF_P (TREE_TYPE (instance))))
{
if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
goto no_clobber;