[cfe-dev] ObjC builtin functions for GNU back end

David Chisnall csdavec at swansea.ac.uk
Mon Mar 30 10:43:18 PDT 2009


On 30 Mar 2009, at 18:25, Eli Friedman wrote:

>> P.S. I notice that LLVM 2.5 has support for checking overflow  
>> (yay!) are
>> there any plans to expose these in clang?
>
> It was perfectly possible to do overflow checks without explicit
> intrinsics...

Possible, but difficult to do in a way that is both fast and correct,  
hence the C1x extensions, although the C1x extensions are likely to  
require a callback being invoked when overflow happens.

> it's hard to comment without a more explicit proposal
> for a language extension.


Something like:

int __builtin_add_check_overflow(int*, int, int)

Would be be nice, with the return being a zero-extended version of the  
i1 (or, since clang supports arbitrary-with integers now, leaving it  
as an i1, as long as this can be used in a comparison).  I'd imagine  
using it something like this:

// Safe version of: a = b + c;
if (__builtin_expect(__builtin_add_check_overflow(&a, b, c), 0))
{
	// Handle overflow
}

David



More information about the cfe-dev mailing list