by nine_k · 1mo ago · 0 comments
AFAICT, UBI is stuff like that:
short int i;
for (i = 0; i < 33000; i++) do_something();
Whether this program continues as normal, crashes, or enters an infinite loop is platform-dependent, because short int can be as small as 16 bit, and an integer overflow past 32767 can be a crash or a wraparound.The goal of my comment was to demonstrate how compilers use UBs to drive analysis.
Dereferencing a null pointer is one of the most basic UBs you can find in C. Since a valid program can not contain UBs, the compiler concludes i must be non-null, propagates that to the test, which is constant and true, thus redundant and eliminated.