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.