This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: aliasing warnings [patch]
Mark Mitchell <mark@codesourcery.com> writes:
|> >>>>> "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;
If i is not correctly aligned for double then the behaviour is undefined
(C9x 6.3.2.3 [#7]). Thus this may not be valid, independent of aliasing
issues.
Andreas.
--
Andreas Schwab "And now for something
schwab@suse.de completely different."
SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg