Undefined behaviors & Clang 3.3

qznc qznc at web.de
Fri Jun 21 01:20:47 PDT 2013


On Thursday, 20 June 2013 at 14:28:42 UTC, bearophile wrote:
> Another nice post about the Integer Undefined Behavior 
> Detection of Clang 3.3:
>
> http://blog.regehr.org/archives/963
>
>>Until these languages die, which isn’t going to happen anytime 
>>soon, our best defense against undefined behaviors is to write 
>>better checking tools.<
>
> Some potential bugs it has found:
>
> http://article.gmane.org/gmane.comp.fonts.freetype.devel/8817
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57324
>
> http://blog.regehr.org/extra_files/perl-test-output.txt
>
> Things like this in gcc:
>
> gcc/gcc/simplify-rtx.c:4004:16: runtime error: signed integer 
> overflow: -1844674407370955161 + -9223372036854775808 cannot be 
> represented in type 'long'
> gcc/gcc/stor-layout.c:2543:45: runtime error: signed integer 
> overflow: -9223372036854775808 - 1 cannot be represented in 
> type 'long'
>
> Is someone able to compile and run the dmd source code with 
> Clang with "-fsanitize=undefined"?
> And is it possible to add -fsanitize=undefined to ldc2?
>
> Bye,
> bearophile

In D an integer overflow is defined, so there is no need to 
detect anything about it. See Spec:

"If both operands are of integral types and an overflow or 
underflow occurs in the computation, wrapping will happen. That 
is, uint.max + 1 == uint.min and uint.min - 1 == uint.max."
http://dlang.org/expression.html


More information about the Digitalmars-d mailing list