public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "balakrishnan.erode at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/65143] New: [C++11] missing devirtualization for virtual base in "final" classes Date: Fri, 20 Feb 2015 17:52:00 -0000 [thread overview] Message-ID: <bug-65143-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65143 Bug ID: 65143 Summary: [C++11] missing devirtualization for virtual base in "final" classes Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: balakrishnan.erode at gmail dot com When a class is marked final, it can devirtualize access to all base classes as its layout is known. This is missing in gcc. struct A { int i(); }; struct B : public virtual A { int get() { return A::i() + 1; } }; struct C final : public B { int get() { return A::i() + 2; } }; int foo(C& c) { return c.get(); // Need not go via vtable pointer as class C is final } int foo(B& b2) { return b2.get(); // This has to go via vtable as most derived class can change the location of A } Assembly: Both do virtual dispatch foo(C&): subq $8, %rsp movq (%rdi), %rax addq -24(%rax), %rdi call one::A::i() addq $8, %rsp addl $2, %eax ret foo(B&): subq $8, %rsp movq (%rdi), %rax addq -24(%rax), %rdi call one::A::i() addq $8, %rsp addl $1, %eax ret Complete example: gcc: http://goo.gl/U4KEvj clang: http://goo.gl/PpQCkd -- Clang does this optimization
next reply other threads:[~2015-02-20 17:36 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-02-20 17:52 balakrishnan.erode at gmail dot com [this message] 2015-02-20 18:06 ` [Bug c++/65143] " balakrishnan.erode at gmail dot com 2015-03-13 16:12 ` balakrishnan.erode at gmail dot com 2015-03-15 6:45 ` maltsevm at gmail dot com 2015-03-17 14:48 ` balakrishnan.erode at gmail dot com 2015-08-12 10:30 ` trippels at gcc dot gnu.org 2015-08-12 10:37 ` trippels at gcc dot gnu.org 2015-08-13 10:42 ` paolo.carlini at oracle 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-65143-4@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).