[cfe-dev] [RFC] Introduce overflow builtins

Eli Friedman eli.friedman at gmail.com
Thu Mar 22 17:41:18 PDT 2012


On Thu, Mar 22, 2012 at 5:19 PM, Joerg Sonnenberger
<joerg at britannica.bec.de> wrote:
> On Mon, Mar 19, 2012 at 02:03:34AM -0400, Xi Wang wrote:
>> With overflow builtins, programmers can implement the example
>> as follows.
>>
>> void *malloc_array(size_t n, size_t size)
>> {
>>       size_t bytes;
>>       if (__overflow_umul(&bytes, n, size))
>>               return NULL;
>>       return malloc(bytes);
>> }
>
> I see two different options for the functions:
>
> (1) Provide __overflow_ # op which derives the types from the arguments.
> In that case it should be just add, sub, div, mul, rem.
>
> (2) Provide __overflow_ # op # _ # type which is explicitly typed. Op is
> still naturally add, sub, div, mul, rem.
>
> Using "umul" doesn't add any value IMO. One practical issue is how
> should div/rem work for 0?

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...

-Eli




More information about the cfe-dev mailing list