From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13513 invoked by alias); 20 Feb 2015 17:36:58 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 13412 invoked by uid 48); 20 Feb 2015 17:36:55 -0000 From: "balakrishnan.erode at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: balakrishnan.erode at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-02/txt/msg02316.txt.bz2 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