...
- The behavior is erroneous.
- The behavior is difficult to diagnose.
- As a hook for implementation extensions.
Conforming implementation implementations can deal with undefined behavior in a variety of fashions, from ignoring the situation completely with unpredictable results, to translating or executing the program in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message). Because compilers are not obligated to generate code for undefined behavior, these behaviors are candidates for optimization. By assuming that undefined behaviors will not occur, compilers can generate code with better performance characteristics.
Unfortunately, undefined behaviors do occur, particularly in the presence of an an attacker. Optimizations make it difficult to determine how these systems will behave in the presence of undefined behaviors. This is particularly true when visually inspecting source code, because if the code relies on undefined behaviors, a code reviewer cannot be certain if the code will be compiled or if it will be optimized out. Furthermore, just because a compiler currently generates objects object code for an undefined behavior, does not mean that future versions of the compiler are obligated to do the same; this behavior may be viewed as an opportunity for further optimization. Compilers are also not required to issue diagnostics for undefined behavior, so there is frequently no easy way to identify undefined behavior in code.
...