Linux and aliasing?
mark@codesourcery.com
mark@codesourcery.com
Thu Jun 3 12:03:00 GMT 1999
>>>>> "David" == David S Miller <davem@redhat.com> writes:
David> Actually, I've changed my mind.
OK, sorry to misrepresent your position.
David> I'm not saying this should be the normal mode of operation,
David> but some mechanism needs to exist so that such code can be
David> made valid _without_ resorting to ugly unions.
There is one: -fno-strict-aliasing.
You can turn off the optimization. Then, however, if you complain
that the kernel would go faster if type-based alias analysis is in
use, you're out of luck. But, this is no worse off than you were
before the optimization existed, and Linux worked pretty well in those
days too.
Despite what you say, you could just use some unions. IMO, it
wouldn't take that much to fix up the TCP_IPV4_MATCH macro. I'm sorry
the socket structure would become uglier, but, on the other hand, it
would make more obvious what exactly it is. Right now, some of the
fields in the structure definition are really acting as unions, and
you're not making that clear to the reader of the code.
David> You know exactly what I'm doing there, and so do I, why
David> can't egcs figure it out that easily as well?
Good question, but you know very well that it's rhetorical. :-) There
are lots of situations where it's obvious what should happen to the
programmer, but highly non-trivial to do in the compiler, if possible
at all.
I agree that in this case a special hack that says "if the access is
through the address of a variable/field of one type, but cast to
another type, then the user is doing something fishy, and we should
treat the access as if it were done with char*" is not ridiculous, and
not impossible to implement. You might consider implementing this, or
hiring someone else to do it for you.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
More information about the Gcc
mailing list