<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 31, 2009, at 4:19 AM, Ed Schouten wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi folks,<br><br>Robert Watson discovered an issue with __builtin_expect() while porting<br>libdispatch to FreeBSD/amd64. According to the GCC docs,<br>__builtin_expect looks like this:<br><br>| long __builtin_expect (long exp, long c);<br><br>But currently we use this line in Builtins.def:<br><br>| BUILTIN(__builtin_expect, "iii"   , "nc")<br><br>This means the arguments and the return value are of type int. This<br>breaks libdispatch, because it tries to pass pointers through this<br>function.<br></div></blockquote><div><br></div><div>Ow, good catch. </div><br><blockquote type="cite"><div>Patch:<br><br>Index: include/clang/Basic/Builtins.def<br>===================================================================<br>--- include/clang/Basic/Builtins.def<span class="Apple-tab-span" style="white-space:pre">    </span>(revision 85650)<br>+++ include/clang/Basic/Builtins.def<span class="Apple-tab-span" style="white-space:pre">      </span>(working copy)<br>@@ -329,7 +329,7 @@<br> BUILTIN(__builtin___vfprintf_chk, "iP*icC*a", "FP:2:")<br> BUILTIN(__builtin___vprintf_chk, "iicC*a", "FP:1:")<br><br>-BUILTIN(__builtin_expect, "iii"   , "nc")<br>+BUILTIN(__builtin_expect, "LiLiLi", "nc")<br> BUILTIN(__builtin_prefetch, "vvC*.", "nc")<br> BUILTIN(__builtin_abort, "v", "Fnr")<br> BUILTIN(__builtin_trap, "v", "nr")<br></div></blockquote><div><br></div><div>Thank you, committed here:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">  <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20091026/022975.html">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20091026/022975.html</a></span></div><br><blockquote type="cite"><div>I've been thinking about adding some tests to the test suite. Maybe we<br>could test something along these lines:<br><br>| ULONG_MAX == __builtin_expect(ULONG_MAX, 1)<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><br></div><div>Since we avoid executable tests in the test-suite, we'd want to look at the generated IR to make sure it preserves the value of LONG_MAX. However, I settled for something a little simpler:</div><div><br></div><div><span class="Apple-style-span" style="color: rgb(205, 0, 166); font-family: Menlo; font-size: 11px; ">extern<span style="color: #000000"> </span>long<span style="color: #000000"> </span>int<span style="color: #000000"> bi0;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(205, 0, 166); ">extern<span style="color: #000000"> </span>__typeof__<span style="color: #000000">(</span><span style="color: #3e8388">__builtin_expect</span><span style="color: #000000">(</span><span style="color: #3c00df">0</span><span style="color: #000000">, </span><span style="color: #3c00df">0</span><span style="color: #000000">)) bi0;</span></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">      </span>- Doug</div><br></body></html>