D - Unsafe and doomed

fra a at b.it
Mon Jan 6 07:56:08 PST 2014


On Monday, 6 January 2014 at 00:20:59 UTC, deadalnix wrote:
> On Monday, 6 January 2014 at 00:13:19 UTC, Walter Bright wrote:
>> I'd still like to see an example, even a contrived one.
>
> void foo(int* ptr) {
>     *ptr;
>     if (ptr is null) {
>         // do stuff
>     }
>
>     // do stuff.
> }

> The problem here is that the if can be removed, as you can't 
> reach that point if the pointer is null, but *ptr can also be 
> removed later as it is a dead load.
>
> The resulting code won't crash and do random shit instead.

"Code can't be reached if pointer is null" means "The code could 
fail before reaching here". Honestly, this looks like an 
optimizer issue to me. Who the **** would remove code that could 
fail?


More information about the Digitalmars-d mailing list