Re:Depressing and faintly terrifying days for the C standard...
by xamuel on Wednesday May 30, 2018 @04:26PM
(#17191426)
Here's an example where these optimizations are useful. Suppose I create a macro DEREF_AND_FREE(x) which expands to if(x)free(*x). Often times, I'll lazily use that in places where I know x isn't null. It's more readable and maintainble than splitting the macro up into two separate macros, DEREF_AND_FREE_IF_NONNULL and DEREF_AND_FREE_I_KNOW_ITS_NONNULL. The UB-based optimizations mean that I don't take the performance hit for my laziness.
[ Parent
| on HN ]
Re:Depressing and faintly terrifying days for the C standard...
by vyodaiken on Wednesday May 30, 2018 @05:22PM
(#17191952)
There is nothing to prevent the compiler from deducing that x is non-null without UB. What UB permits is for the the compiler to deduce that x is not null in the absence of information.
so : if(x)f(x) ...code ... if(x)g(x) doesn't need UB but y = x-> n ..... code if(x)g(x) - the compiler uses UB to remover the check. This will be especially horrible when LTO becomes more prevalent.