This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: type based aliasing again
- To: Joe Buck <jbuck AT synopsys.COM>
- Subject: Re: type based aliasing again
- From: Alexandre Oliva <oliva AT lsd.ic.unicamp.br>
- Date: 14 Sep 1999 07:03:48 -0300
- Cc: gcc AT gcc.gnu dot org, rms AT gnu dot org
- References: <199909090109.SAA28465@atrus.synopsys.com>
On Sep 8, 1999, Joe Buck <jbuck@synopsys.COM> 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