This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: How to supress a specific kind of ansi-aliasing rules?
- From: "Dave Korn" <dave dot korn at artimi dot com>
- To: "'Bokhanko, Andrey S'" <andrey dot s dot bokhanko at intel dot com>, <gcc at gnu dot org>
- Date: Wed, 20 Jun 2007 11:50:48 +0100
- Subject: RE: How to supress a specific kind of ansi-aliasing rules?
- References: <300B70C65DCD59468957941A60716EBC7EB6BD@mssmsx411>
On 20 June 2007 11:36, Bokhanko, Andrey S wrote:
> Hi,
>
> As I learned from experience, gcc always assume independence between memory
> references in the following program:
>
> typedef struct {
> ??? int m1;
> ??? int m2;
> } S1;
>
> void foo(S1 *p1, S1 *p2) {
> ??? ... = p1->m1;
> ??? ... = p2->m2;
> }
>
> ...even if -fno-strict-aliasing (an option disabling ansi-aliasing rules)
> supplied.
>
> I wonder, is there a way to force gcc not to assume independence in the
> example shown above?
Just maybe if you give the struct definition __attribute__ ((packed)) gcc
will no longer assume that all struct S1s are naturally aligned and therefore
know that they might overlap? (But it's also quite possible that it won't...
I haven't been through the sources to determine how much aliasing information
it infers from alignment.)
cheers,
DaveK
--
Can't think of a witty .sigline today....