public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "yongxiangng at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/110057] Missed devirtualization opportunities Date: Fri, 02 Jun 2023 03:43:58 +0000 [thread overview] Message-ID: <bug-110057-4-njxLwZQtOE@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-110057-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110057 --- Comment #6 from Ng YongXiang <yongxiangng at gmail dot com> --- That is interesting. Thanks for the reply. However, I'd argue that the 2 bugs mentioned are different from what I am proposing. The 2 bugs linked access virtual functions via ptr (delete p; val->f();) and are invoked by the user directly, and so I think it makes sense for the compiler to access the vtable. However, the array issue I'm putting forth is caused by the destruction of the array with automatic storage duration, and the destruction code is generated by the compiler not by the user via some kind of ptr or reference. Moreover, clang does it right and devirtualizes the destruction of the array while gcc still doesn't. https://godbolt.org/z/f33Gh5EGM #include <iostream> #include <memory> struct A { A() { std::cout << "A()" << std::endl; } virtual ~A() { std::cout << "~A()" << std::endl; } }; struct B : public A { B() { std::cout << "B()" << std::endl; } virtual ~B() { std::cout << "~B()" << std::endl; } }; int main() { A a[3]; a[0].~A(); :: new(std::addressof(a[0])) B(); }
next prev parent reply other threads:[~2023-06-02 3:43 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-31 10:08 [Bug tree-optimization/110057] New: " yongxiangng at gmail dot com 2023-06-01 0:15 ` [Bug ipa/110057] " pinskia at gcc dot gnu.org 2023-06-01 0:24 ` pinskia at gcc dot gnu.org 2023-06-01 9:35 ` yongxiangng at gmail dot com 2023-06-01 9:37 ` yongxiangng at gmail dot com 2023-06-01 13:37 ` pinskia at gcc dot gnu.org 2023-06-02 3:43 ` yongxiangng at gmail dot com [this message] 2023-06-05 3:11 ` yongxiangng at gmail dot com 2023-06-05 3:13 ` yongxiangng at gmail dot com 2023-07-03 1:09 ` yongxiangng at gmail dot com 2023-07-28 15:40 ` cvs-commit at gcc dot gnu.org 2024-04-12 22:01 ` pinskia at gcc dot gnu.org 2024-05-27 9:29 ` user202729 at protonmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-110057-4-njxLwZQtOE@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).