From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24982 invoked by alias); 19 Dec 2005 19:21:54 -0000 Received: (qmail 24968 invoked by uid 22791); 19 Dec 2005 19:21:52 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 19 Dec 2005 19:20:59 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id jBJJKvpD029054 for ; Mon, 19 Dec 2005 14:20:57 -0500 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id jBJJKq101261 for ; Mon, 19 Dec 2005 14:20:52 -0500 Received: from livre.oliva.athome.lsd.ic.unicamp.br (vpn50-50.rdu.redhat.com [172.16.50.50]) by pobox.corp.redhat.com (8.12.8/8.12.8) with ESMTP id jBJJKoru028625 for ; Mon, 19 Dec 2005 14:20:51 -0500 Received: from livre.oliva.athome.lsd.ic.unicamp.br (livre.oliva.athome.lsd.ic.unicamp.br [127.0.0.1]) by livre.oliva.athome.lsd.ic.unicamp.br (8.13.5/8.13.5) with ESMTP id jBJJKmGP004505 for ; Mon, 19 Dec 2005 17:20:49 -0200 Received: (from aoliva@localhost) by livre.oliva.athome.lsd.ic.unicamp.br (8.13.5/8.13.5/Submit) id jBJJKmav004504; Mon, 19 Dec 2005 17:20:48 -0200 To: gdb-patches@sources.redhat.com Subject: fixes for type-punning warnings in GCC 4.1 From: Alexandre Oliva Date: Tue, 20 Dec 2005 19:35:00 -0000 Message-ID: User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.18 (Social Property, linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2005-12/txt/msg00242.txt.bz2 --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-length: 693 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? --=-=-= Content-Type: text/x-patch; charset=iso-8859-1 Content-Disposition: inline; filename=gdb-type-punning.patch Content-length: 5001 Index: gdb/ChangeLog 2005-12-19 Alexandre Oliva * 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); } --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-length: 188 -- 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} --=-=-=--