Undefined behaviors & Clang 3.3

Artur Skawina art.08.09 at gmail.com
Fri Jun 21 07:48:30 PDT 2013


On 06/21/13 15:48, eles wrote:
> On Friday, 21 June 2013 at 10:42:32 UTC, bearophile wrote:
>> qznc:
>>
>>> In D an integer overflow is defined, so there is no need to detect anything about it.
>>
>> A language should offer the programmer a way to specify when an integral overflow is acceptable. Otherwise the other cases are bugs. Clang 3.3 helps find some of those bugs.
> 
> I just wanted to say almost the same thing: that the original sentence should read:
> 
> 
> "In D an integer overflow is *badly or, at least, questionably and inflexibly* defined, so there is no *possibility* to detect anything *useful* about it."
> 
> Well, that was the flame for today.

Actually, it's the other way around - mandating wrapping is what makes it
possible for code to detect the overflow. Having overflow be undefined 
(C-like) means that the compiler as allowed to remove all code that
checks for or relies on the overflow happening.
Mandating /trapping/ on OF would be a bad idea for perf reasons, You can
implement both trapping and saturating arithmetic on top of wrapping.
As the people wanting these will either a) don't really care about
bare metal performance or a) use h/w acceleration (simd etc) anyway, it
isn't really a problem.

artur


More information about the Digitalmars-d mailing list