What I meant:

Run-time: I have written an enhancement request for LLVM about optimizing much 
better the simple operations needed to spot and use the overflows. LLVM dev 
team has implemented it in 2.8 or 2.9. Such optimizations are not optional, if 
you want people to use overflow tests they need to be efficient. Even the 
advanced optimizations done by LLVM weren't good enough until few months ago.

Compile-time: D is able to run code at compile-time too, but only where you ask 
it explicitly, using or assigning the result where a compile-time constant is 
required. I think this means compile-time overflow tests will usually not 
happen.

There are routines for run-time overflow tests in C and C++, but I am not 
seeing them used. While in Delphi I use overflow tests all the time and I see 
code written by other people that have runtime overflow tests switched on. I 
think that to catch integral overflow bugs in programs you can't just add a 
SafeInt struct, you need a compiler-wide switch. Otherwise most people will not 
use it. Array bound tests are able to catch bugs in normal D code written by 
everybody because you don't need to use a SafeArray instead of the built in 
arrays and because array bound tests are active on default, you need a switch 
to disable them. A bit more syntax is needed to disable tests locally, where 
needed.

Bye,
bearophile

Reply via email to