ObjC builtin functions for GNU back end

The current code in CGObjCGNU.cpp is incorrectly generating internal references to the ObjC runtime functions, so renaming in the IR generation can cause linkage problems. This patch switches to using the CodeGenModule routines.

David

P.S. I notice that LLVM 2.5 has support for checking overflow (yay!) are there any plans to expose these in clang? C1x will include support for overflow-tested operations, but the draft is not yet finalised.

clang.diff (3.6 KB)

It was perfectly possible to do overflow checks without explicit
intrinsics... it's hard to comment without a more explicit proposal
for a language extension.

-Eli

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

Something like:

int __builtin_add_check_overflow(int*, int, int)

Do you mean __builtin_signed_add_check_overflow? Or are we assuming
nobody cares about unsigned overflow?

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

So rather, "_Bool __builtin_signed_add_check_overflow(int*, int,
int)"? Seems reasonable, and rather easy to implement.

if (__builtin_expect(__builtin_add_check_overflow(&a, b, c), 0))

Note that LLVM doesn't support __builtin_expect...

-Eli

Something like:

int __builtin_add_check_overflow(int*, int, int)

Do you mean __builtin_signed_add_check_overflow? Or are we assuming
nobody cares about unsigned overflow?

I was assuming that these would be overloaded, like the atomic operations, and infer the type of operation from the types of the arguments, but they could equally be explicit.

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

So rather, "_Bool __builtin_signed_add_check_overflow(int*, int,
int)"? Seems reasonable, and rather easy to implement.

Sounds great.

if (__builtin_expect(__builtin_add_check_overflow(&a, b, c), 0))

Note that LLVM doesn't support __builtin_expect...

Yet...?

David

Patch is checked in.

- Fariborz

Yet! :slight_smile:

-Chris