[cfe-dev] [Patch] __builtin_expect uses long, not int

Ed Schouten ed at 80386.nl
Sat Oct 31 04:19:13 PDT 2009


Hi folks,

Robert Watson discovered an issue with __builtin_expect() while porting
libdispatch to FreeBSD/amd64. According to the GCC docs,
__builtin_expect looks like this:

| long __builtin_expect (long exp, long c);

But currently we use this line in Builtins.def:

| BUILTIN(__builtin_expect, "iii"   , "nc")

This means the arguments and the return value are of type int. This
breaks libdispatch, because it tries to pass pointers through this
function.

Patch:

Index: include/clang/Basic/Builtins.def
===================================================================
--- include/clang/Basic/Builtins.def	(revision 85650)
+++ include/clang/Basic/Builtins.def	(working copy)
@@ -329,7 +329,7 @@
 BUILTIN(__builtin___vfprintf_chk, "iP*icC*a", "FP:2:")
 BUILTIN(__builtin___vprintf_chk, "iicC*a", "FP:1:")
 
-BUILTIN(__builtin_expect, "iii"   , "nc")
+BUILTIN(__builtin_expect, "LiLiLi", "nc")
 BUILTIN(__builtin_prefetch, "vvC*.", "nc")
 BUILTIN(__builtin_abort, "v", "Fnr")
 BUILTIN(__builtin_trap, "v", "nr")

I've been thinking about adding some tests to the test suite. Maybe we
could test something along these lines:

| ULONG_MAX == __builtin_expect(ULONG_MAX, 1)

-- 
 Ed Schouten <ed at 80386.nl>
 WWW: http://80386.nl/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091031/cedd7821/attachment.sig>


More information about the cfe-dev mailing list