GCC Undefined Behavior Sanitizer

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Sun Oct 19 01:56:48 PDT 2014


On 19 Oct 2014 09:40, "monarch_dodra via Digitalmars-d" <
digitalmars-d at puremagic.com> wrote:
>
> On Saturday, 18 October 2014 at 23:10:15 UTC, Ola Fosheim Grøstad wrote:
>>
>> On Saturday, 18 October 2014 at 08:22:25 UTC, monarch_dodra wrote:
>>>
>>> Besides, the code uses x + 1, so the code is already in undefined
state. It's just as wrong as the "horrible code with UB" we wère trying to
avoid in the first place.
>>>
>>> So much for convincing me that it's a good idea...
>>
>>
>> Not sure if you are saying that modulo-arithmetic as a default is a bad
or good idea?
>
>
> Op usually suggested that all overflows should be undefined behavior, and
that you could "pre-emptivelly" check for overflow with the above code. The
code provided itself overflowed, so was also undefined.
>
> What I'm pointing out is that working with undefined behavior overflow is
exceptionally difficult, see later.
>
>
>> In D and (C++ for uint) it is modulo-arithmetic so it is defined as a
circular type with at discontinuity which makes reasoning about integers
harder.
>
>
> What interesting is that overflow is only defined for unsigned integers.
signed integer overflow is *undefined*, and GCC *will* optimize away any
conditions that rely on it.
>

Good thing that overflow is strictly defined in D then. You can rely on
overflowing to occur rather than be optimised away.

Iain.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141019/98875dfd/attachment.html>


More information about the Digitalmars-d mailing list