This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
ISO Aliasing rules question
- From: law at redhat dot com
- To: gcc at gcc dot gnu dot org
- Date: Fri, 21 Feb 2003 10:16:02 -0700
- Subject: ISO Aliasing rules question
- Reply-to: law at redhat dot com
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