From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13943 invoked by alias); 2 Aug 2005 17:32:43 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 13933 invoked by uid 22791); 2 Aug 2005 17:32:40 -0000 Received: from rproxy.gmail.com (HELO rproxy.gmail.com) (64.233.170.199) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 02 Aug 2005 17:32:40 +0000 Received: by rproxy.gmail.com with SMTP id c51so1582789rne for ; Tue, 02 Aug 2005 10:32:38 -0700 (PDT) Received: by 10.11.99.26 with SMTP id w26mr72129cwb; Tue, 02 Aug 2005 10:32:38 -0700 (PDT) Received: by 10.11.99.15 with HTTP; Tue, 2 Aug 2005 10:32:38 -0700 (PDT) Message-ID: <7f45d9390508021032aea5a61@mail.gmail.com> Date: Tue, 02 Aug 2005 17:32:00 -0000 From: Shaun Jackman Reply-To: Shaun Jackman To: gcc@sources.redhat.com Subject: memcpy to an unaligned address Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-SW-Source: 2005-08/txt/msg00068.txt.bz2 In a typical Ethernet/IP ARP header the source IP address is unaligned. Instead of using... out->srcIPAddr =3D 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