I was not talking about integer overflow there. I was talking about shadow spin locking (spinning on a regular read instead of a locked cmpxchg) and how I suspect it is UB under C11.syzygy wrote:If you allow signed overflow to return ANY bit pattern, it seems difficult to imagine any program (written by a programmer well aware that signed overflow can return ANY bit pattern) that on purpose lets integers overflow.wgarvin wrote:The least they ought to have done, was define some semantics for it with unsigned integer types, providing that it might return ANY bit pattern, but would not trap or otherwise blow up. I have a hard time imagining a C-capable platform that could not meet that requirement.
If C11 had specified that a "data race" on an unsigned int resulted in undefined values instead of UB, it would be possible to implement such things without entering UB territory, and I can't really imagine an optim that would be possible because of that UB, so there wouldn't be much downside that I can see to defining it.
For integer overflow, the costs/benefits would be different, and its clear at least that the UB of integer overflow is valuable to optimizers.