https://bugs.llvm.org/show_bug.cgi?id=47405

            Bug ID: 47405
           Summary: __attribute__((force_align_arg_pointer)) ignored by
                    non-virtual thunk on x86
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangb...@nondot.org
          Reporter: shadow_m...@mail.ru
                CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
                    richard-l...@metafoo.co.uk

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 (https://godbolt.org/z/a847vd):

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to