diff options
author | Jason Merrill <jason@redhat.com> | 2021-05-28 17:05:23 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-06-01 11:38:21 -0400 |
commit | cf2b7020ee8e9745ede527b0a3b2e0ffbafd492b (patch) | |
tree | 2cba3de452cbeda1c79403c5f1d50c957dd43118 /gcc/cp | |
parent | 620cd7861e1266991c9c2a82e1e2d5f4d723ec88 (diff) | |
download | gcc-cf2b7020ee8e9745ede527b0a3b2e0ffbafd492b.zip gcc-cf2b7020ee8e9745ede527b0a3b2e0ffbafd492b.tar.gz gcc-cf2b7020ee8e9745ede527b0a3b2e0ffbafd492b.tar.bz2 |
c++: no clobber for C++20 destroying delete [PR91859]
Before C++20 added destroying operator delete, by the time we called
operator delete for a pointer, the object would already be gone. But that
isn't true for destroying delete. Since the optimizers' assumptions about
operator delete are based on either DECL_IS_REPLACEABLE_OPERATOR (which
already is not set) or CALL_FROM_NEW_OR_DELETE_P, let's avoid setting the
latter flag in this case.
PR c++/91859
gcc/ChangeLog:
* tree.h (CALL_FROM_NEW_OR_DELETE_P): Adjust comment.
gcc/cp/ChangeLog:
* call.c (build_op_delete_call): Don't set CALL_FROM_NEW_OR_DELETE_P
for destroying delete.
* init.c (build_delete): Don't clobber before destroying delete.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/destroying-delete5.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/call.c | 4 | ||||
-rw-r--r-- | gcc/cp/init.c | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c index bf524b5..90192b1 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7206,8 +7206,10 @@ build_op_delete_call (enum tree_code code, tree addr, tree size, treat that as an implicit delete-expression. This is also called for the delete if the constructor throws in a new-expression, and for a deleting destructor (which implements a delete-expression). */ + /* But leave this flag off for destroying delete to avoid wrong + assumptions in the optimizers. */ tree call = extract_call_expr (ret); - if (TREE_CODE (call) == CALL_EXPR) + if (TREE_CODE (call) == CALL_EXPR && !destroying_delete_p (fn)) CALL_FROM_NEW_OR_DELETE_P (call) = 1; return ret; diff --git a/gcc/cp/init.c b/gcc/cp/init.c index a85f4d5..04d4958 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -4881,7 +4881,10 @@ build_delete (location_t loc, tree otype, tree addr, complain); } - if (!destroying_delete && type_build_dtor_call (type)) + if (destroying_delete) + /* The operator delete will call the destructor. */ + expr = addr; + else if (type_build_dtor_call (type)) expr = build_dtor_call (cp_build_fold_indirect_ref (addr), auto_delete, flags, complain); else |