<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - __attribute__((force_align_arg_pointer)) ignored by non-virtual thunk on x86"
   href="https://bugs.llvm.org/show_bug.cgi?id=47405">47405</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__attribute__((force_align_arg_pointer)) ignored by non-virtual thunk on x86
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>shadow_mosk@mail.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Compiler generates incorrect non-virtual thunk in case of multiple inheritance.
It seems that clang ignores __attribute__((force_align_arg_pointer)) for thunk
and accepts it only for original function.

GCC (at least 7.3.0) handles the alignment correctly for original function and
for thunk.

As workaround we use an option -mstackrealign for clang.
But it causes unnecessary alternative prologue/epilogue for functions without
problematic thunks.

Minimal test case (<a href="https://godbolt.org/z/a847vd">https://godbolt.org/z/a847vd</a>):

Options: -target i386-pc-linux-gnu -O2

#include <stdio.h>
#include <memory.h>

struct A
{
    virtual void TestA() { printf("TestA\n"); }
};

struct B
{
    //__attribute__((force_align_arg_pointer))
    virtual void TestB() { printf("TestB\n"); }
};

struct C : public A, public B
{
    __attribute__((force_align_arg_pointer))
    virtual void TestB() { printf("TestB by C\n"); }

    virtual void TestC() { printf("TestC\n"); }
};


----------------------------------------------------------
CLANG 8, 9, 10

C::TestB():                          # @C::TestB()
        push    ebp
        mov     ebp, esp
        and     esp, -16   <--- Stack alignment
        sub     esp, 16
        mov     dword ptr [esp], offset .Lstr.5
        call    puts
        mov     esp, ebp
        pop     ebp
        ret

non-virtual thunk to C::TestB():     # @non-virtual thunk to C::TestB()
        sub     esp, 12    <--- No Stack alignment
        mov     dword ptr [esp], offset .Lstr.5
        call    puts
        add     esp, 12
        ret

-----------------------------------------
GCC 7.3.0:

C::TestB():
        lea     ecx, [esp+4]
        and     esp, -16
        push    DWORD PTR [ecx-4]
        push    ebp
        mov     ebp, esp
        push    ecx
        sub     esp, 16
        push    OFFSET FLAT:.LC2
        call    puts
        mov     ecx, DWORD PTR [ebp-4]
        add     esp, 16
        leave
        lea     esp, [ecx-4]
        ret

non-virtual thunk to C::TestB():
        lea     ecx, [esp+4]
        and     esp, -16
        push    DWORD PTR [ecx-4]
        push    ebp
        mov     ebp, esp
        push    ecx
        sub     esp, 16
        push    OFFSET FLAT:.LC2
        call    puts
        mov     ecx, DWORD PTR [ebp-4]
        add     esp, 16
        leave
        lea     esp, [ecx-4]
        ret</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>