From patchwork Thu Oct 21 12:51:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 68603 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6B4A3B70EE for ; Thu, 21 Oct 2010 23:51:48 +1100 (EST) Received: (qmail 10339 invoked by alias); 21 Oct 2010 12:51:43 -0000 Received: (qmail 10331 invoked by uid 22791); 21 Oct 2010 12:51:43 -0000 X-SWARE-Spam-Status: No, hits=-3.7 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 21 Oct 2010 12:51:36 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id 1E34387104 for ; Thu, 21 Oct 2010 14:51:34 +0200 (CEST) Date: Thu, 21 Oct 2010 14:51:33 +0200 From: Martin Jambor To: GCC Patches Cc: Richard Guenther Subject: [PATCH, PR45875] Fix get_binfo_at_offset Message-ID: <20101021125133.GA21785@virgil.arch.suse.de> Mail-Followup-To: GCC Patches , Richard Guenther MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, the patch below fixes the original problem reported in PR 45875. The if statement is not only totally unnecessary but also wrong because it does not take into account the expected_type parameter. This currently leads to some IPA_JF_ANCESTOR jump functions which should not be there, which then leads to propagations which should not happen and wrong binfos being used for virtual method lookups. Bootstrapped and tested on x86_64-linux. OK for trunk? Thanks, Martin 2010-10-20 Martin Jambor PR tree-optimization/45875 * tree.c (get_binfo_at_offset): Remove initial zero offset test. * testsuite/g++.dg/ipa/pr45875.C: New test. Index: icln/gcc/testsuite/g++.dg/ipa/pr45875.C =================================================================== --- /dev/null +++ icln/gcc/testsuite/g++.dg/ipa/pr45875.C @@ -0,0 +1,48 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fno-early-inlining -fno-ipa-cp" } */ + +extern "C" void abort (void); + +class A +{ +public: + virtual int foo (int i); +}; + +class B +{ +public: + class A confusion; +}; + +int A::foo (int i) +{ + return i + 1; +} + +int __attribute__ ((noinline,noclone)) get_input(void) +{ + return 1; +} + +static int middleman_a (class A *obj, int i) +{ + return obj->foo (i); +} + +static int middleman_b (class B *obj, int i) +{ + return middleman_a (&obj->confusion, i); +} + + +int main (int argc, char *argv[]) +{ + class B b; + int i, j = get_input (); + + for (i = 0; i < j; i++) + if (middleman_b (&b, j) != 2) + abort (); + return 0; +} Index: icln/gcc/tree.c =================================================================== --- icln.orig/gcc/tree.c +++ icln/gcc/tree.c @@ -10884,9 +10884,6 @@ get_binfo_at_offset (tree binfo, HOST_WI { tree type; - if (offset == 0) - return binfo; - type = TREE_TYPE (binfo); while (offset > 0) {