diff options
author | Ng YongXiang <yongxiangng@gmail.com> | 2023-07-27 08:06:14 +0800 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-07-28 08:40:02 -0700 |
commit | a47e615fbf9c6f4b24e5032df5d720b6bf9b63b5 (patch) | |
tree | 7005a6811bb4f9b5a1ecbb75bf1c3806f1af31d2 /gcc/cp/init.cc | |
parent | f5fb9ff2396fd41fdd2e6d35a412e936d2d42f75 (diff) | |
download | gcc-a47e615fbf9c6f4b24e5032df5d720b6bf9b63b5.zip gcc-a47e615fbf9c6f4b24e5032df5d720b6bf9b63b5.tar.gz gcc-a47e615fbf9c6f4b24e5032df5d720b6bf9b63b5.tar.bz2 |
c++: devirtualization of array destruction [PR110057]
PR c++/110057
PR ipa/83054
gcc/cp/ChangeLog:
* init.cc (build_vec_delete_1): Devirtualize array destruction.
gcc/testsuite/ChangeLog:
* g++.dg/warn/pr83054.C: Remove devirtualization warning.
* g++.dg/lto/pr89335_0.C: Likewise.
* g++.dg/tree-ssa/devirt-array-destructor-1.C: New test.
* g++.dg/tree-ssa/devirt-array-destructor-2.C: New test.
* g++.dg/warn/pr83054-2.C: New test.
Signed-off-by: Ng Yong Xiang <yongxiangng@gmail.com>
Diffstat (limited to 'gcc/cp/init.cc')
-rw-r--r-- | gcc/cp/init.cc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index ff5014c..3b9a778 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -4116,8 +4116,8 @@ build_vec_delete_1 (location_t loc, tree base, tree maxindex, tree type, if (type_build_dtor_call (type)) { tmp = build_delete (loc, ptype, base, sfk_complete_destructor, - LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1, - complain); + LOOKUP_NORMAL|LOOKUP_DESTRUCTOR|LOOKUP_NONVIRTUAL, + 1, complain); if (tmp == error_mark_node) return error_mark_node; } @@ -4146,9 +4146,12 @@ build_vec_delete_1 (location_t loc, tree base, tree maxindex, tree type, if (tmp == error_mark_node) return error_mark_node; body = build_compound_expr (loc, body, tmp); + /* [expr.delete]/3: "In an array delete expression, if the dynamic type of + the object to be deleted is not similar to its static type, the behavior + is undefined." So we can set LOOKUP_NONVIRTUAL. */ tmp = build_delete (loc, ptype, tbase, sfk_complete_destructor, - LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1, - complain); + LOOKUP_NORMAL|LOOKUP_DESTRUCTOR|LOOKUP_NONVIRTUAL, + 1, complain); if (tmp == error_mark_node) return error_mark_node; body = build_compound_expr (loc, body, tmp); |