[cfe-dev] [RFC] Introduce overflow builtins

Dave Zarzycki zarzycki at apple.com
Fri Mar 23 12:57:04 PDT 2012


On Mar 22, 2012, at 10:48 PM, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:

> On Thu, Mar 22, 2012 at 05:41:18PM -0700, Eli Friedman wrote:
>> Assuming the point of these builtins is primarily performance of
>> library implementations (since most projects would need some sort of
>> fallback for compilers which don't provide this builtin), I'm not sure
>> it makes sense to have div/rem at all; there isn't any underlying
>> llvm.div.with.overflow to map it to...
> 
> Signed division can overflow (INT_MIN / -1). There is also the question
> of division by 0. It seems natural to consider it as overflow in which
> case both div and rem make sense.


Given that people are going to use these builtins to implement secure/safe code, 
it would also be nice if __builtin_overflow_div() also _forced_ people to think about both the quotient and remainder at the same time. For example: __builtin_overflow_div(T *quotient, T *remainder, T value, T divisor).

davez



More information about the cfe-dev mailing list