From patchwork Wed Jan 22 21:04:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 313418 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 6FF072C00AE for ; Thu, 23 Jan 2014 08:04:46 +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:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=tDfkFZpyH+abGo0azurYjX5BnuHIr7c4jpC9VoKdy4PuuMXH7W PTgayRAwUmmzPhRoBg+MEebZpilhIjSiBIMFFK9AB62Ee70GoiTuvthsYNKTeJmT Kb0Vupm/GGPuKsj0fdMdsRaXo5bORq5kFYzvRYbh/KBjPbb1AfLfh1p2g= 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:cc:subject:message-id:mime-version:content-type; s= default; bh=oVTy1szDWlNJt8iIs4LHiZKw4U8=; b=SzlMX4dA/1UX3k6jt8z6 mF1aSG3h14AWvIvE0+gZkQ1KrR+9OfDYSsFC2M7n5agTEy3s4HRj2IlSoUR9FXe2 lkVPNLxWhETmqM35M8xloutshKwzegbmoOcJwKuaP3QTw7yK6EtbrEstNhOQqlmq DUZMi/DcjqBPb/YKRIbJd+E= Received: (qmail 2350 invoked by alias); 22 Jan 2014 21:04:19 -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 2272 invoked by uid 89); 22 Jan 2014 21:04:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPAM_BODY1, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Jan 2014 21:04:18 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0ML4FFj031309 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 22 Jan 2014 16:04:16 -0500 Received: from redhat.com (ovpn-116-19.ams2.redhat.com [10.36.116.19]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s0ML4BtH031010 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 22 Jan 2014 16:04:14 -0500 Date: Wed, 22 Jan 2014 22:04:11 +0100 From: Marek Polacek To: gcc-patches@gcc.gnu.org Cc: Jakub Jelinek , "Joseph S. Myers" Subject: [C PATCH] Don't leak C_MAYBE_CONST_EXPRs into GIMPLE (PR c/59891) Message-ID: <20140122210410.GU8907@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) As mentioned in the PR, C FE leaked C_MAYBE_CONST_EXPR into GIMPLE. This happened because remove_c_maybe_const_expr doesn't look for nested C_MAYBE_CONST_EXPRs. But c_fully_fold will fold these away, so use that. Regtested/bootstrapped on x86_64-linux, ok for trunk and 4.8? Alternatively, we could in if (int_operands) look at op1/op2, and call c_fully_fold only if C_MAYBE_CONST_EXPR isn't the top level expression. 2014-01-22 Marek Polacek PR c/59891 c/ * c-typeck.c (build_conditional_expr): Call c_fully_fold instead of remove_c_maybe_const_expr on op1 and op2. testsuite/ * gcc.dg/torture/pr59891.c: New test. Marek --- gcc/c/c-typeck.c.mp3 2014-01-22 18:47:36.812358319 +0100 +++ gcc/c/c-typeck.c 2014-01-22 18:45:10.298692933 +0100 @@ -4708,8 +4708,10 @@ build_conditional_expr (location_t colon { if (int_operands) { - op1 = remove_c_maybe_const_expr (op1); - op2 = remove_c_maybe_const_expr (op2); + /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be + nested inside of the expression. */ + op1 = c_fully_fold (op1, false, NULL); + op2 = c_fully_fold (op2, false, NULL); } ret = build3 (COND_EXPR, result_type, ifexp, op1, op2); if (int_operands) --- gcc/testsuite/gcc.dg/torture/pr59891.c.mp3 2014-01-22 19:16:34.000000000 +0100 +++ gcc/testsuite/gcc.dg/torture/pr59891.c 2014-01-22 19:19:23.996129684 +0100 @@ -0,0 +1,9 @@ +/* PR c/59891 */ + +unsigned int a; + +int +main () +{ + return (0 ? a : 0) ? : 0 % 0; /* { dg-warning "division by zero" } */ +}