This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: optimization/4733: Incorrect code when aliasing double and struct on ARM -O2
- To: nobody at gcc dot gnu dot org
- Subject: Re: optimization/4733: Incorrect code when aliasing double and struct on ARM -O2
- From: Richard Earnshaw <rearnsha at arm dot com>
- Date: 29 Oct 2001 17:56:00 -0000
- Cc: gcc-prs at gcc dot gnu dot org,
- Reply-To: Richard Earnshaw <rearnsha at arm dot com>
The following reply was made to PR optimization/4733; it has been noted by GNATS.
From: Richard Earnshaw <rearnsha@arm.com>
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.