This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
memcpy to an unaligned address
- From: Shaun Jackman <sjackman at gmail dot com>
- To: gcc at sources dot redhat dot com
- Date: Tue, 2 Aug 2005 11:32:38 -0600
- Subject: memcpy to an unaligned address
- Reply-to: Shaun Jackman <sjackman at gmail dot com>
In a typical Ethernet/IP ARP header the source IP address is
unaligned. Instead of using...
out->srcIPAddr = in->dstIPAddr;
... I used...
memcpy(&out->srcIPAddr, &in->dstIPAddr, sizeof(uint32_t));
... to account for the unaligned destination. This worked until gcc 4,
which now generates a simple load/store.
ldr r3, [r6, #24]
adds r2, r4, #0
adds r2, #14
str r3, [r2, #0]
A nice optimisation, but in this case it's incorrect. $r4 is aligned,
and the result of adding #14 to $r4 is an unaligned pointer.
Should gcc know better, or do I need to give it a little more
information to help it out?
Please cc me in your reply. Cheers,
Shaun