From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3691 invoked by alias); 2 Aug 2005 20:45:13 -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 3677 invoked from network); 2 Aug 2005 20:45:09 -0000 Received: from unknown (205.217.158.180) by sourceware.org with QMTP; 2 Aug 2005 20:45:09 -0000 Received: (qmail 2885 invoked by uid 10); 2 Aug 2005 20:45:09 -0000 Received: (qmail 10347 invoked by uid 500); 2 Aug 2005 20:45:01 -0000 To: Andrew Pinski Cc: mrs@apple.com (Mike Stump), dave.korn@artimi.com (Dave Korn), pkoning@equallogic.com (Paul Koning), gcc@sources.redhat.com, sjackman@gmail.com (Shaun Jackman) Subject: Re: memcpy to an unaligned address References: <200508022037.j72Kbr4T012558@earth.phy.uc.edu> From: Ian Lance Taylor Date: Tue, 02 Aug 2005 20:45:00 -0000 In-Reply-To: <200508022037.j72Kbr4T012558@earth.phy.uc.edu> Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2005-08/txt/msg00085.txt.bz2 Andrew Pinski writes: > > Yes, this is a compiler bug in the expansion of memcpy, please file a > > bug report. The solution is for the compiler to notice the memory > > alignment of the destination and `do-the-right-thing' when it isn't > > aligned. > > No it is not, once you take the address (which should be rejected), it > is of type "unsigned int *" and not unaligned variable, passing it to > memcpy assumes the type alignment is the natural alignment. That argument doesn't make sense to me. memcpy takes a void* argument, which has no presumed alignment. The builtin should work the same way. That is, there is an implicit cast to void* in the argument to memcpy. The compiler can certainly take advantage of any knowledge it has about the alignment, but it can't assume anything about the alignment that it doesn't already know. Ian