<div dir="ltr"><a href="http://llvm.org/bugs/show_bug.cgi?id=14792" target="_blank" style="font-family:arial,sans-serif;font-size:12.727272033691406px">http://llvm.org/bugs/show_bug.cgi?id=14792</a><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">Problem:</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">
In the i386 ABI Page 3-10, it said that the stack is aligned. However, the two example code show that does not handle the alignment correctly when using variadic function. For example, if the size of the first argument is 17, the overflow_arg_area in va_list will be set to "address of first argument + 16" instead of "address of first argument + 24" after calling va_start.</div>
<div style="font-family:arial,sans-serif;font-size:12.727272033691406px"> In addition, #6636 showed the same problem because in AMD64, arguments is passed by register at first, then pass by memory when run out of register (AMD64 ABI 3.5.7 rule 10).</div>
<div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">Why this problem happened?</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">
When calling va_start to set va_list, overflow_arg_area is not set correctly. To set the overflow_arg_area correctly, we need to get the FrameIndex correctly. Now, here comes the problem, llvm doesn't handle it correctly. It accounts for StackSize to compute the FrameIndex, and if the StackSize is not aligned, it will compute the wrong FrameIndex. As a result overflow_arg_area will not be set correctly.</div>
<div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">My Solution:</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">
1. Record the Align if it is located in Memory.</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">2. If it is variadic function and needs to set FrameIndex, adjust the stacksize.</div></div>