From patchwork Thu Oct 14 15:51:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 67835 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 86587B70E2 for ; Fri, 15 Oct 2010 02:51:37 +1100 (EST) Received: (qmail 24093 invoked by alias); 14 Oct 2010 15:51:33 -0000 Received: (qmail 24080 invoked by uid 22791); 14 Oct 2010 15:51:32 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Oct 2010 15:51:23 +0000 Received: (qmail 15554 invoked from network); 14 Oct 2010 15:51:21 -0000 Received: from unknown (HELO digraph.polyomino.org.uk) (joseph@127.0.0.2) by mail.codesourcery.com with ESMTPA; 14 Oct 2010 15:51:21 -0000 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.69) (envelope-from ) id 1P6Q5B-0000pX-Mb for gcc-patches@gcc.gnu.org; Thu, 14 Oct 2010 15:51:06 +0000 Date: Thu, 14 Oct 2010 15:51:05 +0000 (UTC) From: "Joseph S. Myers" To: gcc-patches@gcc.gnu.org Subject: Fix PR c/45969 (excess precision regression) Message-ID: MIME-Version: 1.0 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 This patch fixes PR 45969, a regression caused by the C excess precision changes where build_binary_op tried to compute a semantic type for a boolean operation on floating-point values when it should just have let the semantic type be the same type, int, as that used for computing the result. I think boolean operations are the only case where this can occur; I've added an appropriate check to avoid computing a semantic type in this case. Bootstrapped with no regressions on i686-pc-linux-gnu. Applied to mainline. Will apply to 4.5 branch subject to testing there. 2010-10-14 Joseph Myers PR c/45969 * c-typeck.c (build_binary_op): Don't try to compute a semantic type with excess precision for boolean operations. testsuite: 2010-10-14 Joseph Myers PR c/45969 * gcc.c-torture/compile/pr45969-1.c: New test. Index: gcc/c-typeck.c =================================================================== --- gcc/c-typeck.c (revision 165418) +++ gcc/c-typeck.c (working copy) @@ -9423,6 +9423,10 @@ build_binary_op (location_t location, en precision. */ bool may_need_excess_precision; + /* True means this is a boolean operation that converts both its + operands to truth-values. */ + bool boolean_op = false; + if (location == UNKNOWN_LOCATION) location = input_location; @@ -9650,6 +9654,7 @@ build_binary_op (location_t location, en op0 = c_common_truthvalue_conversion (location, op0); op1 = c_common_truthvalue_conversion (location, op1); converted = 1; + boolean_op = true; } if (code == TRUTH_ANDIF_EXPR) { @@ -10192,7 +10197,8 @@ build_binary_op (location_t location, en if (build_type == NULL_TREE) { build_type = result_type; - if (type0 != orig_type0 || type1 != orig_type1) + if ((type0 != orig_type0 || type1 != orig_type1) + && !boolean_op) { gcc_assert (may_need_excess_precision && common); semantic_result_type = c_common_type (orig_type0, orig_type1); Index: gcc/testsuite/gcc.c-torture/compile/pr45969-1.c =================================================================== --- gcc/testsuite/gcc.c-torture/compile/pr45969-1.c (revision 0) +++ gcc/testsuite/gcc.c-torture/compile/pr45969-1.c (revision 0) @@ -0,0 +1,6 @@ +/* { dg-options "-std=c89" } */ +void crash() { + double l[4]; + if((l[0]+l[2]) && (l[1]+l[3])){ + } +}