From: Alexandre Oliva <aoliva@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: fixes for type-punning warnings in GCC 4.1
Date: Tue, 20 Dec 2005 19:35:00 -0000 [thread overview]
Message-ID: <ork6e0nban.fsf@livre.oliva.athome.lsd.ic.unicamp.br> (raw)
[-- 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}
next reply other threads:[~2005-12-19 19:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-20 19:35 Alexandre Oliva [this message]
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
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=ork6e0nban.fsf@livre.oliva.athome.lsd.ic.unicamp.br \
--to=aoliva@redhat.com \
--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