3 ms·
> Except the compiler clearly knows that it does happen since it elides the code because of it. That's definitely the opposite of what's happening here. The c
by klodolph 10y ago
> Except the compiler clearly knows that it does happen since it elides the code because of it.
That's definitely the opposite of what's happening here. The compile believes that it does not happen and therefore removes the code.
- kbenson 10y agoIt's actually an interaction between those two aspects which causes the problem. The compiler makes an assumption that something can't be true because that would mean undefined behavior (and of course the programmer isn't doing something that's undefined), and then a later optimization uses that fact to determine code that tests for that exact undefined behavior could never be run, and removes it. The reasoning by itself is not problematic without it's later use in optimization decisions, and the optimization decisions are not problematic without unfounded reasoning about undefined behavior. I think that's why people are so caught up on this. Technically, neither action is a problem, but together they obviously caused a problem. Either one in isolation doesn't look all that horrible (even if the undefined behavior reasoning is pushing it).