From: Joe Buck <Joe.Buck@synopsys.COM>
To: Steve Ellcey <sje@cup.hp.com>
Cc: gcc@gcc.gnu.org
Subject: Re: memcpy / Language Lawyer / optimization question
Date: Thu, 09 Dec 2004 19:41:00 -0000 [thread overview]
Message-ID: <20041209114105.B32427@synopsys.com> (raw)
In-Reply-To: <200412091932.LAA06762@hpsje.cup.hp.com>; from sje@cup.hp.com on Thu, Dec 09, 2004 at 11:32:55AM -0800
On Thu, Dec 09, 2004 at 11:32:55AM -0800, Steve Ellcey wrote:
> I have a question about memcpy and when it is legal to turn it into a
> simple assignment. The first memcpy in the program below will cause an
> abort on IA64 when compiled with -O2 because it gets turned into integer
> assignment and p is not properly aligned. I think this is OK.
No, it's not OK; you are lying to the compiler and paying for the offense.
By declaring the return value of foo to be a pointer to int, you are
promising that the return value will be aligned. It isn't, therefore you
get a crash.
> static char buffer[80];
> ...
> int *foo()
> {
> return (int *) &buffer[1];
> }
Don't ever do that. &buffer[i] is not aligned to a 4-byte boundary, so
casting it to a pointer to int is a very bad mistake.
next prev parent reply other threads:[~2004-12-09 19:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-09 19:33 Steve Ellcey
2004-12-09 19:41 ` Joe Buck [this message]
2004-12-09 19:52 ` Paul Jarc
2004-12-09 20:11 ` Gabriel Dos Reis
2004-12-09 20:14 ` Joe Buck
2004-12-09 20:20 ` Joseph S. Myers
2004-12-10 16:51 ` Steve Ellcey
2004-12-09 22:54 Paul Schlie
2004-12-09 23:36 ` Geoffrey Keating
2004-12-09 23:53 ` Joe Buck
2004-12-10 3:18 ` Paul Schlie
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=20041209114105.B32427@synopsys.com \
--to=joe.buck@synopsys.com \
--cc=gcc@gcc.gnu.org \
--cc=sje@cup.hp.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).