>>78197445Getting rid of your cod is one thing, but this is not the worse (at all) that could happen.
As this is UB, your compiler could decide that this shouldn't happen and could deduce new stuff. Then, depending on where the loop is, it could actually optimize your code in reverse order and nuke code that is BEFORE the UB.
Let's pretend that your code is the following:
int f(int x) {
if (x == 42) return 4;
while (f != 42) {}
return x;
}
The compiler could see the UB. That UB is only reachable if x != 42. As it shouldn't happen, x must be equal to 42.
But if x == 42, then we should have returned 4. So, one way the compiler may want to "abuse" the UB as a way to optimize your code is by inlining this function to just "4".