This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]