One example of undefined behavior of signed integer overflow is when a compiler assumes that a signed integer "cannot" overflow. This can be used to optimize away expressions like the following:
Code:
int a = ...;
// ...
if (a + 1 < a) {}
The compiler is free to assume that a signed integer cannot overflow (because it's undefined), so the entire "if" statement can be removed. Some programs use statements like that to check if an addition would overflow, but it needs to be replaced with a test that has defined behavior, such as this:
Code:
int a = ...;
// ...
if (a > INT_MAX - 1) {}