From patchwork Sat Apr 23 06:36:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 92604 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 72ABAB6FD1 for ; Sat, 23 Apr 2011 16:36:58 +1000 (EST) Received: (qmail 10103 invoked by alias); 23 Apr 2011 06:36:55 -0000 Received: (qmail 9957 invoked by uid 22791); 23 Apr 2011 06:36:54 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 23 Apr 2011 06:36:31 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3N6aUkb003533 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 23 Apr 2011 02:36:30 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p3N6aTWX029935 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 23 Apr 2011 02:36:30 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p3N6aTBi013089 for ; Sat, 23 Apr 2011 08:36:29 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p3N6aTFT013086 for gcc-patches@gcc.gnu.org; Sat, 23 Apr 2011 08:36:29 +0200 Date: Sat, 23 Apr 2011 08:36:29 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up fold_convert_loc for MODIFY_EXPR converted to void (PR c/48685) Message-ID: <20110423063629.GB17079@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek 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! Roger changed fold_convert* back in 2007 to not actually convert to void GIMPLE_MODIFY_STMT: http://gcc.gnu.org/ml/gcc-patches/2007-01/msg00279.html as GIMPLE_MODIFY_STMT didn't have TREE_TYPE and thus converting it to void has been difficult. That == GIMPLE_MODIFY_STMT check has been changed into == MODIFY_EXPR during real tuplification apparently, but MODIFY_EXPR has a type and can be converted to void_type_node type just fine. Not doing so breaks e.g. following testcase, because fold_convert_loc (void_type_node, modify_expr); doesn't actually yield a void_type_node tree and if it is inside of NON_LVALUE_EXPR with void type, the NON_LVALUE_EXPR won't be removed. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.6? 2011-04-23 Jakub Jelinek PR c/48685 * fold-const.c (fold_convert_loc): Add NOP_EXPR when casting to VOID_TYPE even around MODIFY_EXPR. * gcc.dg/pr48685.c: New test. Jakub --- gcc/fold-const.c.jj 2011-04-18 11:28:05.000000000 +0200 +++ gcc/fold-const.c 2011-04-22 21:21:51.000000000 +0200 @@ -2029,8 +2029,6 @@ fold_convert_loc (location_t loc, tree t case VOID_TYPE: tem = fold_ignored_result (arg); - if (TREE_CODE (tem) == MODIFY_EXPR) - goto fold_convert_exit; return fold_build1_loc (loc, NOP_EXPR, type, tem); default: --- gcc/testsuite/gcc.dg/pr48685.c.jj 2011-04-22 21:24:01.000000000 +0200 +++ gcc/testsuite/gcc.dg/pr48685.c 2011-04-22 21:24:14.000000000 +0200 @@ -0,0 +1,11 @@ +/* PR c/48685 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int +main () +{ + int v = 1; + (void) (1 == 2 ? (void) 0 : (v = 0)); + return v; +}