This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: aliasing warnings [patch]
Mark Mitchell wrote:
[...]
> I looked at a few of the warnings that were generated with GCC this
> way. I was not surprised to see that all of them (in my spot check of
> five or six) were false positives of the same form: a pointer is cast
> to a different type, but then uncast before it is used. Your patch
> causes us to warn in both places. For example, SAVE_EXPR_RTL stores
> an `struct rtx_def *' as `union tree_node *'. I believe casts among
> unrelated pointer types are implementation-defined, rather than
> undefined, behavior, so long as you do not dereference them the wrong
> way. Such usage is not strictly portable, of course; implementations
> are allowed to use different numbers of bits for different pointers.
> So, the warning is a *little* bit useful even here. Suffice it to say
> that a machine that really didn't allow casting amongs unrelated
> pointer types would break a ton more software than -fstrict-aliasing,
> though. In other words, I don't think we should worry about fixing
> GCC to avoid these warnings, providing we're not dereferencing the
> pointers incorrectly.
Hmm... Maybe the warning should be disabled when casting from one
aggregate type to another. That should cover most of the cases where
we cast to a different type and back. It would increase the number of
false negatives, though.
I agree it shouldn't be on by default, but I would like to converge on
something that could be on with -Wall.
zw