From patchwork Tue Oct 14 17:07:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 399506 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 96BCC14011B for ; Wed, 15 Oct 2014 04:08:01 +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:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=j+DksuawKc/ud4Pna t/x+MlFqPlZg2sP+2aGp17Hk5gev5q3sOJMoDaTIteN8SZhcXTR3Md8TF7vJj9fP QO5P+rV2Vo+DfyMEeNAjvYZxkQxA9xOrvDyQMOMqig8dVZgHqQDdFI35gcYG/XEC wQWqdYslQP6vhVBJaLzhdXymjo= 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:references:mime-version :content-type:in-reply-to; s=default; bh=9Q5ONhia3Hw+O9cIjSjO9yq YnOY=; b=yYWNsLDM4xOXvMweyp34DJOp7q7pEsoboyXqxE6iV/QuS419f6fhxov T/77jSUQMIiyBfKz86z358phDV7Ihu7udP085gpkdlECGp6ncjWM5SscjgZApRrO eP+asim9MsFfAI9aC6KGcmp5hW5t817na8VOm4QiuIZ9gNER6j4k= Received: (qmail 840 invoked by alias); 14 Oct 2014 17:07:55 -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 831 invoked by uid 89); 14 Oct 2014 17:07:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 14 Oct 2014 17:07:53 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 22B3811615B; Tue, 14 Oct 2014 13:07:51 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 0U8fof5aGNGr; Tue, 14 Oct 2014 13:07:51 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id E880311614F; Tue, 14 Oct 2014 13:07:50 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 0E00840DC3; Tue, 14 Oct 2014 10:07:51 -0700 (PDT) Date: Tue, 14 Oct 2014 10:07:51 -0700 From: Joel Brobecker To: Iain Buclaw Cc: Ian Lance Taylor , gcc-patches Subject: Re: [PATCH] Add D demangling support to libiberty Message-ID: <20141014170751.GG4805@adacore.com> References: <20141014141244.GA17173@adacore.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) > I've just seen this, so I'll repeat what I've said in gdb patches too. > > The call to strtold is only needed to decode templates which have a > floating point value encoded inside. This value may or may not have a > greater than double precision. > > Replacing long double with double will be fine with me. I'll accept > that I didn't consider legacy in hindsight, and in reality it would be > rather rare to stumble upon the need for strtold. Attached is a patch that switches it to strtod. Do you have any test that could quickly verify it? That seems to be the best approach, at least short-term. Later on, if we do want to use higher precision, we can indeed add strtold in libiberty. libiberty/ChangeLog: * d-demangle.c: Replace strtold with strtod in global comment. (strtold): Remove declaration. (strtod): New declaration. (dlang_parse_real): Declare value as double instead of long double. Replace call to strtold by call to strtod. Update format in call to snprintf. I verified that the patch allows GDB to build on both sparc-solaris and x86_64-linux. Thanks, From 99f9794c6d2f4dabed0bbcf2cf362b1eb25ee2a7 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Tue, 14 Oct 2014 12:47:43 -0400 Subject: [PATCH] Use strtod instead of strtold in libiberty/d-demangle.c strtold is currently used to decode templates which have a floating-point value encoded inside; but this routine is not available on some systems, such as Solaris 2.9 for instance. This patch fixes the issue by replace the use of strtold by strtod. It reduces a bit the precision, but it should still remain acceptable in most cases. libiberty/ChangeLog: * d-demangle.c: Replace strtold with strtod in global comment. (strtold): Remove declaration. (strtod): New declaration. (dlang_parse_real): Declare value as double instead of long double. Replace call to strtold by call to strtod. Update format in call to snprintf. --- libiberty/d-demangle.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c index d31bf94..bb481c0 100644 --- a/libiberty/d-demangle.c +++ b/libiberty/d-demangle.c @@ -28,7 +28,7 @@ If not, see . */ /* This file exports one function; dlang_demangle. - This file imports strtol and strtold for decoding mangled literals. */ + This file imports strtol and strtod for decoding mangled literals. */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -44,7 +44,7 @@ If not, see . */ #include #else extern long strtol (const char *nptr, char **endptr, int base); -extern long double strtold (const char *nptr, char **endptr); +extern double strtod (const char *nptr, char **endptr); #endif #include @@ -810,7 +810,7 @@ dlang_parse_real (string *decl, const char *mangled) { char buffer[64]; int len = 0; - long double value; + double value; char *endptr; /* Handle NAN and +-INF. */ @@ -877,12 +877,12 @@ dlang_parse_real (string *decl, const char *mangled) /* Convert buffer from hexadecimal to floating-point. */ buffer[len] = '\0'; - value = strtold (buffer, &endptr); + value = strtod (buffer, &endptr); if (endptr == NULL || endptr != (buffer + len)) return NULL; - len = snprintf (buffer, sizeof(buffer), "%#Lg", value); + len = snprintf (buffer, sizeof(buffer), "%#g", value); string_appendn (decl, buffer, len); return mangled; } -- 1.7.9.5