This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: aliasing warnings [patch]


>>>>> "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.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]