This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix aliasing warning
- From: Andrew Haley <aph at redhat dot com>
- To: Marcus Meissner <meissner at suse dot de>
- Cc: Nathan Sidwell <nathan at codesourcery dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 28 Jun 2005 08:42:49 +0100
- Subject: Re: Fix aliasing warning
- References: <42BFFCAE.9080606@codesourcery.com><20050628064305.GA24612@suse.de>
Marcus Meissner writes:
> > This is unfortunate, and does expose aliasing issues. Luckily I think the
> > aliasing won't bite as we don't read through one then write through the
> > other within the same compiler visible code.
>
> > ! sc = (struct sigcontext *) &rt_->uc.uc_mcontext;
> .....
> > ! /* The void * cast is necessary to avoid an aliasing warning.
> > ! The aliasing warning is correct, but should not be a problem
> > ! because it does not alias anything. */
> > ! sc = (struct sigcontext *) (void *)&rt_->uc.uc_mcontext;
>
> Hmm, as far as I know this does not fix the bug, it just hides
> the warning?
>
> At least thats what I got told as I added (char*) casts to similar code.
Surely the comment explains this perfectly well -- the value isn't
accessed anywhere else in the program by another type. The type as
declared in the system header is wrong, so we have to cast it.
What else could we do? Volatile, perhaps? Some kind of union?
Andrew.