This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ and Java CNI: Check Java references
Fergus Henderson writes:
> > +
> > + /* Strip off all pointer conversions and if the thing at the root is
> > + an integer we won't bother to check it. The main reason for this
> > + is that offsetof is often defined as
> > +
> > + ((size_t)&((type *)0)->memb)
> > +
> > + which implicitly dereferences a null pointer. Let's not check that. */
>
> Hmm... that seems like a bit of a hack.
Fair enough.
> It's also common to write expressions such as `&p[0]',
I think it's impossible in this case. These are Java objects, and
C++-style arrays can't occur.
> and I don't think it's a good idea to check for null
> pointers in that case.
>
> It would be nicer, I think, to skip the check iff the pointer dereference
> is the operand of unary `&' (address-of). Though it may not be as easy
> to implement...
Hmm. I think that this would require trees to be rewritten and the
pointer check to be reoved. Actually, I could avoid all this with a
__builtin_offsetof. Maybe that would fix the problem much more neatly.
> > + tree cond = build (NE_EXPR, boolean_type_node, exp, integer_zero_node);
>
> I'm not sure if it makes any difference, but wouldn't it be more
> appropriate to use null_pointer_node rather than integer_zero_node?
I'm pretty sure it makes no difference, but I agree that this would be
better.
Thanks!
Andrew.