Re:“Pack it in, mathematicians, someone owes LLVM a million ...
by cjfd on Thursday August 19, 2021 @09:39AM
(#28233682)
Is it actually true that endless loops are undefined behavior? This statement does not make sense at face value. I am aware that sometimes UB is used to throw away code, but is an endless loop really UB? Anyway, compiling while(true); in g++ with -O4 just yields a program that runs forerver....
[ Parent
| on HN ]
Re:“Pack it in, mathematicians, someone owes LLVM a million ...
by detaro on Thursday August 19, 2021 @09:46AM
(#28233761)
Compilers choose to not remove it in this case, probably because there is no clean way of making assumptions that provide a way out, unlike in the example from the link, but the core point is as I mentioned "making progress", specificall< the Progress guarantee (https://en.cppreference.com/w/cpp/language/memory_model#Prog...)
In a valid C++ program, every thread eventually does one of the following:
* terminate
* makes a call to an I/O library function
* performs an access through a volatile glvalue
* performs an atomic operation or a synchronization operation
It's fairly obvious how a loop that has none of these side-effects is thus a target to get turned into one that's guaranteed to terminate.