This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Null pointer check elimination
- From: Joe Buck <Joe dot Buck at synopsys dot COM>
- To: Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: Gabriel Dos Reis <gdr at integrable-solutions dot net>,Paul Brook <paul at codesourcery dot com>, gcc at gcc dot gnu dot org,Per Bothner <per at bothner dot com>, Anthony Green <green at redhat dot com>,java at gcc dot gnu dot org
- Date: Mon, 14 Nov 2005 09:37:36 -0800
- Subject: Re: Null pointer check elimination
- References: <m3slu1vb2x.fsf@uniton.integrable-solutions.net> <200511122101.jACL17FV008454@earth.phy.uc.edu>
On Sat, Nov 12, 2005 at 04:01:07PM -0500, Andrew Pinski wrote:
> Was there an example of:
>
> int f(int &);
>
> int g(void)
> {
> int *a = 0;
> return f(*a);
> }
>
>
> Yes this would be undefined code but so what.
In a case like this, gcc could emit an error (since we can already
detect that a reference is always initialized to a null pointer).
If it did so, I can almost guarantee that some free software package
will be flagged (I recall writing such code myself 10+ years ago, before I
knew better), but it still might be a good thing.
Of course, it's not hard to hide the fact that a reference is null from
the compiler, and the compiler might then do optimizations based on the
assumption that the argument to f is a non-null reference. That would
be valid according to the standard.