You have to understand that in the modern understanding of UB as applied by compiler writers, the compiler has every right to assume the program never triggers UB. This means that lines which would be UB if a variable had certain values can be used as proof that the variable
doesn't have those values, thereby eliminating checks.
For example, if a program looks like this:
void foo(int* const p) {
if (p!=NULL) {
bar(p);
}
*p = 1; //this line would be UB if p could be NULL
//so we are free to assume p is not NULL in this scope
}
It will very likely be optimized to this:
void foo(int* const p) {
bar(p);
*p = 1;
}
And even if bar() itself had a line checking if p was not NULL, that will get ellided as well if bar() gets inlined.
This is a good example of how UB on a later line can have an impact on earlier lines, or even in other places in the code.
Note that it's not executions which trigger UB, it is source code programs that do.
Edit: fixed const pointer syntax.