ARM compiler misbehaves ?

Richard Earnshaw Richard.Earnshaw@arm.com
Thu Apr 29 15:21:00 GMT 2004


On Thu, 2004-04-29 at 16:03, Grant Edwards wrote:
> On Thu, Apr 29, 2004 at 07:46:50AM -0700, Dickinson, Derek wrote:
> > >> Last time I checked (with the ARM and H8 gcc's) you could. It's
> > >> just that dereferencing the pointer won't work right. Copying
> > >> to/from the value of the pointer with memcpy() works fine.
> > >> 
> > >
> > >No, even that isn't guaranteed, since the compiler is entitled to "know"
> > >the implementation of memcpy, and therefore to implement it inline.
> > 
> > Is this true?  I thought memcpy was guaranteed to work on unaligned 
> > addresses regardless of whether it is inline.
> 
> memcpy() has always worked for me with any alignment of source
> and destination.

You'll have to take this one up in comp.std.c if you are unhappy, 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, 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).

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



More information about the crossgcc mailing list