public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* ISO Aliasing rules question
@ 2003-02-21 17:18 law
  2003-02-21 19:16 ` Mark Mitchell
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: law @ 2003-02-21 17:18 UTC (permalink / raw)
  To: gcc


Given this testcase:

struct s1 { double d; };
struct s2 { double d; };

double f(struct s1 *a, struct s2 *b)
{
  a->d = 1.0;
  return b->d + 1.0;
}

int main()
{
  struct s1 a;
  a.d = 0.0;
  if (f (&a, (struct s2 *)&a) != 2.0)
    abort ();
  return 0;
}


Does this code produce undefined behavior according to ISO standard,
particularly in regards to aliasing issues.

My recollection of the standard is that struct s1 and struct s2 are 
_NOT_ type compatible (even though they have identical internal structure).

Thus the variables a & b in function f can't refer to the same object
as they are not type compatible.  Thus the compiler should be free to
ignore the assignment a->d = 1.0 when evaluating return b->d + 1.0
(which is precisely what the tree-ssa branch does :-)

Is this correct?  Or is my recollection of the ISO standard incorrect here?

Jeff


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2003-02-27 17:23 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-21 17:18 ISO Aliasing rules question law
2003-02-21 19:16 ` Mark Mitchell
2003-02-21 19:38   ` law
2003-02-21 20:03     ` Mark Mitchell
2003-02-21 20:10       ` Michael Matz
2003-02-21 20:01   ` Michael Matz
2003-02-21 20:17     ` Mark Mitchell
2003-02-21 20:29       ` Michael Matz
2003-02-21 21:26         ` Mark Mitchell
2003-02-22  1:22     ` Geoff Keating
2003-02-21 19:33 ` Michael Matz
2003-02-22  0:53   ` Joseph S. Myers
2003-02-24 21:37     ` law
2003-02-24 23:13       ` Joseph S. Myers
2003-02-24 23:23       ` Toon Moene
2003-02-25  3:20       ` Fergus Henderson
2003-02-27 18:47 ` David Carlton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).