From patchwork Sat Sep 25 21:33:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 65767 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 58F57B70CE for ; Sun, 26 Sep 2010 07:40:45 +1000 (EST) Received: (qmail 23916 invoked by alias); 25 Sep 2010 21:40:43 -0000 Received: (qmail 23906 invoked by uid 22791); 25 Sep 2010 21:40:41 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 25 Sep 2010 21:40:36 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id DBB86CB028C for ; Sat, 25 Sep 2010 23:40:33 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tb0hj5TIOTPz for ; Sat, 25 Sep 2010 23:40:33 +0200 (CEST) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id AF91CCB027D for ; Sat, 25 Sep 2010 23:40:33 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: Fix thinko in GIMPLE inliner Date: Sat, 25 Sep 2010 23:33:06 +0200 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201009252333.06163.ebotcazou@adacore.com> 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 I've attached a testcase that, when compiled with our 4.5-based compiler at -O or above, runs into a thinko in the GIMPLE inliner. However, because of new code on the mainline (mem-ref branch) and too ancient code in gigi on the 4.5 branch, it doesn't run into this thinko with FSF compilers. But the issue is latent in them too. tree-inline.c:copy_bb reads: seq_gsi = copy_gsi; /* With return slot optimization we can end up with non-gimple (foo *)&this->m, fix that here. */ if (is_gimple_assign (stmt) && gimple_assign_rhs_code (stmt) == NOP_EXPR && !is_gimple_val (gimple_assign_rhs1 (stmt))) { tree new_rhs; new_rhs = force_gimple_operand_gsi (&seq_gsi, gimple_assign_rhs1 (stmt), true, NULL, false, GSI_NEW_STMT); gimple_assign_set_rhs1 (stmt, new_rhs); id->regimplify = false; } gsi_insert_after (&seq_gsi, stmt, GSI_NEW_STMT); The problem is the first GSI_NEW_STMT because: GSI_NEW_STMT, /* Only valid when single statement is added, move iterator to it. */ so if force_gimple_operand_gsi happens to create more than one statement (this will occur when the LHS of the return statement is a VIEW_CONVERT_EXPR), the seq_gsi iterator will be moved to the first statement. As a consequence, the modified STMT will be inserted between the first and the second newly created statements, wreaking havoc in the SSA form. Fixed by using GSI_CONTINUE_LINKING instead of GSI_NEW_STMT. Bootstrapped and regtested on x86_64-suse-linux, applied on mainline and 4.5 branch as obvious. 2010-09-25 Eric Botcazou * tree-inline.c (copy_bb): Use GSI_CONTINUE_LINKING when inserting new statements because of the return slot optimization. 2010-09-25 Eric Botcazou * gnat.dg/return2.ad[sb]: New test. * gnat.dg/return2_pkg.ads: New helper. Index: tree-inline.c =================================================================== --- tree-inline.c (revision 164617) +++ tree-inline.c (working copy) @@ -1558,7 +1558,8 @@ copy_bb (copy_body_data *id, basic_block tree new_rhs; new_rhs = force_gimple_operand_gsi (&seq_gsi, gimple_assign_rhs1 (stmt), - true, NULL, false, GSI_NEW_STMT); + true, NULL, false, + GSI_CONTINUE_LINKING); gimple_assign_set_rhs1 (stmt, new_rhs); id->regimplify = false; }