From patchwork Thu Mar 13 15:56:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 329994 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 61FCE2C00AF for ; Fri, 14 Mar 2014 02:56:24 +1100 (EST) 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=vCc+XnAr3AHXjJRCS3hP+p8BBryaEVnsQ9/CMy5AQBiCVV6hXyDL2 baIlImT5/PsQ+GAAtjfvreBGi9q2Jr+MdFkXPZi91X791JYdfvAFz63UeQVgzhof Y8dY4uax1v4RD8Hl0b+Zc1XsjYt5JkEzUrkUaZx1Y2L9OO5i2PryG8= 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=cXfumdnUe2pq0SVJV/p/47wYhgk=; b=J5BTDUrun0GEYk/0K8fj WCFPQkHP6wHkwhId7+1hSIePCO1m/u1F7ir8Ybgj/txi0RAu5R5VRyuf6QuJS1r7 N0xyO+OIPMia14pMKCJ1XazLriTaoospzlldHDbxHkxngMM2wW1wkHlruRMz4LDh LH5yfEpzKfY+IdgpbZZsZ0c= Received: (qmail 7381 invoked by alias); 13 Mar 2014 15:56:17 -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 7371 invoked by uid 89); 13 Mar 2014 15:56:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.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; Thu, 13 Mar 2014 15:56:16 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DAF5975016 for ; Thu, 13 Mar 2014 15:56:12 +0000 (UTC) Date: Thu, 13 Mar 2014 16:56:12 +0100 From: Martin Jambor To: GCC Patches Subject: [PATCH, PR 60461] Fix loop condition at the end of ipa_modify_call_arguments Message-ID: <20140313155612.GF19304@virgil.suse> Mail-Followup-To: GCC Patches MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, the reference re-building part of ipa_modify_call_arguments has a stupid bug in the while loop condition, which means it does not look at statements produced by force_gimple_operand_gsi which may lead to bugs such as PR 60461. The 4.8 branch does not have this code and does not exhibit the bug so for th time being I'm leaving the code alone there. I have bootstrapped and tested the following patch on x86_64-linux on trunk and will commit it there shortly as obvious. Thanks, Martin 2014-03-13 Martin Jambor PR lto/60461 * ipa-prop.c (ipa_modify_call_arguments): Fix iteration condition. testsuite/ * gcc.dg/lto/pr60461_0.c: New test. diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 4fb916a..efe8c7a 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -3901,7 +3901,7 @@ ipa_modify_call_arguments (struct cgraph_edge *cs, gimple stmt, gsi_prev (&gsi); } while ((gsi_end_p (prev_gsi) && !gsi_end_p (gsi)) - || (!gsi_end_p (prev_gsi) && gsi_stmt (gsi) == gsi_stmt (prev_gsi))); + || (!gsi_end_p (prev_gsi) && gsi_stmt (gsi) != gsi_stmt (prev_gsi))); } /* If the expression *EXPR should be replaced by a reduction of a parameter, do diff --git a/gcc/testsuite/gcc.dg/lto/pr60461_0.c b/gcc/testsuite/gcc.dg/lto/pr60461_0.c new file mode 100644 index 0000000..cad6a8d --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr60461_0.c @@ -0,0 +1,37 @@ +/* { dg-lto-do link } */ +/* { dg-lto-options {{-Os -flto} } } */ + + +struct S +{ + int f1; + int f2; +} a[1] = { {0, 0} }; + +int b, c; + +static unsigned short fn1 (struct S); + +void +fn2 () +{ + for (; c;) + ; + b = 0; + fn1 (a[0]); +} + +unsigned short +fn1 (struct S p) +{ + if (p.f1) + fn2 (); + return 0; +} + +int +main () +{ + fn2 (); + return 0; +}