Under modern interpretations of \"Undefined Behavior\", a compiler is entitled to assume that no chain of events which would cause undefined behavior to be \"inevitable\" wi
This is well described in C++ under [intro.execution]:
5 - A conforming implementation executing a well-formed program shall produce the same observable behavior as one of the possible executions of the corresponding instance of the abstract machine with the same program and the same input. However, if any such execution contains an undefined operation, this International Standard places no requirement on the implementation executing that program with that input (not even with regard to operations preceding the first undefined operation).
It is generally accepted that C has the same characteristics, and so that a C compiler can similarly perform "time travel" in the presence of undefined behavior.
Importantly, note that the question is whether there exists an instance of the abstract machine exhibiting undefined behavior; it doesn't matter that you can arrange to prevent undefined behavior on your machine by terminating program execution first.
You can prevent undefined behavior (and resulting time travel) if you cause the program to terminate itself in a fully-defined way which the abstract machine cannot wriggle out of. For example, in your second example if you replace access to *p
with (exit(0), 0)
then undefined behavior cannot occur as there is no possible execution of the abstract machine where exit
returns to its caller. But whatever the characteristics of your platform, the abstract machine does not have to terminate your program on access to an insta-kill address (indeed, the abstract machine does not have any insta-kill addresses).