ISO Aliasing rules question
law@redhat.com
law@redhat.com
Fri Feb 21 17:18:00 GMT 2003
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
More information about the Gcc
mailing list