From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29301 invoked by alias); 31 Oct 2007 05:38:04 -0000 Received: (qmail 29292 invoked by uid 22791); 31 Oct 2007 05:38:04 -0000 X-Spam-Check-By: sourceware.org Received: from mx10.gnu.org (HELO mx10.gnu.org) (199.232.76.166) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 31 Oct 2007 05:38:02 +0000 Received: from e23smtp02.au.ibm.com ([202.81.18.163]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1In6H5-0003y9-6E for gcc-patches@gcc.gnu.org; Wed, 31 Oct 2007 01:38:00 -0400 Received: from sd0109e.au.ibm.com (d23rh905.au.ibm.com [202.81.18.225]) by e23smtp02.au.ibm.com (8.13.1/8.13.1) with ESMTP id l9V5abLs002002 for ; Wed, 31 Oct 2007 16:36:37 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by sd0109e.au.ibm.com (8.13.8/8.13.8/NCO v8.6) with ESMTP id l9V5eCS9266540 for ; Wed, 31 Oct 2007 16:40:13 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id l9V5aVuF003258 for ; Wed, 31 Oct 2007 16:36:31 +1100 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.190.163.12]) by d23av02.au.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id l9V5aUpt003013; Wed, 31 Oct 2007 16:36:31 +1100 Received: from [9.185.129.148] (WECM00-9-185-129-148.au.ibm.com [9.185.129.148]) (using SSLv3 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.au.ibm.com (Postfix) with ESMTP id 8BCB47350D; Wed, 31 Oct 2007 16:36:23 +1100 (EST) Subject: PATCH: fix for parsing hex floats From: Ben Elliston To: gcc-patches Cc: Ulrich Weigand Content-Type: text/plain Date: Wed, 31 Oct 2007 09:09:00 -0000 Message-Id: <1193808985.5606.7.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2007-10/txt/msg01863.txt.bz2 This patch, authored by Ulrich Weigand, improves parsing of hexadecimal floating point constants on targets with various rounding modes. Tested with a bootstrap and regression testsuite run on powerpc-linux. OK for the trunk? Ben 2007-10-31 Ulrich Weigand * c-cppbuiltin.c (builtin_define_with_hex_fp_value): Depending on the default target rounding mode, the decimal string we get may convert back to a different number when read back by the parser. Try to remedy this. Index: c-cppbuiltin.c =================================================================== --- c-cppbuiltin.c (revision 129781) +++ c-cppbuiltin.c (working copy) @@ -840,7 +840,7 @@ builtin_define_with_hex_fp_value (const const char *fp_suffix, const char *fp_cast) { - REAL_VALUE_TYPE real; + REAL_VALUE_TYPE real, real2; char dec_str[64], buf1[256], buf2[256]; /* Hex values are really cool and convenient, except that they're @@ -856,6 +856,39 @@ builtin_define_with_hex_fp_value (const real_from_string (&real, hex_str); real_to_decimal (dec_str, &real, sizeof (dec_str), digits, 0); + /* Depending on the default target rounding mode, the decimal string + we get may convert back to a different number when read back by + the parser. Try to remedy this. */ + + real_from_string (&real2, dec_str); + real_convert (&real2, TYPE_MODE (type), &real2); + if (!real_identical (&real2, &real)) + { + char *p = dec_str; + while (ISDIGIT (*p)) + p++; + if (*p == '.') + { + p++; + while (ISDIGIT (p[1])) + p++; + } + + if (ISDIGIT (*p)) + { + while (*p == '9') + { + *p-- = '0'; + gcc_assert (p > dec_str && ISDIGIT (*p)); + } + *p = *p + 1; + } + + real_from_string (&real2, dec_str); + real_convert (&real2, TYPE_MODE (type), &real2); + } + gcc_assert (real_identical (&real2, &real)); + /* Assemble the macro in the following fashion macro = fp_cast [dec_str fp_suffix] */ sprintf (buf1, "%s%s", dec_str, fp_suffix);