On January 3, 2018 1:21:40 PM GMT+01:00, Nathan Sidwell <nat...@acm.org> wrote:
>On 01/02/2018 04:12 PM, Jakub Jelinek wrote:
>> Hi!
>> 
>> This patch improves code generated for:
>> struct A { int a; };
>> struct B { int b; };
>> struct C : A, B { int c; };
>> C *bar (B *b) { return &static_cast<C &>(*b); }
>> Unlike return static_cast<C *>(b); where b can be validly NULL, the
>> reference shouldn't bind to NULL, but we still emit
>> b ? b - 4 : 0.  The following patch omits the non-NULL check except
>when
>> -fsanitize=null (or undefined) and when sanitizing makes sure such
>bugs are
>> diagnosed.
>
>It's sad the optimizers don't know REFERENCE_TYPE (x) means x != NULL. 
>(or perhaps that's just a C++ semantic of REFERENCE_TYPE?).  

Given we treat reference and pointer types as interchangeable we indeed don't 
know that. 

Do we 
>manage to elide the check if we eventually dereference the pointer? 

We eventually should via path isolation of the null dereference. But better 
check that  ;) 

>(Not that that'd be an easy fix, but maybe worth a (new?) bug report.)
>
>Your patch is fine, but could you add a test case to make sure the null
>
>check is not there in the output assembly -- it'd be $cpu-of-choice 
>specific, of course.
>
>nathan

Reply via email to