From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26359 invoked by alias); 16 Jan 2011 15:15:43 -0000 Received: (qmail 26350 invoked by uid 22791); 16 Jan 2011 15:15:42 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 16 Jan 2011 15:15:37 +0000 From: "zsojka at seznam dot cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/47316] New: devirtualize calls to virtual methods that are never further overriden X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: zsojka at seznam dot cz X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sun, 16 Jan 2011 15:26:00 -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 X-SW-Source: 2011-01/txt/msg01524.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47316 Summary: devirtualize calls to virtual methods that are never further overriden Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: zsojka@seznam.cz CC: jamborm@gcc.gnu.org Created attachment 22984 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22984 testcase Similiar to PR46043, but the compiler itself can be able to find out there are cases a virtual method is never overriden. Maybe this is the original intention of the devirtualization work, but in the case it is not, I am opening this PR. It is quite common to have one base class and several derived classes that are no further derived, and the hierarchy looks roughly like: class Base { virtual void f1(); virtual void f2(); virtual void f3(); }; class A : Base { virtual void f1() { ... this->f3(); ... } virtual void f2() { ... this->f1(); ... } }; class B : Base { virtual void f2() { ... this->f1(); ... } }; void foo(A *a) { ... a->f1(); ... } In a whole-program mode, if the compiler finds no type/variable is coming from external calls (where there could be possibly type derived from Base/A/B), all these cases could be devirtualized. Attached is a simple testcase that could be devirtualized, but isn't even with: $ g++ tstdevirt.C -O3 -fwhole-program