From patchwork Fri Apr 13 13:52:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 152312 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 A398BB700A for ; Fri, 13 Apr 2012 23:53:03 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1334929983; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Cc:Subject:Message-ID:Mail-Followup-To:MIME-Version: Content-Type:Content-Disposition:User-Agent:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=p9rRPDWyJ2POIXh78RSV5QHu4K8=; b=gJR9l3YkNCHMvNTICcYT4l5PkJfsvoZWbT0Oy8fuMgX/7jTyoYDufqYoPOxpST HWepoTdYNYjGWujmxisqDk1ULOTQG9jCgddsaygXUWxd+JG0e8pxuv7bZF1P556g K7VHphkS4Ee2WWr+zr4ZS/MZ1EsqVD41xTejptXB2hJIA= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:Cc:Subject:Message-ID:Mail-Followup-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=fCysS7p4vix7aAMuJruJNnU7+q/em6//uz4LwPDRgNTg+7dUn84zsWohGzY4wd HgYWvEBjZJNjzFEii/M07/9izM58dik6lfK/WCz86rXDfe7mFG7w+0TVfTFGME3M 8Skkg01HIO9mfPCt/Tkk6EO65Hy9R0vfmVmohqqbVy6rk=; Received: (qmail 8339 invoked by alias); 13 Apr 2012 13:52:58 -0000 Received: (qmail 8329 invoked by uid 22791); 13 Apr 2012 13:52:57 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, SUBJ_OBFU_PUNCT_FEW 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; Fri, 13 Apr 2012 13:52:38 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 46AAB90CE3 for ; Fri, 13 Apr 2012 15:52:37 +0200 (CEST) Date: Fri, 13 Apr 2012 15:52:36 +0200 From: Martin Jambor To: GCC Patches Cc: Richard Guenther Subject: [PATCH, PR 52939] Gracefully deal with fold_ctor_reference returning NULL during devirtualization Message-ID: <20120413135236.GA15120@virgil.arch.suse.de> Mail-Followup-To: GCC Patches , Richard Guenther MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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, currently we ICE when attempting to devirtualize a call to a virtual method introduced in a descendant but with a base which is an ancestor which does not have it. This is because fold_ctor_reference returns constant zero when it cannot find the particular value in the provided constructor which is something gimple_get_virt_method_for_binfo cannot cope with. The patch below avoids it by simply testing for that value and bailing out. Bootstrapped and tested on x86_64-linux, OK for trunk? Thanks, Martin 2012-04-12 Martin Jambor PR middle-end/52939 * gimple-fold.c (gimple_get_virt_method_for_binfo): Bail out if fold_ctor_reference returns a zero constant. * testsuite/g++.dg/ipa/pr52939.C: New test. Index: src/gcc/gimple-fold.c =================================================================== --- src.orig/gcc/gimple-fold.c +++ src/gcc/gimple-fold.c @@ -3087,7 +3087,7 @@ gimple_get_virt_method_for_binfo (HOST_W offset += token * size; fn = fold_ctor_reference (TREE_TYPE (TREE_TYPE (v)), DECL_INITIAL (v), offset, size); - if (!fn) + if (!fn || integer_zerop (fn)) return NULL_TREE; gcc_assert (TREE_CODE (fn) == ADDR_EXPR || TREE_CODE (fn) == FDESC_EXPR); Index: src/gcc/testsuite/g++.dg/ipa/pr52939.C =================================================================== --- /dev/null +++ src/gcc/testsuite/g++.dg/ipa/pr52939.C @@ -0,0 +1,58 @@ +/* Verify that we do not ICE on invalid devirtualizations (which might + be OK at run-time because never executed). */ +/* { dg-do run } */ +/* { dg-options "-O3 -fno-early-inlining -fno-inline" } */ + +extern "C" void abort (void); + +class A +{ +public: + int data; + virtual int foo (int i); +}; + +class B : public A +{ +public: + virtual int foo (int i); + virtual int bar (int i); +}; + +int A::foo (int i) +{ + return i + 1; +} + +int B::foo (int i) +{ + return i + 2; +} + +int B::bar (int i) +{ + return i + 3; +} + +static int middleman (class A *obj, int i) +{ + class B *b = (class B *) obj; + + if (i != 1) + return b->bar (i); + else + return i; +} + +int __attribute__ ((noinline,noclone)) get_input(void) +{ + return 1; +} + +int main (int argc, char *argv[]) +{ + class A o; + if (middleman (&o, get_input ()) != 1) + abort (); + return 0; +}