3 ms·
I looked at the source now and found nothing specific. The optimisation seems to be wrong; clang returns a constant 1, which assumes that the function is never
by Arnt 7y ago
I looked at the source now and found nothing specific.
The optimisation seems to be wrong; clang returns a constant 1, which assumes that the function is never called with n=0. Which is true for the Collatz conjecture (it starts at 1), but surely clang has no right to assume that n≥1?
- clmul 7y agoThis assumption is allowed, as n=0 results in infinite recursion (without side-effects) which is undefined behavior: https://en.cppreference.com/w/cpp/language/memory_model https://en.cppreference.com/w/cpp/language/memory_model https://en.cppreference.com/w/cpp/language/ub#Infinite_loop_without_side-effects https://en.cppreference.com/w/cpp/language/ub#Infinite_loop_...
- Arnt 7y agoOh, right. I knew the "eventually must" rule, but missed the implication.