This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Null pointer check elimination
- From: Joe Buck <Joe dot Buck at synopsys dot COM>
- To: Per Bothner <per at bothner dot com>
- Cc: Andrew Pinski <pinskia at physics dot uc dot edu>,Gabriel Dos Reis <gdr at integrable-solutions dot net>,Anthony Green <green at redhat dot com>, java at gcc dot gnu dot org,GCC Mailing List <gcc at gcc dot gnu dot org>
- Date: Mon, 14 Nov 2005 09:41:46 -0800
- Subject: Re: Null pointer check elimination
- References: <200511121838.jACIcBge006902@earth.phy.uc.edu> <437638C5.9020900@bothner.com>
On Sat, Nov 12, 2005 at 10:47:33AM -0800, Per Bothner wrote:
> Per Bothner wrote:
> >A "function-never-returns-null" attribute doesn't seem like
> >the right mechanism. Instead, there should be a "never-null"
> >attribute on pointer types. A "function-never-returns-null" is
> >just a function whose return-type has the "never-null" attribute.
>
> Gabriel Does Reis wrote:
> >We already have such mechanism: a reference type -- which morally is
> >implemented as a pointer type.
>
> Andrew Pinski wrote:
> >That was mentioned a way ago as being wrong. A reference type can be NULL.
>
> There are other differences, at least in C++: If you assign to a
> pointer, you change the pointer, while if you assign to a reference
> you modify the referenced object. I.e. if a variable has reference
> type, then the reference itself is constant.
That's two separate features: the first is about how the source code
is interpreted (and that corresponds to informing the debugger that
the object is auto-dereferenced). The second corresponds to declaring
that a pointer is itself const.
So a C++ reference could be represented as a middle-end pointer type,
provided that it is marked as auto-dereferencing, never null, and
constant.