It's not just the function that becomes undefined, it's the entire program. There's literally nothing that the compiler is supposed to do following undefined behavior.
i.e. Is it undefined behavior if there are code paths that might access an array out of bounds, but at runtime it actually never would ?
With this assumption you might even deduce that
int f(int x) {
if (x != 42) undefined_behavior;
return x;
}
is the equivalent of int f(int x) {
return 42;
}
since (according to the assumption) in runtime it would always be called in a way that doesn't reach the undefined behavior, i.e., with x=42. And, of course, the many similar assumptions about array boundaries, pointer nullabilities, numbers not reaching overflow, etc.