<html><head></head><body><div class="-x-evo-paragraph"><div>Thank you for your response.</div><div><br></div><blockquote type="cite"><div>It looks like support for the Windows ABI hasn't really been added to</div><div>LLVM's va_arg instruction at all, so it's falling back to the generic</div><div>implementation in SelectionDAG. To change that, you'll probably want</div><div>to hook into X86TargetLowering::LowerVAARG.</div></blockquote><div><br></div><div class="-x-evo-paragraph">Yes, finally I changed the behavior and generated a new VAArg with correct alignment when using Win64 conv. Don't know if it's correct but it works.</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>SDValue X86TargetLowering::LowerVAARG(SDValue Op, SelectionDAG &DAG) const {</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> assert(Subtarget->is64Bit() &&</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> "LowerVAARG only handles 64-bit va_arg!");</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> assert(Op.getNode()->getNumOperands() == 4);</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span></div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> MachineFunction &MF = DAG.getMachineFunction();</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> if (Subtarget->isCallingConvWin64(MF.getFunction()->getCallingConv()))</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> // The Win64 ABI uses char* instead of a structure.</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> </div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> // Win64 ABI stores the arguments on the stack with an alignment of 8 bytes</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> SDValue V = DAG.getVAArg(Op.getNode()->getVTList().VTs[0],</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> Loc(Op),</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span> Op.getOperand(0),</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span> Op.getOperand(1),</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span> Op.getOperand(2),</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> 8);</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span> return DAG.expandVAArg(V.getNode());</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>...</div><div><br></div><div>I searched everywhere (especially in LowerCall) to find out a function that can give me this stack argument alignment of 8 but I didn't find it. So, I hardcoded the value.</div><div><br></div><div>By the way, I didn't find any official information that talk about the argument alignment on the stack in the case of a Win64 call. </div><div><br></div><blockquote type="cite"><div>You ought to be able to</div><div>override the alignment of 32-bit types there. (Beware, it'll never be</div><div>able to handle the full breadth of C/C++ use-cases, there's a reason</div><div>Clang implements it directly and it's not purely for efficiency).</div></blockquote><div><br></div><div>What do you mean by "C/C++ use-cases" ? Does the va_arg will never be "fully working"? Why?</div><div><br></div><blockquote type="cite"><div>Alternatively, you might be able to get away with always doing an i64</div><div>va_arg and truncating the result if you control the front-end and</div><div>don't want to fully expand va_arg.</div></blockquote><div><br></div><div class="-x-evo-paragraph">Yes, I tried to implement this solution but given the different types, it becomes complicated quickly.</div><div class="-x-evo-paragraph"><br></div><div class="-x-evo-paragraph">Regards,</div><div class="-x-evo-paragraph">Gaƫl</div></div><div></div></body></html>