From patchwork Wed Jan 26 19:34:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 80543 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 DF47DB7124 for ; Thu, 27 Jan 2011 06:34:43 +1100 (EST) Received: (qmail 4232 invoked by alias); 26 Jan 2011 19:34:42 -0000 Received: (qmail 4102 invoked by uid 22791); 26 Jan 2011 19:34:41 -0000 X-SWARE-Spam-Status: No, hits=-6.4 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; Wed, 26 Jan 2011 19:34:35 +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.13.8/8.13.8) with ESMTP id p0QJYPrQ003487 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 Jan 2011 14:34:25 -0500 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 p0QJYOi6020210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 26 Jan 2011 14:34:25 -0500 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 p0QJYNcX013282; Wed, 26 Jan 2011 20:34:23 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p0QJYN48013281; Wed, 26 Jan 2011 20:34:23 +0100 Date: Wed, 26 Jan 2011 20:34:22 +0100 From: Jakub Jelinek To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix interpret_float on imaginary with -std=c99 and excess precision (PR c/47473) Message-ID: <20110126193422.GJ2724@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! For 1.0iF interpret_float was incorrectly returning EXCESS_PRECISION_EXPR with type float instead of _Complex float (with correct subexpression COMPLEX_EXPR with _Complex long double type). This bug confused later on other parts of the FE (e.g. in an expression containing a scalar on one side and this complex on another side none of the type codes were COMPLEX_TYPE). Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-01-26 Jakub Jelinek PR c/47473 * c-lex.c (interpret_float): If CPP_N_IMAGINARY, ensure EXCESS_PRECISION_EXPR is created with COMPLEX_TYPE instead of REAL_TYPE. * gcc.dg/torture/pr47473.c: New test. Jakub --- gcc/c-family/c-lex.c.jj 2010-12-02 13:14:58.000000000 +0100 +++ gcc/c-family/c-lex.c 2011-01-26 15:57:07.750402034 +0100 @@ -752,8 +752,15 @@ interpret_float (const cpp_token *token, /* Create a node with determined type and value. */ value = build_real (const_type, real); if (flags & CPP_N_IMAGINARY) - value = build_complex (NULL_TREE, convert (const_type, integer_zero_node), - value); + { + value = build_complex (NULL_TREE, convert (const_type, + integer_zero_node), value); + if (type != const_type) + { + const_type = TREE_TYPE (value); + type = build_complex_type (type); + } + } if (type != const_type) value = build1 (EXCESS_PRECISION_EXPR, type, value); --- gcc/testsuite/gcc.dg/torture/pr47473.c.jj 2011-01-26 16:11:55.255764078 +0100 +++ gcc/testsuite/gcc.dg/torture/pr47473.c 2011-01-26 16:14:08.537651972 +0100 @@ -0,0 +1,14 @@ +/* PR c/47473 */ +/* { dg-do run } */ +/* { dg-options "-std=c99" } */ + +int +main (void) +{ + long double _Complex w = 0.2L - 0.3iL; + w = w * (0.3L - (0.0F + 1.0iF) * 0.9L); + if (__builtin_fabsl (__real__ w + 0.21L) > 0.001L + || __builtin_fabsl (__imag__ w + 0.27L) > 0.001L) + __builtin_abort (); + return 0; +}