Undefined Behavior Is Really Undefined
https://cryptoservices.github.io/fde/2018/11/30/undefined-behavior.html [cryptoservices.github.io]
2018-12-03 17:09
This is in a nutshell what UB means: the compiler can assume that UB does not happen, and produce code under that assumption. In the code producing routines used by the compiler, each instruction has dependencies that restrict the opcode scheduling algorithm: an instruction cannot be issued before the instructions that it depends upon, or after the instructions that depend on it. In the example above, UB removes the dependencies between the writes to d[], and the “subsequent” reads from s[]. In a similar way, UB can allow the compiler to simply remove code that cannot happen without going through an UB condition.
source: L