|
|
|
|
|
by BeeOnRope
2861 days ago
|
|
Sure, and compilers do now sometimes emit warnings like "shift amount is always out of range". Overall though, this isn't how compilers work: they aren't "fucking around" with code they know for sure is broken and will be executed. They are just applying a large series of optimization passes which includes passes like removing unreachable code, and that interacts with an analysis of paths that cannot be take for various reasons (including that end in UB) to remove "big chunks of code". The same passes that screw you over in any of these famous examples are the ones that help code generation in the 99% of remaining cases including many "obvious" optimizations that you'd want the compiler to perform. I know the situation with undefined behavior is distressing and the examples make it look like the compiler writers are out to get you, but that's not really the case. |
|