<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div></div><div><br></div><div>As you can see in the attached files the code gen for the va_list is different (and the calling conventions are different too) for clang vs clang -ccc-host-triple x86_64-pc-win32-macho.</div><div><br></div><div><div>int</div><div>ReturnMarker (</div><div> VA_LIST Marker</div><div> )</div><div>{</div><div> return VA_ARG (Marker, int);</div><div>}</div></div><div><br></div><div><div>_ReturnMarker: ## @ReturnMarker clang</div><div>Leh_func_begin0:</div><div>## BB#0:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>pushq<span class="Apple-tab-span" style="white-space:pre"> </span>%rbp</div><div>Ltmp0:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>%rsp, %rbp</div><div>Ltmp1:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movslq<span class="Apple-tab-span" style="white-space:pre"> </span>(%rdi), %rax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>cmpq<span class="Apple-tab-span" style="white-space:pre"> </span>$40, %rax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ja<span class="Apple-tab-span" style="white-space:pre"> </span>LBB0_2</div><div>## BB#1:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>16(%rdi), %rcx</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>addq<span class="Apple-tab-span" style="white-space:pre"> </span>%rax, %rcx</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>addl<span class="Apple-tab-span" style="white-space:pre"> </span>$8, %eax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movl<span class="Apple-tab-span" style="white-space:pre"> </span>%eax, (%rdi)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>jmp<span class="Apple-tab-span" style="white-space:pre"> </span>LBB0_3</div><div>LBB0_2:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>8(%rdi), %rcx</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>leaq<span class="Apple-tab-span" style="white-space:pre"> </span>8(%rcx), %rax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>%rax, 8(%rdi)</div><div>LBB0_3:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movl<span class="Apple-tab-span" style="white-space:pre"> </span>(%rcx), %eax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>popq<span class="Apple-tab-span" style="white-space:pre"> </span>%rbp</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ret</div></div><div><br></div><div><div>_ReturnMarker: ## @ReturnMarker clang -ccc-host-triple x86_64-pc-win32-macho Marker == rcx</div><div>Leh_func_begin0:</div><div>## BB#0:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>(%rcx), %rax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>leaq<span class="Apple-tab-span" style="white-space:pre"> </span>8(%rax), %rdx</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>%rdx, (%rcx)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movl<span class="Apple-tab-span" style="white-space:pre"> </span>(%rax), %eax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ret</div></div><div><br></div><div><br></div><div><br></div><div><div><div>Marker$ = 8</div><div>ReturnMarker PROC NEAR cl /FAcs v.c /Os # Visual Studio</div><div><br></div><div>; 16 : {</div><div><br></div><div> 00000<span class="Apple-tab-span" style="white-space:pre"> </span>48 89 4c 24 08<span class="Apple-tab-span" style="white-space:pre"> </span> mov<span class="Apple-tab-span" style="white-space:pre"> </span> QWORD PTR [rsp+8], rcx</div><div><br></div><div>; 17 : return VA_ARG (Marker, int);</div><div><br></div><div> 00005<span class="Apple-tab-span" style="white-space:pre"> </span>48 8b 44 24 08<span class="Apple-tab-span" style="white-space:pre"> </span> mov<span class="Apple-tab-span" style="white-space:pre"> </span> rax, QWORD PTR Marker$[rsp]</div><div> 0000a<span class="Apple-tab-span" style="white-space:pre"> </span>48 83 c0 08<span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span>add<span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> rax, 8</div><div> 0000e<span class="Apple-tab-span" style="white-space:pre"> </span>48 89 44 24 08<span class="Apple-tab-span" style="white-space:pre"> </span> mov<span class="Apple-tab-span" style="white-space:pre"> </span> QWORD PTR Marker$[rsp], rax</div><div> 00013<span class="Apple-tab-span" style="white-space:pre"> </span>48 8b 44 24 08<span class="Apple-tab-span" style="white-space:pre"> </span> mov<span class="Apple-tab-span" style="white-space:pre"> </span> rax, QWORD PTR Marker$[rsp]</div><div> 00018<span class="Apple-tab-span" style="white-space:pre"> </span>8b 40 f8<span class="Apple-tab-span" style="white-space:pre"> </span> mov<span class="Apple-tab-span" style="white-space:pre"> </span> eax, <span class="Apple-tab-span" style="white-space:pre"> </span>DWORD PTR [rax-8]</div><div><br></div><div>; 18 : }</div><div><br></div><div> 0001b<span class="Apple-tab-span" style="white-space:pre"> </span>c3<span class="Apple-tab-span" style="white-space:pre"> </span> ret<span class="Apple-tab-span" style="white-space:pre"> </span> 0</div><div>ReturnMarker ENDP</div></div></div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">ret$ = 32</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">Marker$ = 40</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">Handle$ = 64</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">Test<span class="Apple-tab-span" style="white-space:pre"> </span>PROC NEAR</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><span class="Apple-style-span" style="font-size: medium;"><font class="Apple-style-span" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></span></div></div><div><br></div><div>But sizeof (__builtin_va_list) returns 24 bytes in both cases and this would seem to indicate the compiler using a mixture of va_list schemes? </div><div><br></div><div><div>int</div><div>Test2 ()</div><div>{</div><div> return sizeof (VA_LIST);</div><div>}</div></div><div><br></div><div><br></div><div><div>_Test2: ## @Test2 clang </div><div>Leh_func_begin2:</div><div>## BB#0:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>pushq<span class="Apple-tab-span" style="white-space:pre"> </span>%rbp</div><div>Ltmp5:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>%rsp, %rbp</div><div>Ltmp6:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movl<span class="Apple-tab-span" style="white-space:pre"> </span>$24, %eax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>popq<span class="Apple-tab-span" style="white-space:pre"> </span>%rbp</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ret</div><div><br></div><div>_Test2: ## @Test2 clang -ccc-host-triple x86_64-pc-win32-macho</div><div>Leh_func_begin2:</div><div>## BB#0:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movl<span class="Apple-tab-span" style="white-space:pre"> </span>$24, %eax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ret</div></div><div><br></div><div><br></div><div>Any help on fixing this would be greatly appreciated. </div><div><br></div><div>One more thing, in the failing case the va_list was being passed on the stack and not in a register since it was the 5th or 6th argument.</div><div><br></div><div>Thanks,</div><div><br></div><div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; font-size: 12px; "><div>Andrew Fish</div><div><br></div><div><div>clang -v</div><div>clang version 3.0 (trunk 127294)</div><div>Target: x86_64-apple-darwin10</div><div>Thread model: posix</div></div><div><br></div><div><br></div><div><br></div></div>PS I also noticed that the clang -ccc-host-triple x86_64-pc-win32-macho is not reserving the 32 bytes on the stack so the callee can spill the registers. I think this may be a violation of the 64-bit Windows calling convention? <br class="Apple-interchange-newline"><br class="Apple-interchange-newline">
</div><div><div>_Test: ## @Test</div><div>Leh_func_begin1:</div><div>## BB#0:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>subq<span class="Apple-tab-span" style="white-space:pre"> </span>$24, %rsp</div><div>Ltmp0:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>%r9, 56(%rsp)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>%r8, 48(%rsp)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>%rdx, 40(%rsp)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>leaq<span class="Apple-tab-span" style="white-space:pre"> </span>40(%rsp), %rax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>%rax, (%rsp)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>leaq<span class="Apple-tab-span" style="white-space:pre"> </span>48(%rsp), %rax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>%rax, (%rsp)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movl<span class="Apple-tab-span" style="white-space:pre"> </span>40(%rsp), %eax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>addq<span class="Apple-tab-span" style="white-space:pre"> </span>$24, %rsp</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ret</div></div><div><br></div><div><br class="webkit-block-placeholder"></div><div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">ret$ = 32</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">Marker$ = 40</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">Handle$ = 64</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">Test<span class="Apple-tab-span" style="white-space:pre"> </span>PROC NEAR</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">; 26 : {</div><div><br></div></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">$LN3:</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 00030<span class="Apple-tab-span" style="white-space: pre; "> </span>48 89 4c 24 08<span class="Apple-tab-span" style="white-space: pre; "> </span> mov<span class="Apple-tab-span" style="white-space: pre; "> </span> QWORD PTR [rsp+8], rcx</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 00035<span class="Apple-tab-span" style="white-space: pre; "> </span>48 89 54 24 10<span class="Apple-tab-span" style="white-space: pre; "> </span> mov<span class="Apple-tab-span" style="white-space: pre; "> </span> QWORD PTR [rsp+16], rdx</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 0003a<span class="Apple-tab-span" style="white-space: pre; "> </span>4c 89 44 24 18<span class="Apple-tab-span" style="white-space: pre; "> </span> mov<span class="Apple-tab-span" style="white-space: pre; "> </span> QWORD PTR [rsp+24], r8</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 0003f<span class="Apple-tab-span" style="white-space: pre; "> </span>4c 89 4c 24 20<span class="Apple-tab-span" style="white-space: pre; "> </span> mov<span class="Apple-tab-span" style="white-space: pre; "> </span> QWORD PTR [rsp+32], r9</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 00044<span class="Apple-tab-span" style="white-space: pre; "> </span>48 83 ec 38<span class="Apple-tab-span" style="white-space: pre; "> </span> sub<span class="Apple-tab-span" style="white-space: pre; "> </span> rsp, 56<span class="Apple-tab-span" style="white-space: pre; "> </span>; 00000038H</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">; 27 : VA_LIST Marker;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">; 28 : int ret;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">; 29 : </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">; 30 : VA_START (Marker, Handle);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 00048<span class="Apple-tab-span" style="white-space: pre; "> </span>48 8d 44 24 48<span class="Apple-tab-span" style="white-space: pre; "> </span> lea<span class="Apple-tab-span" style="white-space: pre; "> </span> rax, QWORD PTR Handle$[rsp+8]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 0004d<span class="Apple-tab-span" style="white-space: pre; "> </span>48 89 44 24 28<span class="Apple-tab-span" style="white-space: pre; "> </span> mov<span class="Apple-tab-span" style="white-space: pre; "> </span> QWORD PTR Marker$[rsp], rax</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">; 31 : ret = ReturnMarker (Marker);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 00052<span class="Apple-tab-span" style="white-space: pre; "> </span>48 8b 4c 24 28<span class="Apple-tab-span" style="white-space: pre; "> </span> mov<span class="Apple-tab-span" style="white-space: pre; "> </span> rcx, QWORD PTR Marker$[rsp]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 00057<span class="Apple-tab-span" style="white-space: pre; "> </span>e8 00 00 00 00<span class="Apple-tab-span" style="white-space: pre; "> </span> call<span class="Apple-tab-span" style="white-space: pre; "> </span> ReturnMarker</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 0005c<span class="Apple-tab-span" style="white-space: pre; "> </span>89 44 24 20<span class="Apple-tab-span" style="white-space: pre; "> </span> mov<span class="Apple-tab-span" style="white-space: pre; "> </span> DWORD PTR ret$[rsp], eax</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">; 32 : VA_END (Marker);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 00060<span class="Apple-tab-span" style="white-space: pre; "> </span>48 c7 44 24 28</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><span class="Apple-tab-span" style="white-space: pre; "> </span>00 00 00 00<span class="Apple-tab-span" style="white-space: pre; "> </span> mov<span class="Apple-tab-span" style="white-space: pre; "> </span> QWORD PTR Marker$[rsp], 0</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">; 33 : </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">; 34 : return ret;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "> 00069<span class="Apple-tab-span" style="white-space: pre; "> </span>8b 44 24 20<span class="Apple-tab-span" style="white-space: pre; "> </span> mov<span class="Apple-tab-span" style="white-space: pre; "> </span> eax, DWORD PTR ret$[rsp]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">; 35 : }</div></div></div><div><br></div><div><br class="webkit-block-placeholder"></div>
<br></body></html>