This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: aliasing warnings [patch]
Jason Merrill wrote:
> >>>>> Zack Weinberg <zack@bitmover.com> writes:
>
> > The warnings would be much more useful if they named the types, but I
> > don't see a way of extracting a type name from the tree that defines
> > it. c-aux-info.c has a lengthy private function to do it.
>
> The C++ frontend has convenient error-reporting functions that handle
> printing out all sorts of trees. It might be nice to move that into
> the language-independent code.
I shall look at this. The C front end has plenty of warnings/errors
that could be improved.
> > I'm not sure how many false negatives this will generate. Casting
> > through char * or void * suppresses the warning, so a genuine aliasing
> > bug can be masked - in particular, a memcpy() that takes char * args
> > and casts them to long * may have problems but get no warning.
>
> Would it make sense to warn about casts from char*? The standard only says
> that anything can be accessed through a char*, not vice versa.
Consider this fragment:
{
char buf[sizeof(struct foo)];
struct foo *x = (struct foo *)buf;
x->bar = value1;
x->baz = value2;
...
fwrite(buf, sizeof(struct foo), 1, file);
}
I believe this is well-defined.
> How about adding this to the C++ frontend, too?
It will have to be rewritten for C++'s type checking code, which is
completely different. I fear I don't understand the C++ new-style
casts well enough to do it right.
zw