public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@airs.com>
To: Richard Henderson <rth@redhat.com>
Cc: Andrew Pinski <pinskia@physics.uc.edu>,
	Mike Stump <mrs@apple.com>, Dave Korn <dave.korn@artimi.com>,
	Paul Koning <pkoning@equallogic.com>,
	gcc@sources.redhat.com, Shaun Jackman <sjackman@gmail.com>
Subject: Re: memcpy to an unaligned address
Date: Thu, 04 Aug 2005 04:42:00 -0000	[thread overview]
Message-ID: <m3br4egvnx.fsf@gossamer.airs.com> (raw)
In-Reply-To: <20050803180011.GA16808@redhat.com>

Richard Henderson <rth@redhat.com> writes:

> On Tue, Aug 02, 2005 at 01:45:01PM -0700, Ian Lance Taylor wrote:
> > Andrew Pinski <pinskia@physics.uc.edu> 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.
> 
> It is nevertheless correct.  Examine all of the parts of the expression.
> 
> In particular, "&s->b".  What type does it have?  In an ideal world, it
> would be "pointer to unaligned integer".  But we have no such type in
> our type system, so it is "pointer to integer".  This expression is ONLY
> THEN passed to memcpy.  At which point we query the argument for its
> alignment, and get the non-intuitive result.

That's a good explanation for what gcc is doing, and I do now
understand better than I did before.  But I thought Andrew was arguing
that gcc's behaviour is correct, and is not a compiler bug.  I still
think that gcc's behaviour here is not correct.  It is clear that if
gcc did not open code memcpy, the right thing would happen.  If gcc
open codes memcpy in such a way that it makes an incorrect assumption
about alignment, for whatever reason, I think that is a bug in the
compiler.

And so, since I think this is a bug which we want to fix, and since we
obviously want gcc to open code memcpy, I think that gcc has to
somehow notice the memory alignments involved.

Ian

  parent reply	other threads:[~2005-08-04  4:42 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-02 17:32 Shaun Jackman
2005-08-02 17:43 ` Dave Korn
2005-08-02 19:13   ` Shaun Jackman
2005-08-02 19:19     ` Paul Koning
2005-08-02 19:26       ` Shaun Jackman
2005-08-02 19:40         ` Dave Korn
2005-08-02 19:48           ` Paul Koning
2005-08-02 20:15           ` Shaun Jackman
2005-08-02 20:29             ` Paul Koning
2005-08-02 20:29             ` Mike Stump
2005-08-02 20:38               ` Andrew Pinski
2005-08-02 20:45                 ` Ian Lance Taylor
2005-08-02 21:30                   ` Mike Stump
2005-08-02 21:34                     ` Joe Buck
2005-08-03 18:00                   ` Richard Henderson
2005-08-03 18:15                     ` Shaun Jackman
2005-08-03 18:19                       ` Dave Korn
2005-08-03 21:26                       ` Richard Henderson
2005-08-04  4:42                     ` Ian Lance Taylor [this message]
2005-08-04 12:40                     ` Paul Koning
2005-08-02 20:46                 ` Paul Koning
2005-08-02 22:17                   ` Shaun Jackman
2005-08-03 17:16                     ` Paul Koning
2005-08-02 22:26                   ` Shaun Jackman
2005-08-02 22:29                     ` Shaun Jackman
2005-08-02 21:05                 ` Mike Stump
2005-08-02 21:11                   ` Joe Buck
2005-08-02 22:15                     ` Shaun Jackman
2005-08-02 22:12                       ` Joe Buck
2005-08-02 17:48 ` Falk Hueffner
2005-08-02 18:03 ` Mike Stump
     [not found] <345be691050804025955c0b4ab@mail.gmail.com>
2005-08-04 15:06 ` Shaun Jackman
2005-08-04 15:09   ` Christian Joensson
2005-08-05  8:41   ` Carl Whitwell
2005-08-05 16:09     ` Shaun Jackman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3br4egvnx.fsf@gossamer.airs.com \
    --to=ian@airs.com \
    --cc=dave.korn@artimi.com \
    --cc=gcc@sources.redhat.com \
    --cc=mrs@apple.com \
    --cc=pinskia@physics.uc.edu \
    --cc=pkoning@equallogic.com \
    --cc=rth@redhat.com \
    --cc=sjackman@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).