This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: fixes for type-punning warnings in GCC 4.1
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Eli Zaretskii <eliz at gnu dot org>
- Cc: gdb-patches at sources dot redhat dot com
- Date: Wed, 08 Feb 2006 00:48:11 -0200
- Subject: Re: fixes for type-punning warnings in GCC 4.1
- References: <ork6e0nban.fsf@livre.oliva.athome.lsd.ic.unicamp.br> <ufyoog2mf.fsf@gnu.org> <20051219221830.GA32448@nevyn.them.org> <or1wz8gham.fsf@livre.oliva.athome.lsd.ic.unicamp.br> <20060122203323.GC27224@nevyn.them.org>
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?
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 *,
--
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}