|
|
|
|
|
by gpderetta
1306 days ago
|
|
> using "a pointer was dereferenced" as evidence "this pointer is safe to dereference" is comically bad evidence Do you think the compiler would be right to remove the second check here? if (!x) std::abort();
if (!x) return;
... = *x;
What about changing std::abort with the following? [[noreturn]] void my_abort();
How's that different form a check after dereferencing a pointer? In both cases the check can be removed because dataflow or control flow analysis.What if my_abort returns instead? Or another thread changes x after the fact? |
|
It's been long enough since I wrote C that I'm not familiar with that noreturn syntax or the contract I guess it implies, but control flow analysis which can prove the code will never be run, should all ideally warn me about it so that I can remove it in the source code, not quietly remove it from the object code.
I'm not demanding that it should happen in every case, but the cases where it's undecidable whether a statement is reachable or not, obviously it's undecidable for purposes of optimizing away the statement too.