From: Daniel Jacobowitz <dan@debian.org>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Invalid compilation without -fno-strict-aliasing
Date: Thu, 27 Feb 2003 14:45:22 -0500 [thread overview]
Message-ID: <20030227194522.GA10427@nevyn.them.org> (raw)
In-Reply-To: <b3lovr$16j$1@penguin.transmeta.com>
On Thu, Feb 27, 2003 at 07:30:03PM +0000, Linus Torvalds wrote:
> In article <20030226172213.O3910@devserv.devel.redhat.com>,
> Jakub Jelinek <jakub@redhat.com> wrote:
> >
> >To fix that, __constant_memcpy would have to access the data through
> >union,
>
> Which is impossible, since memcpy _fundamentally_ cannot know what the
> different types are..
>
> > or you could as well forget about __constant_memcpy and use
> >__builtin_memcpy where gcc will take care about the constant copying.
>
> Which is impossible because (a) historically __builtin_memcpy does a bad
> job and (b) it doesn't solve the generic case anyway, ie for other
> non-memcpy things.
>
> The fact is, for type-based alias analysis gcc needs a way to tell it
> "this can alias", which it doesn't have. Unions are _not_ useful,
> _regardless_ of what silly language lawyers say, since they are not a
> generic method. Unions only work for trivial and largely uninteresting
> cases, and it doesn't _matter_ what C99 says about the issue, since that
> nasty thing called "real life" interferes.
>
> Until we get some non-union way to say "this can alias", that
> -fno-strict-alias has to stay because gcc is too broken to allow us
> doing interesting stuff in-line without it.
>
> My personal opinion is (and was several years ago when this started
> coming up) that a cast (any cast) should do it. But I don't are _what_
> it is, as long as it is syntactically sane and isn't limited to special
> cases like unions.
Well, if that's all you're asking for, it's easy - I don't know if
you'll agree that the syntax is sane, but it's there. From the GCC 3.3
manual:
`may_alias'
Accesses to objects with types with this attribute are not
subjected to type-based alias analysis, but are instead assumed to
be able to alias any other type of objects, just like the `char'
type. See `-fstrict-aliasing' for more information on aliasing
issues.
Example of use:
typedef short __attribute__((__may_alias__)) short_a;
int
main (void)
{
int a = 0x12345678;
short_a *b = (short_a *) &a;
b[1] = 0;
if (a == 0x12345678)
abort();
exit(0);
}
If you replaced `short_a' with `short' in the variable
declaration, the above program would abort when compiled with
`-fstrict-aliasing', which is on by default at `-O2' or above in
recent GCC versions.
So you define a typedef for unsigned long which has the __may_alias__
attribute, and you go to town writing memcpy inline with that type
instead of a normal unsigned long.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
next prev parent reply other threads:[~2003-02-27 19:35 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-25 23:46 Invalid compilation without -fno-strict-aliasing Jean Tourrilhes
2003-02-26 15:38 ` Horst von Brand
2003-02-26 16:04 ` Falk Hueffner
2003-02-26 20:47 ` Horst von Brand
2003-02-26 20:57 ` Daniel Jacobowitz
2003-02-26 22:22 ` Jakub Jelinek
2003-02-27 19:30 ` Linus Torvalds
2003-02-27 19:45 ` Daniel Jacobowitz [this message]
2003-02-27 20:00 ` Linus Torvalds
2003-02-27 20:35 ` Daniel Jacobowitz
2003-02-27 20:38 ` Linus Torvalds
2003-02-27 23:55 ` H. Peter Anvin
2003-03-01 8:29 ` Anton Blanchard
2003-02-26 17:22 ` Jean Tourrilhes
2003-02-26 21:07 ` Horst von Brand
2003-02-27 4:41 ` Daniel Phillips
2003-02-26 17:26 ` Linus Torvalds
-- strict thread matches above, loose matches on Subject: below --
2003-02-26 4:33 Albert Cahalan
2003-02-26 17:20 ` Jean Tourrilhes
2003-02-26 18:23 ` Richard B. Johnson
2003-02-26 19:22 ` Daniel Jacobowitz
2003-02-26 19:40 ` Richard B. Johnson
2003-02-26 19:42 ` Daniel Jacobowitz
2003-02-26 20:19 ` Richard B. Johnson
2003-02-26 21:30 ` Albert Cahalan
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=20030227194522.GA10427@nevyn.them.org \
--to=dan@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.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