2 ms·
> It's the same optimisation: elimination of unreachable code. No it isn't, because in the one case, if you don't eliminate the code, it turns out to be reacha
by kazinator 6y ago
> It's the same optimisation: elimination of unreachable code.
No it isn't, because in the one case, if you don't eliminate the code, it turns out to be reachable. The reason is that the logical predicate by which it was deduced to be unreachable ("the program is perfectly written and doesn't invoke undefined behavior") is not actually true.
So that is to say, this code will actually terminate due to wraparound past INT_MAX "for (i = 0; i >= 0; i++);" and statements which follow it are reached. That same compiler has wraparound behavior for int.
It's not the same as "if (1) return;" where the basis for removing the subsequent code is simply true.
- MaxBarraclough 6y agoSo you're suggesting restricting the optimisation to trivial cases only, greatly hampering what it can do. Again, your suggestion is imprecise. Would you want undefined behaviour eliminated from the language entirely? If yes, deep changes would need to be made. If no, there's little point, as it's still a highly unsafe language.