JDK 9 build with GCC 6.1.1

Kim Barrett kim.barrett at oracle.com
Mon Jun 27 22:19:05 UTC 2016


> On Jun 27, 2016, at 4:43 PM, David Holmes <david.holmes at oracle.com> wrote:
> 
> On 27/06/2016 9:45 PM, Andrew Haley wrote:
>> On 27/06/16 12:32, David Holmes wrote:
>>> I wasn't aware that we have any reliance on gcc doing any kind of "null
>>> pointer check" ??
>> 
>> Ah, right, I assumed you'd seen this before.
>> 
>> If GCC sees something like
>> 
>>   a->foo();
>>   if (a) {
>>     b();
>>   }
>> 
>> it will turn it into
>> 
>>   a->foo();
>>   b();
>> 
>> This surprises some people, but is quite legal.
> 
> Okay. So I know I was initially surprised we have code that can do:
> 
> a->foo();
> 
> when a is NULL, but that is because it is actually compiled as:
> 
> foo(a);
> 
> IIRC foo() has a "if (this != NULL)" check internally.
> 
> I'm kind of surprised that the compiler itself seems to think a->foo() implies a is not NULL.

a->foo() is defined to be equivalent to (*a).foo(). Dereferencing a
null pointer is undefined behavior...

> 
> I also hope it either is extremely smart about this or else very conservative. Would want it to make a mess of this:
> 
> if (init(&a) != NULL) {
>  a->foo();
> }
> else {
>  log(...);
> }
> if (a)
>  a->bar();
> 
> Cheers,
> David
> 
>> Andrew.




More information about the hotspot-dev mailing list