Null pointer check elimination

Per Bothner per@bothner.com
Sat Nov 12 17:27:00 GMT 2005


Diego Novillo wrote:
> On Saturday 12 November 2005 12:05, 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.
>>
> 
> I disagree.  We would have to prove that every possible instance of this 
> type is non-NULL.

I think you're missing the point.  The proposal is for a "type variant"
-  not that different from say "constant".

"non-null java.lang.String" is a different POINTER_TYPE object than
"[possibly-null] java.lang.String".  If you dereference an expression
whose type is "non-null java.lang.String" then you know you don't need
an null pointer check.  If you derefernce an expression of type
"[possibly-null] java.lang.String" then you do need the null pointer
check.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/



More information about the Java mailing list