From: Alexandre Oliva <aoliva@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sources.redhat.com
Subject: Re: fixes for type-punning warnings in GCC 4.1
Date: Wed, 08 Feb 2006 03:35:00 -0000 [thread overview]
Message-ID: <oru0bazhuc.fsf@livre.oliva.athome.lsd.ic.unicamp.br> (raw)
In-Reply-To: <20060122203323.GC27224@nevyn.them.org> (Daniel Jacobowitz's message of "Sun, 22 Jan 2006 15:33:23 -0500")
[-- Attachment #1: Type: text/plain, Size: 330 bytes --]
On Jan 22, 2006, Daniel Jacobowitz <drow@false.org> wrote:
> The output is always a DOUBLEST. I don't know of any reason why we
> should enable HAVE_LONG_DOUBLE if we can't printf and scanf them; would
> this be simpler in that case? Don't make DOUBLEST something we can't
> scan or print.
Sounds good to me. Ok to install?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gdb-type-punning-3.patch --]
[-- Type: text/x-patch, Size: 7155 bytes --]
Index: gdb/c-exp.y
===================================================================
--- gdb/c-exp.y.orig 2006-02-08 00:09:27.000000000 -0200
+++ gdb/c-exp.y 2006-02-08 00:19:55.000000000 -0200
@@ -1080,24 +1080,8 @@ parse_number (p, len, parsed_float, puti
char saved_char = p[len];
p[len] = 0; /* null-terminate the token */
-
- if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
- num = sscanf (p, "%g%s", (float *) &putithere->typed_val_float.dval,s);
- else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
- num = sscanf (p, "%lg%s", (double *) &putithere->typed_val_float.dval,s);
- else
- {
-#ifdef SCANF_HAS_LONG_DOUBLE
- num = sscanf (p, "%Lg%s", &putithere->typed_val_float.dval,s);
-#else
- /* Scan it into a double, then assign it to the long double.
- This at least wins with values representable in the range
- of doubles. */
- double temp;
- num = sscanf (p, "%lg%s", &temp,s);
- putithere->typed_val_float.dval = temp;
-#endif
- }
+ num = sscanf (p, DOUBLEST_FORMAT "%s",
+ &putithere->typed_val_float.dval, s);
p[len] = saved_char; /* restore the input stream */
if (num == 1)
Index: gdb/jv-exp.y
===================================================================
--- gdb/jv-exp.y.orig 2006-02-08 00:09:27.000000000 -0200
+++ gdb/jv-exp.y 2006-02-08 00:20:43.000000000 -0200
@@ -713,23 +713,8 @@ parse_number (p, len, parsed_float, puti
char saved_char = p[len];
p[len] = 0; /* null-terminate the token */
- if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
- num = sscanf (p, "%g%c", (float *) &putithere->typed_val_float.dval, &c);
- else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
- num = sscanf (p, "%lg%c", (double *) &putithere->typed_val_float.dval, &c);
- else
- {
-#ifdef SCANF_HAS_LONG_DOUBLE
- num = sscanf (p, "%Lg%c", &putithere->typed_val_float.dval, &c);
-#else
- /* Scan it into a double, then assign it to the long double.
- This at least wins with values representable in the range
- of doubles. */
- double temp;
- num = sscanf (p, "%lg%c", &temp, &c);
- putithere->typed_val_float.dval = temp;
-#endif
- }
+ num = sscanf (p, DOUBLEST_FORMAT "%c",
+ &putithere->typed_val_float.dval, &c);
p[len] = saved_char; /* restore the input stream */
if (num != 1) /* check scanf found ONLY a float ... */
return ERROR;
Index: gdb/objc-exp.y
===================================================================
--- gdb/objc-exp.y.orig 2006-02-08 00:09:28.000000000 -0200
+++ gdb/objc-exp.y 2006-02-08 00:32:57.000000000 -0200
@@ -1025,23 +1025,8 @@ parse_number (p, len, parsed_float, puti
/* It's a float since it contains a point or an exponent. */
- if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
- sscanf (p, "%g", (float *)&putithere->typed_val_float.dval);
- else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
- sscanf (p, "%lg", (double *)&putithere->typed_val_float.dval);
- else
- {
-#ifdef PRINTF_HAS_LONG_DOUBLE
- sscanf (p, "%Lg", &putithere->typed_val_float.dval);
-#else
- /* Scan it into a double, then assign it to the long double.
- This at least wins with values representable in the range
- of doubles. */
- double temp;
- sscanf (p, "%lg", &temp);
- putithere->typed_val_float.dval = temp;
-#endif
- }
+ sscanf (p, DOUBLEST_FORMAT "%c",
+ &putithere->typed_val_float.dval, &c);
/* See if it has `f' or `l' suffix (float or long double). */
Index: gdb/p-exp.y
===================================================================
--- gdb/p-exp.y.orig 2006-02-08 00:09:28.000000000 -0200
+++ gdb/p-exp.y 2006-02-08 00:21:34.000000000 -0200
@@ -799,23 +799,8 @@ parse_number (p, len, parsed_float, puti
char saved_char = p[len];
p[len] = 0; /* null-terminate the token */
- if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
- num = sscanf (p, "%g%c", (float *) &putithere->typed_val_float.dval,&c);
- else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
- num = sscanf (p, "%lg%c", (double *) &putithere->typed_val_float.dval,&c);
- else
- {
-#ifdef SCANF_HAS_LONG_DOUBLE
- num = sscanf (p, "%Lg%c", &putithere->typed_val_float.dval,&c);
-#else
- /* Scan it into a double, then assign it to the long double.
- This at least wins with values representable in the range
- of doubles. */
- double temp;
- num = sscanf (p, "%lg%c", &temp,&c);
- putithere->typed_val_float.dval = temp;
-#endif
- }
+ num = sscanf (p, DOUBLEST_FORMAT "%c",
+ &putithere->typed_val_float.dval, &c);
p[len] = saved_char; /* restore the input stream */
if (num != 1) /* check scanf found ONLY a float ... */
return ERROR;
Index: gdb/tui/tui-data.c
===================================================================
--- gdb/tui/tui-data.c.orig 2006-02-08 00:09:28.000000000 -0200
+++ gdb/tui/tui-data.c 2006-02-08 00:14:13.000000000 -0200
@@ -44,7 +44,13 @@ static int term_height, term_width;
static struct tui_gen_win_info _locator;
static struct tui_gen_win_info exec_info[2];
static struct tui_win_info * src_win_list[2];
-static struct tui_list source_windows = {(void **) src_win_list, 0};
+/* The intermediate cast to void* silences a type-punning warning
+ issued by GCC. The use appears to be safe, since we always access
+ source_windows.list with type void**, and whenever we access one of
+ the list members, we cast it to struct tui_win_info*. The
+ interface of struct tui_list should probably be redesigned with
+ less type opacity to avoid type punning. -aoliva */
+static struct tui_list source_windows = {(void **) (void *) src_win_list, 0};
static int default_tab_len = DEFAULT_TAB_LEN;
static struct tui_win_info * win_with_focus = (struct tui_win_info *) NULL;
static struct tui_layout_def layout_def =
Index: gdb/varobj.c
===================================================================
--- gdb/varobj.c.orig 2006-02-08 00:09:28.000000000 -0200
+++ gdb/varobj.c 2006-02-08 00:14:13.000000000 -0200
@@ -1374,7 +1374,7 @@ free_variable (struct varobj *var)
/* Free the expression if this is a root variable. */
if (var->root->rootvar == var)
{
- free_current_contents ((char **) &var->root->exp);
+ free_current_contents (&var->root->exp);
xfree (var->root);
}
Index: gdb/doublest.h
===================================================================
--- gdb/doublest.h.orig 2006-02-08 00:09:28.000000000 -0200
+++ gdb/doublest.h 2006-02-08 00:25:16.000000000 -0200
@@ -48,10 +48,12 @@ struct floatformat;
host's `long double'. In general, we'll probably reduce the precision of
any such values and print a warning. */
-#ifdef HAVE_LONG_DOUBLE
+#if defined HAVE_LONG_DOUBLE && defined SCANF_HAS_LONG_DOUBLE
typedef long double DOUBLEST;
+# define DOUBLEST_FORMAT "%Lg"
#else
typedef double DOUBLEST;
+# define DOUBLEST_FORMAT "%g"
#endif
extern void floatformat_to_doublest (const struct floatformat *,
[-- Attachment #3: Type: text/plain, Size: 249 bytes --]
--
Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/
Secretary for FSF Latin America http://www.fsfla.org/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}
next prev parent reply other threads:[~2006-02-08 3:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-20 19:35 Alexandre Oliva
2005-12-20 20:50 ` Eli Zaretskii
2005-12-20 21:05 ` Daniel Jacobowitz
2005-12-21 11:25 ` Eli Zaretskii
2005-12-22 3:48 ` Alexandre Oliva
2006-01-16 18:27 ` Alexandre Oliva
2006-01-22 20:33 ` Daniel Jacobowitz
2006-02-08 3:35 ` Alexandre Oliva [this message]
2006-02-08 4:59 ` Daniel Jacobowitz
2006-02-10 0:33 ` Alexandre Oliva
2006-02-10 1:39 ` Daniel Jacobowitz
2006-02-13 18:58 ` Alexandre Oliva
2006-02-13 20:13 ` Mark Kettenis
2006-02-13 20:19 ` Daniel Jacobowitz
2006-02-08 5:58 ` Alexandre Oliva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=oru0bazhuc.fsf@livre.oliva.athome.lsd.ic.unicamp.br \
--to=aoliva@redhat.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox