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, Apr 29, 2004 at 04:21:46PM +0100, Richard Earnshaw wrote:

>>>> 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,

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).

> 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.

-- 
Grant Edwards
grante@visi.com

------
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]