This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


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: ARM compiler misbehaves ?


On Thu, 2004-04-29 at 16:29, Grant Edwards wrote:

> > You'll have to take this one up in comp.std.c if you are
> > unhappy,
> 
> Oh no.  I stay away from that newsgroup. ;)
> 

:-)

> > but my reading of c89 (along with TC1) is that passing a
> > pointer to short to a memcpy permits the compiler to make
> > assumptions along the lines of the target really being
> > correctly aligned.
> > 
> > TC1 for section 7.11 (string.h) says
> > 
> > ... pointer arguments on a call must still have valid values, as
> > decribed in subclause 7.1.7.
> > 
> > Subclause 7.1.7 says:
> > 
> > If a function argument is described as being an array,
> 
> Well, we aren't talking about an array, so I don't see how this
> applies (at least without more context).
> 

Indeed we are talking about an array.  A pointer is simply the address
of the first element of an array.

> > the pointer actually passed to the function shall have a value
> > such that all address computations and accesses to objects
> > ([...]) are in fact valid.
> 
> > Putting this all together generally means that (except in a
> > freestanding environment) the compiler can convert a memcpy
> > into anything it likes that implements the specification.  For
> > example, it can either inline the copy directly (using memory
> > accesses that match the implied alignment), or it could rework
> > the code to call a more efficient implementation (such as one
> > that knows in advance what the alignment is).
> 
> So casting the pointer to a (char*) or (void*) should guarantee
> that the memcpy() works correctly.  Assuming that the "&"
> operator on a packed field correctly returns the address of the
> first byte in the field.

No.  The compiler is entitled to infer alignment (and other things, such
as aliasing, but lets not go there right now) through casts.

If you lie to the compiler it's entitled to do all sorts of random
things.  Putting something that isn't suitably aligned into a pointer
that implies some alignment is lying to the compiler...  It doesn't
matter how much you try to camouflage it, once you've lied you get
exactly what you deserve.

R.

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


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