Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* fixes for type-punning warnings in GCC 4.1
@ 2005-12-20 19:35 Alexandre Oliva
  2005-12-20 20:50 ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Alexandre Oliva @ 2005-12-20 19:35 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 693 bytes --]

Hi,

This patch fixes the type-punning warnings that the GCC 4.1 branch
issues when compiling the GDB code base.

The fixes for the .y files are safe, since the casts only perform a
non-identity conversion when code paths that are never taken.  The two
other cases are situations in which the use of opaque types forces us
to violate the ISO C string aliasing rules; the one in tui/tui-data.c
is safe in that we never access the affected data structures with the
wrong type.  In varobj.c that's much trickier to prove, but since it's
in a separate translation unit from the call, what we have now is no
safer than what we get after my patch.

Build-tested on amd64-linux-gnu.  Ok to install?


[-- Attachment #2: gdb-type-punning.patch --]
[-- Type: text/x-patch, Size: 5001 bytes --]

Index: gdb/ChangeLog
2005-12-19  Alexandre Oliva  <aoliva@redhat.com>

	* c-exp.y (parse_number): Silence type-punning warnings.
	* jv-exp.y (parse_number): Likewise.
	* objc-exp.y (parse_number): Likewise.
	* p-exp.y (parse_number): Likewise.
	* tui/tui-data.c (source_windows): Likewise.
	* varobj.c (free_variable): Likewise.

Index: gdb/c-exp.y
===================================================================
--- gdb/c-exp.y.orig	2005-12-19 15:07:39.000000000 -0200
+++ gdb/c-exp.y	2005-12-19 15:25:35.000000000 -0200
@@ -1082,9 +1082,9 @@
       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);
+	num = sscanf (p, "%g%s", (float *) (void *) &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);
+	num = sscanf (p, "%lg%s", (double *) (void *) &putithere->typed_val_float.dval,s);
       else
 	{
 #ifdef SCANF_HAS_LONG_DOUBLE
Index: gdb/jv-exp.y
===================================================================
--- gdb/jv-exp.y.orig	2005-12-19 15:07:41.000000000 -0200
+++ gdb/jv-exp.y	2005-12-19 15:24:53.000000000 -0200
@@ -714,9 +714,9 @@
 
       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);
+	num = sscanf (p, "%g%c", (float *) (void *) &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);
+	num = sscanf (p, "%lg%c", (double *) (void *) &putithere->typed_val_float.dval, &c);
       else
 	{
 #ifdef SCANF_HAS_LONG_DOUBLE
Index: gdb/objc-exp.y
===================================================================
--- gdb/objc-exp.y.orig	2005-12-19 15:07:45.000000000 -0200
+++ gdb/objc-exp.y	2005-12-19 15:24:53.000000000 -0200
@@ -1026,9 +1026,9 @@
       /* 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);
+	sscanf (p, "%g", (float *) (void *) &putithere->typed_val_float.dval);
       else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
-	sscanf (p, "%lg", (double *)&putithere->typed_val_float.dval);
+	sscanf (p, "%lg", (double *) (void *) &putithere->typed_val_float.dval);
       else
 	{
 #ifdef PRINTF_HAS_LONG_DOUBLE
Index: gdb/p-exp.y
===================================================================
--- gdb/p-exp.y.orig	2005-12-19 15:07:45.000000000 -0200
+++ gdb/p-exp.y	2005-12-19 15:24:53.000000000 -0200
@@ -800,9 +800,9 @@
 
       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);
+	num = sscanf (p, "%g%c", (float *) (void *) &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);
+	num = sscanf (p, "%lg%c", (double *) (void *) &putithere->typed_val_float.dval,&c);
       else
 	{
 #ifdef SCANF_HAS_LONG_DOUBLE
Index: gdb/tui/tui-data.c
===================================================================
--- gdb/tui/tui-data.c.orig	2005-12-19 15:07:52.000000000 -0200
+++ gdb/tui/tui-data.c	2005-12-19 15:24:53.000000000 -0200
@@ -44,7 +44,13 @@
 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	2005-12-19 15:07:50.000000000 -0200
+++ gdb/varobj.c	2005-12-19 15:24:53.000000000 -0200
@@ -1374,7 +1374,7 @@
   /* 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);
     }
 

[-- Attachment #3: Type: text/plain, Size: 188 bytes --]


-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2005-12-20 19:35 fixes for type-punning warnings in GCC 4.1 Alexandre Oliva
@ 2005-12-20 20:50 ` Eli Zaretskii
  2005-12-20 21:05   ` Daniel Jacobowitz
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2005-12-20 20:50 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gdb-patches

> From: Alexandre Oliva <aoliva@redhat.com>
> Date: Mon, 19 Dec 2005 17:20:48 -0200
> 
> This patch fixes the type-punning warnings that the GCC 4.1 branch
> issues when compiling the GDB code base.
> [...]
> -	num = sscanf (p, "%g%s", (float *) &putithere->typed_val_float.dval,s);
> +	num = sscanf (p, "%g%s", (float *) (void *) &putithere->typed_val_float.dval,s);

If this is the fix, then forgive me, but I'd prefer not to fix it at
all, 'cause it's so UUUGLYYYY!  If we can use some command-line switch
to GCC to shut it up, let's do that instead.  Failing that, let's just
leave the code alone, so that GCC's continued whining stands as a token
of our unappreciation to compilers that should have known better!

Thanks for working on this, anyway.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2005-12-20 20:50 ` Eli Zaretskii
@ 2005-12-20 21:05   ` Daniel Jacobowitz
  2005-12-21 11:25     ` Eli Zaretskii
  2006-01-16 18:27     ` Alexandre Oliva
  0 siblings, 2 replies; 15+ messages in thread
From: Daniel Jacobowitz @ 2005-12-20 21:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Alexandre Oliva, gdb-patches

On Tue, Dec 20, 2005 at 12:10:00AM +0200, Eli Zaretskii wrote:
> > From: Alexandre Oliva <aoliva@redhat.com>
> > Date: Mon, 19 Dec 2005 17:20:48 -0200
> > 
> > This patch fixes the type-punning warnings that the GCC 4.1 branch
> > issues when compiling the GDB code base.
> > [...]
> > -	num = sscanf (p, "%g%s", (float *) &putithere->typed_val_float.dval,s);
> > +	num = sscanf (p, "%g%s", (float *) (void *) &putithere->typed_val_float.dval,s);
> 
> If this is the fix, then forgive me, but I'd prefer not to fix it at
> all, 'cause it's so UUUGLYYYY!  If we can use some command-line switch
> to GCC to shut it up, let's do that instead.  Failing that, let's just
> leave the code alone, so that GCC's continued whining stands as a token
> of our unappreciation to compilers that should have known better!

I really can't agree; the code GCC's warning about here is pretty
disgusting to start with, and this warning is a very valuable service
of GCC for C conformance.

We should fix it properly, in any case.  The right solution here is
pretty apparent: delete the "float" case, and #define appropriate
format characters for DOUBLEST in doublest.h, in the same place we
typedef DOUBLEST.  Just like GCC's HOST_WIDE_INT_PRINT.

-- 
Daniel Jacobowitz
CodeSourcery, LLC


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  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
  1 sibling, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2005-12-21 11:25 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gdb-patches

> Date: Mon, 19 Dec 2005 17:18:30 -0500
> From: Daniel Jacobowitz <drow@false.org>
> Cc: Alexandre Oliva <aoliva@redhat.com>, gdb-patches@sources.redhat.com
> 
> On Tue, Dec 20, 2005 at 12:10:00AM +0200, Eli Zaretskii wrote:
> > > From: Alexandre Oliva <aoliva@redhat.com>
> > > Date: Mon, 19 Dec 2005 17:20:48 -0200
> > > 
> > > This patch fixes the type-punning warnings that the GCC 4.1 branch
> > > issues when compiling the GDB code base.
> > > [...]
> > > -	num = sscanf (p, "%g%s", (float *) &putithere->typed_val_float.dval,s);
> > > +	num = sscanf (p, "%g%s", (float *) (void *) &putithere->typed_val_float.dval,s);
> > 
> > If this is the fix, then forgive me, but I'd prefer not to fix it at
> > all, 'cause it's so UUUGLYYYY!  If we can use some command-line switch
> > to GCC to shut it up, let's do that instead.  Failing that, let's just
> > leave the code alone, so that GCC's continued whining stands as a token
> > of our unappreciation to compilers that should have known better!
> 
> I really can't agree; the code GCC's warning about here is pretty
> disgusting to start with, and this warning is a very valuable service
> of GCC for C conformance.

Obviously, Alexandre didn't think it was a valuable service, since he
tried to dupe GCC into not providing it ;-)

> We should fix it properly, in any case.

If we can, let's do it.

> The right solution here is pretty apparent: delete the "float" case,
> and #define appropriate format characters for DOUBLEST in
> doublest.h, in the same place we typedef DOUBLEST.

That would be good, yes.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2005-12-21 11:25     ` Eli Zaretskii
@ 2005-12-22  3:48       ` Alexandre Oliva
  0 siblings, 0 replies; 15+ messages in thread
From: Alexandre Oliva @ 2005-12-22  3:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

On Dec 19, 2005, Eli Zaretskii <eliz@gnu.org> wrote:

> Obviously, Alexandre didn't think it was a valuable service, since he
> tried to dupe GCC into not providing it ;-)

It was valuable, but the code warned about turned out to be a harmless
in this particular case, since it would never run anyway.  If it ever
got a chance to run, it would invoke undefined behavior, and possibly
lead to obscure bugs.

-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2005-12-20 21:05   ` Daniel Jacobowitz
  2005-12-21 11:25     ` Eli Zaretskii
@ 2006-01-16 18:27     ` Alexandre Oliva
  2006-01-22 20:33       ` Daniel Jacobowitz
  1 sibling, 1 reply; 15+ messages in thread
From: Alexandre Oliva @ 2006-01-16 18:27 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1293 bytes --]

On Dec 19, 2005, Daniel Jacobowitz <drow@false.org> wrote:

>> > From: Alexandre Oliva <aoliva@redhat.com>
>> > Date: Mon, 19 Dec 2005 17:20:48 -0200

>> > -	num = sscanf (p, "%g%s", (float *) &putithere->typed_val_float.dval,s);
>> > +	num = sscanf (p, "%g%s", (float *) (void *) &putithere->typed_val_float.dval,s);

> We should fix it properly, in any case.  The right solution here is
> pretty apparent: delete the "float" case, and #define appropriate
> format characters for DOUBLEST in doublest.h, in the same place we
> typedef DOUBLEST.  Just like GCC's HOST_WIDE_INT_PRINT.

We can't quite do that because we may have to issue more complex
command patterns than simply a plain sscanf into the output location.
I've come up with this macro that defers to a static inline function
in the complex case.  Is this change acceptable?  Tested on
amd64-linux-gnu.

Another alternative that I found uglier would be to define a
DOUBLEST_SCAN macro and a DOUBLEST_SCAN_TYPE typedef, and always
declare a variable of DOUBLEST_SCAN_TYPE, scan into it, and then copy
the scanned value to the given output variable.  This enables people
to construct more complex scan patterns, but is it worth the ugliness
and extra copying for the sake of the uncommon `has long double but
can't scanf it' case?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gdb-type-punning-2.patch --]
[-- Type: text/x-patch, Size: 7908 bytes --]

Index: gdb/ChangeLog
2005-12-19  Alexandre Oliva  <aoliva@redhat.com>

	* c-exp.y (parse_number): Silence type-punning warnings.
	* jv-exp.y (parse_number): Likewise.
	* objc-exp.y (parse_number): Likewise.
	* p-exp.y (parse_number): Likewise.
	* tui/tui-data.c (source_windows): Likewise.
	* varobj.c (free_variable): Likewise.

Index: gdb/c-exp.y
===================================================================
--- gdb/c-exp.y.orig	2006-01-16 15:30:39.000000000 -0200
+++ gdb/c-exp.y	2006-01-16 16:09:10.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_DOUBLEST_AND_SUFFIX (p, putithere->typed_val_float.dval,
+					"%s", s);
       p[len] = saved_char;	/* restore the input stream */
 
       if (num == 1)
Index: gdb/jv-exp.y
===================================================================
--- gdb/jv-exp.y.orig	2006-01-16 15:30:39.000000000 -0200
+++ gdb/jv-exp.y	2006-01-16 16:08:33.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_DOUBLEST_AND_SUFFIX (p, putithere->typed_val_float.dval,
+					"%c", &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-01-16 15:30:39.000000000 -0200
+++ gdb/objc-exp.y	2006-01-16 16:08:50.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_DOUBLEST_AND_SUFFIX (p, putithere->typed_val_float.dval,
+				  "%c", &c);
 
       /* See if it has `f' or `l' suffix (float or long double).  */
 
Index: gdb/p-exp.y
===================================================================
--- gdb/p-exp.y.orig	2006-01-16 15:30:39.000000000 -0200
+++ gdb/p-exp.y	2006-01-16 16:09:00.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_DOUBLEST_AND_SUFFIX (p, putithere->typed_val_float.dval,
+					"%c", &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-01-16 15:30:39.000000000 -0200
+++ gdb/tui/tui-data.c	2006-01-16 15:33:33.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-01-16 15:30:39.000000000 -0200
+++ gdb/varobj.c	2006-01-16 15:33:33.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-01-16 15:57:33.000000000 -0200
+++ gdb/doublest.h	2006-01-16 16:08:27.000000000 -0200
@@ -50,8 +50,33 @@ struct floatformat;
 
 #ifdef HAVE_LONG_DOUBLE
 typedef long double DOUBLEST;
+
+# ifdef SCANF_HAS_LONG_DOUBLE
+#  define SSCANF_DOUBLEST_AND_SUFFIX(from, val, sufspec, suf)	\
+  (sscanf ((from), "%Lg" sufspec, &(val), (suf)))
+
+# else
+#  define SSCANF_DOUBLEST_AND_SUFFIX(from, val, sufspec, suf)	\
+  (sscanf_doublest_and_suffix ((from), "%lg" sufspec, &(val), (suf)))
+static inline int
+sscanf_doublest_and_suffix (const char *from, const char *spec,
+			    DOUBLEST *valp, void *sufp)
+{
+  int result;
+  double temp;
+
+  result = sscanf (from, spec, &temp, sufp);
+
+  *valp = temp;
+
+  return result;
+}
+# endif
+
 #else
 typedef double DOUBLEST;
+# define SSCANF_DOUBLEST_AND_SUFFIX(from, val, sufspec, suf)	\
+  (sscanf ((from), "%g" sufspec, &(val), &(suf)))
 #endif
 
 extern void floatformat_to_doublest (const struct floatformat *,

[-- Attachment #3: Type: text/plain, Size: 188 bytes --]


-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2006-01-16 18:27     ` Alexandre Oliva
@ 2006-01-22 20:33       ` Daniel Jacobowitz
  2006-02-08  3:35         ` Alexandre Oliva
  0 siblings, 1 reply; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-01-22 20:33 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: Eli Zaretskii, gdb-patches

On Mon, Jan 16, 2006 at 04:26:57PM -0200, Alexandre Oliva wrote:
> On Dec 19, 2005, Daniel Jacobowitz <drow@false.org> wrote:
> 
> >> > From: Alexandre Oliva <aoliva@redhat.com>
> >> > Date: Mon, 19 Dec 2005 17:20:48 -0200
> 
> >> > -	num = sscanf (p, "%g%s", (float *) &putithere->typed_val_float.dval,s);
> >> > +	num = sscanf (p, "%g%s", (float *) (void *) &putithere->typed_val_float.dval,s);
> 
> > We should fix it properly, in any case.  The right solution here is
> > pretty apparent: delete the "float" case, and #define appropriate
> > format characters for DOUBLEST in doublest.h, in the same place we
> > typedef DOUBLEST.  Just like GCC's HOST_WIDE_INT_PRINT.
> 
> We can't quite do that because we may have to issue more complex
> command patterns than simply a plain sscanf into the output location.
> I've come up with this macro that defers to a static inline function
> in the complex case.  Is this change acceptable?  Tested on
> amd64-linux-gnu.
> 
> Another alternative that I found uglier would be to define a
> DOUBLEST_SCAN macro and a DOUBLEST_SCAN_TYPE typedef, and always
> declare a variable of DOUBLEST_SCAN_TYPE, scan into it, and then copy
> the scanned value to the given output variable.  This enables people
> to construct more complex scan patterns, but is it worth the ugliness
> and extra copying for the sake of the uncommon `has long double but
> can't scanf it' case?

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.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2006-01-22 20:33       ` Daniel Jacobowitz
@ 2006-02-08  3:35         ` Alexandre Oliva
  2006-02-08  4:59           ` Daniel Jacobowitz
  2006-02-08  5:58           ` Alexandre Oliva
  0 siblings, 2 replies; 15+ messages in thread
From: Alexandre Oliva @ 2006-02-08  3:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- 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}

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2006-02-08  3:35         ` Alexandre Oliva
@ 2006-02-08  4:59           ` Daniel Jacobowitz
  2006-02-10  0:33             ` Alexandre Oliva
  2006-02-08  5:58           ` Alexandre Oliva
  1 sibling, 1 reply; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-02-08  4:59 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: Eli Zaretskii, gdb-patches

On Wed, Feb 08, 2006 at 12:48:11AM -0200, Alexandre Oliva wrote:
> 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?

Well, it's not right as-is; you need to look at the other uses of
HAVE_LONG_DOUBLE.  It's not obviously harmful, but the long double
support code in doublest.c should match the condition on
DOUBLEST-is-long-double.

Would you mind terribly fixing that, adding a changelog, and leaving
out the tui-data change for now?  Anything that needs an explanatory
paragraph it's probably worth seeing how hard the interface fix is;
if you don't have time, I'll do it.


-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2006-02-08  3:35         ` Alexandre Oliva
  2006-02-08  4:59           ` Daniel Jacobowitz
@ 2006-02-08  5:58           ` Alexandre Oliva
  1 sibling, 0 replies; 15+ messages in thread
From: Alexandre Oliva @ 2006-02-08  5:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

On Feb  8, 2006, Alexandre Oliva <aoliva@redhat.com> wrote:

> 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?

GRR.  quilt was eating my ChangeLog entries :-( Here's what I meant to
post along with the previous patch:

for gdb/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* doublest.h (DOUBLEST): Use long double only if we can scan in.
	(DOUBLEST_FORMAT): New.
	* c-exp.y (parse_number): Use it.
	* jv-exp.y (parse_number): Likewise.
	* objc-exp.y (parse_number): Likewise.
	* p-exp.y (parse_number): Likewise.
	* tui/tui-data.c (source_windows): Silence type-punning warnings.
	* varobj.c (free_variable): Likewise.


-- 
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}


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2006-02-08  4:59           ` Daniel Jacobowitz
@ 2006-02-10  0:33             ` Alexandre Oliva
  2006-02-10  1:39               ` Daniel Jacobowitz
  0 siblings, 1 reply; 15+ messages in thread
From: Alexandre Oliva @ 2006-02-10  0:33 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

On Feb  8, 2006, Daniel Jacobowitz <drow@false.org> wrote:

> On Wed, Feb 08, 2006 at 12:48:11AM -0200, Alexandre Oliva wrote:
>> 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?

> Well, it's not right as-is; you need to look at the other uses of
> HAVE_LONG_DOUBLE.

Did.  The other uses of HAVE_LONG_DOUBLE are correct, since they do
not assume DOUBLEST is long double and they make no attempts at
printing long doubles directly.

> Would you mind terribly fixing that, adding a changelog, and leaving
> out the tui-data change for now?

gdb won't build without the tui-data change.  What's wrong with adding
the temporary fix now, such that it builds, until someone with a
better understanding can go ahead and re-engineer the data structure
correctly?

> Anything that needs an explanatory paragraph it's probably worth
> seeing how hard the interface fix is; if you don't have time, I'll
> do it.

Thanks,

-- 
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}


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2006-02-10  0:33             ` Alexandre Oliva
@ 2006-02-10  1:39               ` Daniel Jacobowitz
  2006-02-13 18:58                 ` Alexandre Oliva
  0 siblings, 1 reply; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-02-10  1:39 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: Eli Zaretskii, gdb-patches

On Thu, Feb 09, 2006 at 10:32:48PM -0200, Alexandre Oliva wrote:
> On Feb  8, 2006, Daniel Jacobowitz <drow@false.org> wrote:
> 
> > On Wed, Feb 08, 2006 at 12:48:11AM -0200, Alexandre Oliva wrote:
> >> 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?
> 
> > Well, it's not right as-is; you need to look at the other uses of
> > HAVE_LONG_DOUBLE.
> 
> Did.  The other uses of HAVE_LONG_DOUBLE are correct, since they do
> not assume DOUBLEST is long double and they make no attempts at
> printing long doubles directly.

Disagree; did you read the bit of my message that you snipped?
doublest.c jumps through unnecessary hoops casting to long double and
back to handle a DOUBLEST if this is defined.

> > Would you mind terribly fixing that, adding a changelog, and leaving
> > out the tui-data change for now?
> 
> gdb won't build without the tui-data change.  What's wrong with adding
> the temporary fix now, such that it builds, until someone with a
> better understanding can go ahead and re-engineer the data structure
> correctly?

Sorry, use -Wno-error if you're in that much of a hurry.  I even
offered to take care of it for you.  If your fix goes in, it will never
leave; we have plenty of experience with FIXMEs in GDB to back that up,
I think.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2006-02-10  1:39               ` Daniel Jacobowitz
@ 2006-02-13 18:58                 ` Alexandre Oliva
  2006-02-13 20:13                   ` Mark Kettenis
  0 siblings, 1 reply; 15+ messages in thread
From: Alexandre Oliva @ 2006-02-13 18:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 2042 bytes --]

On Feb  9, 2006, Daniel Jacobowitz <drow@false.org> wrote:

> On Thu, Feb 09, 2006 at 10:32:48PM -0200, Alexandre Oliva wrote:
>> On Feb  8, 2006, Daniel Jacobowitz <drow@false.org> wrote:
>> 
>> > On Wed, Feb 08, 2006 at 12:48:11AM -0200, Alexandre Oliva wrote:
>> >> 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?
>> 
>> > Well, it's not right as-is; you need to look at the other uses of
>> > HAVE_LONG_DOUBLE.
>> 
>> Did.  The other uses of HAVE_LONG_DOUBLE are correct, since they do
>> not assume DOUBLEST is long double and they make no attempts at
>> printing long doubles directly.

> Disagree; did you read the bit of my message that you snipped?
> doublest.c jumps through unnecessary hoops casting to long double and
> back to handle a DOUBLEST if this is defined.

Yep.  It didn't look like those two occurrences were such a big deal.
I don't see why we should refuse to handle long double at all just
because we can't scan them in as such.  But it's not my call, I guess.

>> > Would you mind terribly fixing that, adding a changelog, and leaving
>> > out the tui-data change for now?

>> gdb won't build without the tui-data change.  What's wrong with adding
>> the temporary fix now, such that it builds, until someone with a
>> better understanding can go ahead and re-engineer the data structure
>> correctly?

> Sorry, use -Wno-error if you're in that much of a hurry.  I even
> offered to take care of it for you.  If your fix goes in, it will never
> leave; we have plenty of experience with FIXMEs in GDB to back that up,
> I think.

Ok, I tried changing the type in the struct declaration and that
seems to have worked, so I went ahead and removed the now-redundant
type casts.

Ok to install?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gdb-type-punning-4.patch --]
[-- Type: text/x-patch, Size: 12346 bytes --]

for gdb/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* doublest.h (DOUBLEST): Use long double only if we can scan
	it in.  Undefine HAVE_LONG_DOUBLE otherwise.
	(DOUBLEST_FORMAT): New.
	* c-exp.y (parse_number): Use it.
	* jv-exp.y (parse_number): Likewise.
	* objc-exp.y (parse_number): Likewise.
	* p-exp.y (parse_number): Likewise.
	* varobj.c (free_variable): Silence type-punning warnings.
	* tui/tui-data.h (struct tui_list): Change type of list member.
	* tui/tui-data.c: Remove no-longer-needed type casts.
	(source_windows): Silence type-punning warnings.
	* tui/tui-stack.c, tui/tui-win.c, tui/tui-winsource.c: Likewise.

Index: gdb/c-exp.y
===================================================================
--- gdb/c-exp.y.orig	2006-02-13 16:33:29.000000000 -0200
+++ gdb/c-exp.y	2006-02-13 16:34: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-13 16:33:29.000000000 -0200
+++ gdb/jv-exp.y	2006-02-13 16:34:55.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-13 16:33:29.000000000 -0200
+++ gdb/objc-exp.y	2006-02-13 16:34:55.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-13 16:33:29.000000000 -0200
+++ gdb/p-exp.y	2006-02-13 16:34:55.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/varobj.c
===================================================================
--- gdb/varobj.c.orig	2006-02-13 16:33:29.000000000 -0200
+++ gdb/varobj.c	2006-02-13 16:34:55.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-13 16:33:29.000000000 -0200
+++ gdb/doublest.h	2006-02-13 16:34:55.000000000 -0200
@@ -48,10 +48,15 @@ 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"
+/* If we can't scan or print long double, we don't want to use it
+   anywhere.  */
+# undef HAVE_LONG_DOUBLE
 #endif
 
 extern void floatformat_to_doublest (const struct floatformat *,
Index: gdb/tui/tui-data.c
===================================================================
--- gdb/tui/tui-data.c.orig	2006-02-13 16:51:35.000000000 -0200
+++ gdb/tui/tui-data.c	2006-02-13 16:52:07.000000000 -0200
@@ -44,7 +44,7 @@ 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};
+static struct tui_list source_windows = {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 =
@@ -182,7 +182,7 @@ tui_clear_source_windows_detail (void)
   int i;
 
   for (i = 0; i < (tui_source_windows ())->count; i++)
-    tui_clear_win_detail ((struct tui_win_info *) (tui_source_windows ())->list[i]);
+    tui_clear_win_detail ((tui_source_windows ())->list[i]);
 }
 
 
@@ -782,7 +782,7 @@ tui_free_all_source_wins_content (void)
 
   for (i = 0; i < (tui_source_windows ())->count; i++)
     {
-      struct tui_win_info * win_info = (struct tui_win_info *) (tui_source_windows ())->list[i];
+      struct tui_win_info * win_info = (tui_source_windows ())->list[i];
 
       if (win_info != NULL)
 	{
Index: gdb/tui/tui-data.h
===================================================================
--- gdb/tui/tui-data.h.orig	2006-02-13 16:51:35.000000000 -0200
+++ gdb/tui/tui-data.h	2006-02-13 16:52:07.000000000 -0200
@@ -110,7 +110,7 @@ enum tui_scroll_direction
 /* General list struct.  */
 struct tui_list
 {
-  void **list;
+  struct tui_win_info **list;
   int count;
 };
 
Index: gdb/tui/tui-stack.c
===================================================================
--- gdb/tui/tui-stack.c.orig	2006-02-13 16:51:35.000000000 -0200
+++ gdb/tui/tui-stack.c	2006-02-13 16:52:07.000000000 -0200
@@ -343,7 +343,7 @@ tui_show_frame_info (struct frame_info *
       for (i = 0; i < (tui_source_windows ())->count; i++)
 	{
 	  union tui_which_element *item;
-	  win_info = (struct tui_win_info *) (tui_source_windows ())->list[i];
+	  win_info = (tui_source_windows ())->list[i];
 
 	  item = &((struct tui_win_element *) locator->content[0])->which_element;
 	  if (win_info == TUI_SRC_WIN)
@@ -401,7 +401,7 @@ tui_show_frame_info (struct frame_info *
       tui_show_locator_content ();
       for (i = 0; i < (tui_source_windows ())->count; i++)
 	{
-	  win_info = (struct tui_win_info *) (tui_source_windows ())->list[i];
+	  win_info = (tui_source_windows ())->list[i];
 	  tui_clear_source_content (win_info, EMPTY_SOURCE_PROMPT);
 	  tui_update_exec_info (win_info);
 	}
Index: gdb/tui/tui-win.c
===================================================================
--- gdb/tui/tui-win.c.orig	2006-02-13 16:51:35.000000000 -0200
+++ gdb/tui/tui-win.c	2006-02-13 16:52:07.000000000 -0200
@@ -1119,7 +1119,7 @@ tui_adjust_win_heights (struct tui_win_i
 	      make_invisible_and_set_new_height (primary_win_info, new_height);
 	      if (primary_win_info->generic.type == CMD_WIN)
 		{
-		  win_info = (struct tui_win_info *) (tui_source_windows ())->list[0];
+		  win_info = (tui_source_windows ())->list[0];
 		  src_win_info = win_info;
 		}
 	      else
@@ -1148,7 +1148,7 @@ tui_adjust_win_heights (struct tui_win_i
 	      else
 		{
 		  first_win = TUI_DATA_WIN;
-		  second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
+		  second_win = (tui_source_windows ())->list[0];
 		}
 	      if (primary_win_info == TUI_CMD_WIN)
 		{		/*
@@ -1393,7 +1393,7 @@ new_height_ok (struct tui_win_info * pri
 	      struct tui_win_info * win_info;
 
 	      if (primary_win_info == TUI_CMD_WIN)
-		win_info = (struct tui_win_info *) (tui_source_windows ())->list[0];
+		win_info = (tui_source_windows ())->list[0];
 	      else
 		win_info = TUI_CMD_WIN;
 	      ok = ((new_height +
@@ -1414,7 +1414,7 @@ new_height_ok (struct tui_win_info * pri
 	  else
 	    {
 	      first_win = TUI_DATA_WIN;
-	      second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
+	      second_win = (tui_source_windows ())->list[0];
 	    }
 	  /*
 	     ** We could simply add all the heights to obtain the same result
@@ -1543,7 +1543,7 @@ parse_scrolling_args (char *arg, struct 
 	    error (_("Invalid window specified. \n\
 The window name specified must be valid and visible.\n"));
 	  else if (*win_to_scroll == TUI_CMD_WIN)
-	    *win_to_scroll = (struct tui_win_info *) (tui_source_windows ())->list[0];
+	    *win_to_scroll = (tui_source_windows ())->list[0];
 	}
       xfree (buf);
     }
Index: gdb/tui/tui-winsource.c
===================================================================
--- gdb/tui/tui-winsource.c.orig	2006-02-13 16:51:35.000000000 -0200
+++ gdb/tui/tui-winsource.c	2006-02-13 16:52:07.000000000 -0200
@@ -160,7 +160,7 @@ tui_update_source_windows_with_addr (COR
 
       for (i = 0; i < (tui_source_windows ())->count; i++)
 	{
-	  struct tui_win_info * win_info = (struct tui_win_info *) (tui_source_windows ())->list[i];
+	  struct tui_win_info * win_info = (tui_source_windows ())->list[i];
 
 	  tui_clear_source_content (win_info, EMPTY_SOURCE_PROMPT);
 	  tui_clear_exec_info_content (win_info);
@@ -384,7 +384,7 @@ tui_update_all_breakpoint_info (void)
 
   for (i = 0; i < list->count; i++)
     {
-      struct tui_win_info * win = (struct tui_win_info *) list->list[i];
+      struct tui_win_info * win = list->list[i];
 
       if (tui_update_breakpoint_info (win, FALSE))
         {

[-- Attachment #3: Type: text/plain, Size: 250 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}

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2006-02-13 18:58                 ` Alexandre Oliva
@ 2006-02-13 20:13                   ` Mark Kettenis
  2006-02-13 20:19                     ` Daniel Jacobowitz
  0 siblings, 1 reply; 15+ messages in thread
From: Mark Kettenis @ 2006-02-13 20:13 UTC (permalink / raw)
  To: aoliva; +Cc: eliz, gdb-patches

> From: Alexandre Oliva <aoliva@redhat.com>
> Date: Mon, 13 Feb 2006 16:57:28 -0200
>
> Ok to install?

Looks ok to me.

> for gdb/ChangeLog
> from  Alexandre Oliva  <aoliva@redhat.com>
> 
> 	* doublest.h (DOUBLEST): Use long double only if we can scan
> 	it in.  Undefine HAVE_LONG_DOUBLE otherwise.
> 	(DOUBLEST_FORMAT): New.
> 	* c-exp.y (parse_number): Use it.
> 	* jv-exp.y (parse_number): Likewise.
> 	* objc-exp.y (parse_number): Likewise.
> 	* p-exp.y (parse_number): Likewise.
> 	* varobj.c (free_variable): Silence type-punning warnings.
> 	* tui/tui-data.h (struct tui_list): Change type of list member.
> 	* tui/tui-data.c: Remove no-longer-needed type casts.
> 	(source_windows): Silence type-punning warnings.
> 	* tui/tui-stack.c, tui/tui-win.c, tui/tui-winsource.c: Likewise.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: fixes for type-punning warnings in GCC 4.1
  2006-02-13 20:13                   ` Mark Kettenis
@ 2006-02-13 20:19                     ` Daniel Jacobowitz
  0 siblings, 0 replies; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-02-13 20:19 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gdb-patches

On Mon, Feb 13, 2006 at 04:57:28PM -0200, Alexandre Oliva wrote:
> Yep.  It didn't look like those two occurrences were such a big deal.
> I don't see why we should refuse to handle long double at all just
> because we can't scan them in as such.  But it's not my call, I guess.

My only point here was that, if we know that DOUBLEST is a double,
then casting it to a long double and passing it to a home-brewed
long double reimplementation of ldexp is pretty silly; the other
HAVE_LONG_DOUBLE conditionals were all really
"DOUBLEST_IS_LONG_DOUBLE".

On Mon, Feb 13, 2006 at 09:13:21PM +0100, Mark Kettenis wrote:
> > From: Alexandre Oliva <aoliva@redhat.com>
> > Date: Mon, 13 Feb 2006 16:57:28 -0200
> >
> > Ok to install?
> 
> Looks ok to me.

Me too.  Thanks!

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-02-13 20:19 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-20 19:35 fixes for type-punning warnings in GCC 4.1 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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox