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]


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

Actually, I never specified what happens when one pointer is copied to
another.  It seems you're assuming that the "unsafe" bit would be copied.
In fact, I didn't really think about it enough.

> >  Consider:
> > 
> >   int i;
> >   int *ip = &i;
> >   double *dp = (double *) ip;

Here dp is definitely unsafe to dereference, so pedwarn is OK.

> >   int *ip2 = (int*) dp;

We only know here that dp is unsafe to dereference, but not
whether ip2 is unsafe to dereference.  But you're right, it
would be wrong to pedwarn in this case.  If we knew that
the true type pointed to is int, we then know that ip2 is safe.
Alternatively, "unsafe to dereference" could be a three-way property:
yes, no, and maybe.

Zack writes:
> 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.

Does your extra pointer slot contain the true type?

My crude *guess* would be that the extra pointer slot wouldn't matter
that much, as long as we continue the current policy of only using trees
for statements, not whole functions.  It would matter more if we keep
trees around for whole functions.

Joe


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