[cfe-dev] [RFC] Introduce overflow builtins
Joerg Sonnenberger
joerg at britannica.bec.de
Thu Mar 22 17:19:11 PDT 2012
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?
Joerg
More information about the cfe-dev
mailing list