From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30418 invoked by alias); 8 Feb 2006 03:35:20 -0000 Received: (qmail 30407 invoked by uid 22791); 8 Feb 2006 03:35:19 -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; Wed, 08 Feb 2006 03:35:14 +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 k183ZCil018193 for ; Tue, 7 Feb 2006 22:35:12 -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 k183ZC108455 for ; Tue, 7 Feb 2006 22:35:12 -0500 Received: from livre.oliva.athome.lsd.ic.unicamp.br (vpn50-114.rdu.redhat.com [172.16.50.114]) by pobox.corp.redhat.com (8.12.8/8.12.8) with ESMTP id k183ZBYT029610 for ; Tue, 7 Feb 2006 22:35:11 -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 k182or9r008199 for ; Wed, 8 Feb 2006 00:50:53 -0200 Received: (from aoliva@localhost) by livre.oliva.athome.lsd.ic.unicamp.br (8.13.5/8.13.5/Submit) id k182mCuQ008173; Wed, 8 Feb 2006 00:48:12 -0200 To: Eli Zaretskii Cc: gdb-patches@sources.redhat.com Subject: Re: fixes for type-punning warnings in GCC 4.1 References: <20051219221830.GA32448@nevyn.them.org> <20060122203323.GC27224@nevyn.them.org> From: Alexandre Oliva Date: Wed, 08 Feb 2006 03:35:00 -0000 In-Reply-To: <20060122203323.GC27224@nevyn.them.org> (Daniel Jacobowitz's message of "Sun, 22 Jan 2006 15:33:23 -0500") Message-ID: User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.18 (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: 2006-02/txt/msg00161.txt.bz2 --=-=-= Content-length: 330 On Jan 22, 2006, Daniel Jacobowitz 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? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=gdb-type-punning-3.patch Content-length: 7155 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 *, --=-=-= Content-length: 249 -- 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} --=-=-=--