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 05:34:50 +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:
>
> Currently references to a "char" member of a structure are put in
> alias set zero, ie like they are a char*.
Right. That matches what the standard specifies.
Consider the following program:
struct first { char f1; int x; };
struct second { char f2; double y; };
void
g1 (struct first *ps1, struct second *ps2)
{
ps1->f1++;
ps2->f2++;
ps1->f1++;
ps2->f2++;
}
int
main (void)
{
void *p = calloc(sizeof(struct first) + sizeof(struct second), 1);
g1 (p, p);
printf("%d\n", ((struct first *)p)->f1);
return 0;
}
Isn't that program strictly conforming C, which should output `4'?
And won't your patch mis-optimize it to output something different?
Or did I miss something?
--
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.