With Clang 13 you can literally format your hard drive using undefined behavior
twitter.com
twitter.com
* The loop in f1 guaranteed to overflow int i if it's executed, but that's undefined behavior.
* Compilers sometimes delete code with undefined behavior, since that's the most efficient possible implementation.
* Deleting undefined behavior leaves an empty function.
* (Bug?) Empty function gets optimized a way to completely nothing, not even "enter and then exit". Edit: This comment explains the "missing exit" better. https://news.ycombinator.com/item?id=26499110
* Bug: the empty function f1 gets an address anyway, but 0 code; which makes execution fall through to whatever's next; in this case, it's f2's implementation.
* So, calling f1 jumps to the address where f2 is, and f2 runs, which isn't what you want.
"Format your hard drive" just means that "call an arbitrary different function".
How is it clearly a bug? Undefined means undefined.
In the decades since, benchmark competition has given us the hostile mess we have today.
In C and C++, that's exactly what undefined behavior means. I think you're confusing it with unspecified behavior.
If undefined behavior would happen during an execution of a program, then that entire execution of the program is undefined behavior from the start.
Since all possible executions of this program will lead to undefined behavior, the compiler was free to emit any other program. It is permitted to get rid of all the code. You could say that Clang 13 missed an optimization opportunity here. It could have produced an empty file.
You know shit is serious when someone threatens to format the drive to btrfs