[llvm-bugs] [Bug 48595] New: bad codegen for regcall when passing large argument on stack for function with different calling convention on i686-w64-mingw32

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 24 23:10:04 PST 2020


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

            Bug ID: 48595
           Summary: bad codegen for regcall when passing large argument on
                    stack for function with different calling convention
                    on i686-w64-mingw32
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mizvekov at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Compiling the following program with `clang -target i686-w64-mingw32 -g -O2
test.cc` will produce binary with bad code, which will cause program to
segfault when run:

```
struct baz { char buf[sizeof(long long) + 1]{}; };
struct bar {
        baz a;
        [[gnu::noinline]] bar(baz a) : a{a} {}
};

[[gnu::regcall, gnu::noinline]] static void foo() { bar c{baz{}}; }

int main() {
        const volatile char a = 1;
        foo();
        return a;
}
```

This is generated assembly for `foo`:

```
004015f0 <__regcall3__foo()>:
  4015f0:       55                      push   %ebp
  4015f1:       89 e5                   mov    %esp,%ebp
  4015f3:       54                      push   %esp
  4015f4:       83 e4 f0                and    $0xfffffff0,%esp
  4015f7:       81 ec 80 00 00 00       sub    $0x80,%esp
  4015fd:       0f 29 7d e8             movaps %xmm7,-0x18(%ebp)
  401601:       0f 29 75 d8             movaps %xmm6,-0x28(%ebp)
  401605:       0f 29 6d c8             movaps %xmm5,-0x38(%ebp)
  401609:       0f 29 65 b8             movaps %xmm4,-0x48(%ebp)
  40160d:       c7 44 24 1c 00 00 00 00         movl   $0x0,0x1c(%esp)
  401615:       c7 44 24 18 00 00 00 00         movl   $0x0,0x18(%esp)
  40161d:       c6 44 24 20 00          movb   $0x0,0x20(%esp)
  401622:       8d 4c 24 24             lea    0x24(%esp),%ecx
  401626:       8a 44 24 20             mov    0x20(%esp),%al
  40162a:       88 44 24 08             mov    %al,0x8(%esp)
  40162e:       f2 0f 10 44 24 18       movsd  0x18(%esp),%xmm0
  401634:       f2 0f 11 04 24          movsd  %xmm0,(%esp)
  401639:       e8 52 10 00 00          call   402690 <bar::bar(baz)>
  40163e:       83 ec 0c                sub    $0xc,%esp
  401641:       0f 28 65 b8             movaps -0x48(%ebp),%xmm4
  401645:       0f 28 6d c8             movaps -0x38(%ebp),%xmm5
  401649:       0f 28 75 d8             movaps -0x28(%ebp),%xmm6
  40164d:       0f 28 7d e8             movaps -0x18(%ebp),%xmm7
  401651:       8d 65 fc                lea    -0x4(%ebp),%esp
  401654:       5c                      pop    %esp
  401655:       5d                      pop    %ebp
  401656:       c3                      ret
  401657:       66 90                   xchg   %ax,%ax
  401659:       66 90                   xchg   %ax,%ax
  40165b:       66 90                   xchg   %ax,%ax
  40165d:       66 90                   xchg   %ax,%ax
  40165f:       90                      nop
```

The execution will segfault at the first movaps, because the memory address
does not satisfy alignment for this instruction (movups should be used
instead). Windows x86 ABI does not require stack to be 16 byte aligned unlike
Linux for example.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201225/00f276db/attachment.html>


More information about the llvm-bugs mailing list