This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix aliasing warning


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]