From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Earnshaw To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org Subject: Re: optimization/4733: Incorrect code when aliasing double and struct on ARM -O2 Date: Mon, 29 Oct 2001 09:56:00 -0000 Message-id: <20011029175600.29891.qmail@sourceware.cygnus.com> X-SW-Source: 2001-10/msg00664.html List-Id: The following reply was made to PR optimization/4733; it has been noted by GNATS. From: Richard Earnshaw To: bjh21@netbsd.org Cc: gcc-gnats@gcc.gnu.org, Richard.Earnshaw@arm.com Subject: Re: optimization/4733: Incorrect code when aliasing double and struct on ARM -O2 Date: Mon, 29 Oct 2001 17:43:44 +0000 > >How-To-Repeat: > use "./cc1 -O2" > > typedef unsigned int u_int; > struct ieee_double { > u_int dbl_fracl; > u_int dbl_frach:20; > u_int dbl_exp:11; > u_int dbl_sign:1; > }; > int > isinf (d) > double d; > { > register struct ieee_double *p = (struct ieee_double *)(void *)&d; > > return (p->dbl_exp == 2047 && > (p->dbl_frach == 0 && p->dbl_fracl == 0)); > } Nope, this code violates the ANSI memory aliasing rules. According to ANSI, the only way to do this portably is to memcpy between the types; gcc will do the right thing if you use a union, but not otherwise. R.