From patchwork Tue Aug 9 16:16:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 657378 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s7zvP5Rnjz9t1L for ; Wed, 10 Aug 2016 02:17:21 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=NyvlxK0f; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=VI8eAc9zglZvlsMqipJNQU/YUFa/66gz0+cq0PMlsmgqHZfJDKEaF QbKy8UfAJQkA4b3TsRAVhAhVHq5hLWj/aq6PykNHvqr4qV2JPUZzFE58lRAn/LaP NWBYp/LVf8ZQdZlE1AVMhU7K7VCxfm71FoP4EpPtKjyQHXfFkE3GGI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=+uLeCQ66kng5C3JFFtcaENLzAxE=; b=NyvlxK0foXdk0nYySu9I MYD7RS9TdYzu4BJlR/lPHByy7M1mQmGfbIVwaUyu/UGfbafUbmkPCPOCiJGrWr3H KcRa7yKmPrUXMOIEARNiy2vNSof/IfuUtYLcDKO7GBeqCn4L405xUCs+zEJbqIr8 8JiQ4VGeL3zPrlu5zTJvq68= Received: (qmail 32459 invoked by alias); 9 Aug 2016 16:17:13 -0000 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 Received: (qmail 32418 invoked by uid 89); 9 Aug 2016 16:17:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=16696, 1669, 6, our X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Tue, 09 Aug 2016 16:17:02 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 79857AAEF for ; Tue, 9 Aug 2016 16:16:59 +0000 (UTC) Date: Tue, 9 Aug 2016 18:16:59 +0200 From: Martin Jambor To: GCC Patches Subject: [PR ipa/71981] Make get_dynamic_type grok MEM_REF Message-ID: <20160809161659.56tqv6dc5rkgd5gw@virgil.suse.cz> Mail-Followup-To: GCC Patches MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.2-neo (2016-06-11) X-IsSubscribed: yes Hi, in the PR ipa_polymorphic_call_context::get_dynamic_type hits an assert when it tries to figure out dynamic type changes in sequence: _3 = MEM[(char * *)""]; fn1.isra.0 (_3); and gets the MEM_REF as its instance parameter. This patch makes it bail out early instead. Pre-approved by Honza on IRC, I have committed it to the trunk and the gcc-6-branch after bootstrapping and testing it on both. Thanks, Martin 2016-08-09 Martin Jambor PR ipa/71981 * ipa-polymorphic-call.c (get_dynamic_type): Bail out gracefully if instance is a MEM_REF. testsuite/ PR ipa/71981 * gcc.dg/ipa/pr71981.c: New test. diff --git a/gcc/ipa-polymorphic-call.c b/gcc/ipa-polymorphic-call.c index 56f3344..f7ef6aa 100644 --- a/gcc/ipa-polymorphic-call.c +++ b/gcc/ipa-polymorphic-call.c @@ -1544,6 +1544,11 @@ ipa_polymorphic_call_context::get_dynamic_type (tree instance, if (!maybe_in_construction && !maybe_derived_type) return false; + /* If we are in fact not looking at any object object or the instance is + some placement new into a random load, give up straight away. */ + if (TREE_CODE (instance) == MEM_REF) + return false; + /* We need to obtain refernce to virtual table pointer. It is better to look it up in the code rather than build our own. This require bit of pattern matching, but we end up verifying that what we found is @@ -1664,7 +1669,6 @@ ipa_polymorphic_call_context::get_dynamic_type (tree instance, tci.offset = instance_offset; tci.instance = instance; tci.vtbl_ptr_ref = instance_ref; - gcc_assert (TREE_CODE (instance) != MEM_REF); tci.known_current_type = NULL_TREE; tci.known_current_offset = 0; tci.otr_type = otr_type; diff --git a/gcc/testsuite/gcc.dg/ipa/pr71981.c b/gcc/testsuite/gcc.dg/ipa/pr71981.c new file mode 100644 index 0000000..1b21602 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr71981.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -w" } */ + +int **a; +static void fn1(char **p1) { + char s = *p1, b = &s; + while (*fn2()[a]) + ; +} +int main() { fn1(""); return 0; }