This is the mail archive of the gcc@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]

Re: Linux and aliasing?


>>>>> "Linus" == Linus Torvalds <torvalds@transmeta.com> writes:

    Linus> On Sat, 5 Jun 1999 mark@codesourcery.com wrote:
    >>  Not really always true.  You can use `memcpy (target, src,
    >> sizeof (x))' and if the alignments of the src and target are
    >> known to the compiler you *should* get optimal code.  (I don't
    >> know if GCC does this at present, but it could, and that would
    >> clearly be a good improvement.)

    Linus> Only if that's assuming that it _is_ a memcpy.

    Linus> Think of things like

    Linus> 	a = ntohl(*(u32 *)p);

    Linus> etc - which is _not_ just a copy.

Right.  But the part that's causing aliasing issues is just a memcpy;
that's the `*(u32 *) p' bit.   You could write:

  memcpy (&a, p, sizeof (a));
  a = ntohl (a);

I would argue that GCC *should* generate the code you want for this.
GCC may not.  Fixing it might be difficult.  But, if GCC does not
generate good code for this case, improving it would be an
optimization of general utility.

Yes, I recognize that this is not as a compact a coding style as you
are used to.  All the previous discussion about difficulty of
conversion stands; both your opinions and mine.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com


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