<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jul 24, 2013, at 11:13 PM, Reid Kleckner wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div>Sounds good mostly, but I happen to be in the middle of untangling the mess of CC_Default != CC_C.</div><div><br></div>One thing that should probably work here is if I'm targeting a platform where sysv_abi is equivalent to the default cc, a sysv_abi function should be compatible with a normal function pointer.  Similarly when targeting Windows, an ms_abi function is probably compatible with a normal function pointer.  Please see what gcc does and add tests that show that we match it.</div></blockquote>That's definitely true, and I should've known better ;). In fact, GCC will allow a sysv_abi function to be assigned to a plain function pointer on non-Windows, or an ms_abi function to be assigned to a plain function pointer on Windows.</div><div><br></div><div>Some other findings of mine:</div><div><br></div><div>- The ms_abi and sysv_abi attributes cannot be used together in the same declaration. But it is possible to declare a function with one, and then with the other later. This behavior doesn't make sense to me. Since they aren't compatible, we should always err in both cases.</div><div>- Either one can be combined with cdecl. Personally, I think that should only be possible with the one that is the default for that platform (since cdecl maps to CC_C in the AST, and thus, to ccc in the IR), but I'll defer to your judgment.</div><div>- Either one can also be combined with the regparm() attribute. Apparently, GCC ignores regparm and cdecl on x86-64, just as it ignores ms_abi and sysv_abi on i386 (see below). We seem to ignore regparm() on x86-64 as well.<br><blockquote type="cite"><div dir="ltr"><div>
<br></div><div>Hm, now I worry if we have a bug in LLVM.  LLVM will replace calls with the wrong cc with unreachable, I think, and it may not know that x86_64_sysv_cc is compatible with ccc on non-Windows OSs.<br></div></div></blockquote>Great. That's one corner case I forgot. I'll have to make a patch LLVM to handle this. Looks like I'll have to add Anton's target CC hook after all.<br><blockquote type="cite"><div dir="ltr"><div><div><br>
</div><div>Also, what does ms_abi do on x86_32?</div></div></div></blockquote>In older versions of GCC (up to 4.6.x), it's ignored. In fact, you'll get a -Wattributes warning telling you this. That's why I didn't handle it for i386.<br><blockquote type="cite"><div dir="ltr"><div><div>  Is it stdcall or cdecl?  Add a test for i686.</div></div></div></blockquote>Actually, it's whatever the default calling convention is. Normally, that's __cdecl, unless you pass -mrtd; then it's __stdcall. It's still ignored on i386; it's just that gcc won't warn on it anymore (for some reason). I haven't been able to find anything in their Bugzilla about it. (This is at least true on 4.7, but I really don't feel like building 4.8 to find out if that's changed. It took all day just for the computer running Linux to build 4.7 so I could verify this for you. ;)</div><div><br></div><div>The question is, since it has no effect on any platform except x86-64, should *we* warn about it? I think we should.</div><div><br></div><div>I have a new patch, but I need to test it first. I'm also tired. I'll have it for you tomorrow morning (hopefully).</div><div><br></div><div>Chip</div><div><br><blockquote type="cite"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 24, 2013 at 10:50 PM, Charles Davis <span dir="ltr"><<a href="mailto:cdavis5x@gmail.com" target="_blank">cdavis5x@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div class="h5"><div>On Jul 12, 2013, at 5:48 AM, Reid Kleckner wrote:</div>
<br><blockquote type="cite"><div dir="ltr">On Tue, Jun 18, 2013 at 6:25 AM, Benno Rice <span dir="ltr"><<a href="mailto:benno@freebsd.org" target="_blank">benno@freebsd.org</a>></span> wrote:<br><div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">
<br><div><div><div>On 12/06/2013, at 10:40 PM, Reid Kleckner <<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>> wrote:</div>
<br></div><blockquote type="cite"><div dir="ltr"><div>On Wed, Jun 12, 2013 at 7:13 AM, Charles Davis <span dir="ltr"><<a href="mailto:cdavis5x@gmail.com" target="_blank">cdavis5x@gmail.com</a>></span> wrote:<br>
</div><div><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div>
<div>You mean like in my patch here:</div></div></div></div><div><br></div><div><a href="http://llvm-reviews.chandlerc.com/D729" target="_blank">http://llvm-reviews.chandlerc.com/D729</a></div><div><div>
<br></div><div>?</div></div></div></blockquote><div><br></div><div>Yeah, that looks good to me.  :)</div><div><br></div><div>From the docs, it seems attr(ms_abi) just maps to x86_64_win64cc and x86_stdcallcc depending on the architecture:</div>


<div><a href="http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bsysv_005fabi_007d-attribute-2670" target="_blank">http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bsysv_005fabi_007d-attribute-2670</a></div>


<div>gcc also appears to support a sysv_abi attribute, which lets you use the sysv CCs when targeting Windows.</div></div></div></div></div>
</blockquote></div><br><div>So what's in the way of this being committed? Is there anything I can do that would accelerate things?</div></div></blockquote><div><br></div><div>Benno, Charles added explicit sysv and win64 CCs to LLVM.  Feel free to update your clang patch based on that and resend. </div>

</div></div></div>
</blockquote></div></div>I can wait no longer...</div><div><br></div><div>I've taken the Clang side of Benno's patch, updated it against my LLVM patch, and rebased it against trunk. I also added the complementary sysv_abi attribute.</div>
<div><br></div><div>OK to commit?</div><div><br></div><div>Chip</div><div><br></div></div><br><div style="word-wrap:break-word"></div><br></blockquote></div><br></div>
</blockquote></div><br></body></html>