This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: aliasing warnings [patch]
Mark Mitchell wrote:
> >>>>> "Joe" == Joe Buck <jbuck@synopsys.COM> writes:
> Joe> What if, instead of immediately issuing a warning, instead
>
> Joe> you simply tag the tree for the pointer somehow? The idea is
> Joe> to mark pointers that are unsafe to dereference. If the
> Joe> pointer is later dereferenced, you could do a pedwarn (as the
> Joe> program unquestionably breaks the strict ANSI/ISO rules, and
> Joe> that's what -pedantic is for). If it goes out of scope
> Joe> without being dereferenced, no problem. The only problematic
> Joe> case is if it is on the heap, passed to a function, etc. You
> Joe> could optionally generate a warning for such cases.
>
> I think your idea is probably a good one, but your statement is not
> 100% correct. Consider:
>
> int i;
> int *ip = &i;
> double *dp = (double *) ip;
> int *ip2 = (int*) dp;
>
> *ip2 = 3;
>
> As I understand it, your proposal would warn about this construct. I
> think that's fine; it's "suspicious", even though it happens to be
> valid. So, the sentence I disagree with is "the program
> unquestionably breaks the strict ANSI/ISO rules". I don't think
> that's true.
I had a very similar idea in the shower this morning, and will try to
implement it when I get a chance. It won't warn about the construct
you have there. It will, however, involve adding another pointer slot
to every tree node - this may be an unacceptable memory penalty.
zw