<div dir="ltr"><div>Hi All,<br></div>Please find enclosed an updated and simplified patch along with a additional test for properly aligned variadic arguments.<br>Tom<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Jul 19, 2013 at 8:36 PM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com" target="_blank">eli.friedman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Thu, Jul 18, 2013 at 10:31 PM, Yun-Wei Lee <<a href="mailto:lee2041412@gmail.com">lee2041412@gmail.com</a>> wrote:<br>
> Thank for your suggestion.<br>
<div class="">><br>
> I have tried to use GetAlignedArgumentStackSize.<br>
</div>> It is so strange that this function may output uncorrectly.<br>
> For example, the StackSize will be 40 when handling the third function call<br>
> in main.<br>
<div class="">> If I modified the this function, it will fail one test.<br>
> I wonder this may be another bug in llvm......<br>
> And that's why I didn't use GetAlignedArgumentStackSize previously.<br>
><br>
</div>> Thank you!<br>
<br>
I'm sorry, I'm not that familiar with the code.  A brief look tells me<br>
that it's likely none of the patches are quite right;<br>
<a href="http://llvm.org/bugs/attachment.cgi?id=10897" target="_blank">http://llvm.org/bugs/attachment.cgi?id=10897</a> looks closer, but still<br>
not quite right.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Eli<br>
</font></span><div class="im HOEnZb"><br>
><br>
> On Thu, Jul 18, 2013 at 7:56 PM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>><br>
> wrote:<br>
>><br>
</div><div class="HOEnZb"><div class="h5">>> On Thu, Jul 18, 2013 at 8:36 AM, Yun-Wei Lee <<a href="mailto:lee2041412@gmail.com">lee2041412@gmail.com</a>> wrote:<br>
>> > <a href="http://llvm.org/bugs/show_bug.cgi?id=14792" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=14792</a><br>
>> ><br>
>> > Problem:<br>
>> >   In the i386 ABI Page 3-10, it said that the stack is aligned. However,<br>
>> > the<br>
>> > two example code show that does not handle the alignment correctly when<br>
>> > using variadic function. For example, if the size of the first argument<br>
>> > is<br>
>> > 17, the overflow_arg_area in va_list will be set to "address of first<br>
>> > argument + 16" instead of "address of first argument + 24" after calling<br>
>> > va_start.<br>
>> >   In addition, #6636 showed the same problem because in AMD64, arguments<br>
>> > is<br>
>> > passed by register at first, then pass by memory when run out of<br>
>> > register<br>
>> > (AMD64 ABI 3.5.7 rule 10).<br>
>> ><br>
>> > Why this problem happened?<br>
>> >   When calling va_start to set va_list, overflow_arg_area is not set<br>
>> > correctly. To set the overflow_arg_area correctly, we need to get the<br>
>> > FrameIndex correctly. Now, here comes the problem, llvm doesn't handle<br>
>> > it<br>
>> > correctly. It accounts for StackSize to compute the FrameIndex, and if<br>
>> > the<br>
>> > StackSize is not aligned, it will compute the wrong FrameIndex. As a<br>
>> > result<br>
>> > overflow_arg_area will not be set correctly.<br>
>> ><br>
>> > My Solution:<br>
>> > 1. Record the Align if it is located in Memory.<br>
>> > 2. If it is variadic function and needs to set FrameIndex, adjust the<br>
>> > stacksize.<br>
>><br>
>> Please read <a href="http://llvm.org/docs/DeveloperPolicy.html" target="_blank">http://llvm.org/docs/DeveloperPolicy.html</a> .  In<br>
>> particular, patches should be sent to llvm-commits, and patches should<br>
>> generally include a regression test.<br>
>><br>
>> In terms of the code, you might want to consider using<br>
>> llvm::RoundUpToAlignment.<br>
>><br>
>> -Eli<br>
><br>
><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div>