rjmccall added a comment.

Discourse nitpick: I would encourage you to just use the ordinary phrase "null 
pointer", or just "null", when referring to a pointer value that happens to be 
null and to reserve "nullptr" for *statically* null pointers, especially the 
`nullptr` expression.

If the pointer is not null, the runtime overhead of the null check is pretty 
negligible next to the cost of actually doing the allocation.  If the pointer 
is null, the runtime overhead of making at least one unnecessary call — 
probably two, if 'operator delete' doesn't do its own null check before calling 
'free', and probably one that crosses image boundaries — is not negligible at 
all.  So the relative impact on code that does end up destroying a trivial 
value is outsized.

On the other hand, if the programmer adds an explicit null-check, it's unlikely 
to be optimized away; that means that if we did this automatically, there would 
still be an avenue for them to get the null check back.

The code-size argument against doing the null check seems strong, however.  
Have you considered just doing this in the code-size-sensitive modes, in 
particular -Os/-Oz (for obvious reasons) and -O0 (because less code size == 
faster compiles, especially when it involves control flow)?

  rC Clang


cfe-commits mailing list

Reply via email to