From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexandre Oliva To: Joe Buck Cc: gcc@gcc.gnu.org, rms@gnu.org Subject: Re: type based aliasing again Date: Thu, 30 Sep 1999 18:02:00 -0000 Message-ID: References: <199909090109.SAA28465@atrus.synopsys.com> X-SW-Source: 1999-09n/msg00522.html Message-ID: <19990930180200.2A28IQPBDe822ukaX_4PEGDhf-mzxSKIAUiKlMwAPUs@z> On Sep 8, 1999, Joe Buck wrote: > The question that has been asked by a number of people is whether we > can make some of the more "obvious" cases work correctly I don't think we can draw a line that separates the ``obvious'' cases from the non-obvious ones. > The change is simply to postpone the type-based check until after the > other analysis is done. If we detect that the references collide, but > the types say that we can assume they don't, we issue a warning and > then tell the compiler that there is aliasing. I don't think this can detect cases in which pointers are passed into functions. But I haven't thought very thoroughly about it. Methinks it would be much easier to just issue a warning whenever we find a type cast to a type that couldn't alias the original type. Of course one may cheat and introduce an intermediate cast to void* or char*, to silence the compiler (would this remove the aliasing problem too?), but the right fix would be to cast to the appropriate union type. This warning would catch most (all?) cases of dangerous type cases, and require the user to take action to work around them, and it would take place early enough in the compiler that we could issue good warning messages. BTW, it seems to me that this `cast to union' is something particular to gcc, not a general solution, right? I mean, other compilers might not pay as much attention to the unions as gcc does, since accessing any type other than the one that was actually stored in the union is undefined behavior anyway. -- Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org} oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org} ** I may forward mail about projects to mailing lists; please use them