This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] fix aliasing for chars in global structures - take II
- From: Fergus Henderson <fjh at cs dot mu dot OZ dot AU>
- To: Dan Nicolaescu <dann at godzilla dot ICS dot UCI dot EDU>
- Cc: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>, gcc-patches at gcc dot gnu dot org
- Date: Sat, 23 Mar 2002 06:21:55 +1100
- Subject: Re: [PATCH] fix aliasing for chars in global structures - take II
On 22-Mar-2002, Dan Nicolaescu <dann@godzilla.ICS.UCI.EDU> wrote:
> Fergus Henderson <fjh@cs.mu.oz.au> writes:
> > Consider the following program:
...
> > Isn't that program strictly conforming C, which should output `4'?
> > And won't your patch mis-optimize it to output something
> > different?
>
> I don't think so. The the references to ps1->f1 and ps2->f2 will be in
> the same alias set.
Sorry, I got the example wrong.
Let's make it
struct first { unsigned char f1; int x; };
struct second { unsigned int f2; double y; };
so that they are not in the same alias set,
and change the code to something like this:
void
g (struct first *ps1, struct second *ps2)
{
ps1->f1++;
ps2->f2 = 0;
ps1->f1++;
}
int
main (void)
{
void *p = calloc (sizeof(struct first) + sizeof(struct second), 1);
g (p, p);
printf("%d\n", ((struct first *) p)->f1);
return 0;
}
This one should print "1", but I suspect that with your patch it will
print either "0" or "2".
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.