]> granicus.if.org Git - clang/commit
[X86] Fix i386 struct and union parameter alignment
authorPengfei Wang <pengfei.wang@intel.com>
Wed, 29 May 2019 08:42:35 +0000 (08:42 +0000)
committerPengfei Wang <pengfei.wang@intel.com>
Wed, 29 May 2019 08:42:35 +0000 (08:42 +0000)
commit3ae15d2c9fbebdd0847144ea7b80729ac150ceda
treead3f349f35315951b96d21f568bacd9921b456eb
parent70733d6fd1da1c4ef329a9526cf8686a0729e318
[X86] Fix i386 struct and union parameter alignment

According to i386 System V ABI 2.1: Structures and unions assume the
alignment of their most strictly aligned component. But current
implementation always takes them as 4-byte aligned which will result
in incorrect code, e.g:

 1 #include <immintrin.h>
 2 typedef union {
 3         int d[4];
 4         __m128 m;
 5 } M128;
 6 extern void foo(int, ...);
 7 void test(void)
 8 {
 9   M128 a;
10   foo(1, a);
11   foo(1, a.m);
12 }

The first call (line 10) takes the second arg as 4-byte aligned while
the second call (line 11) takes the second arg as 16-byte aligned.
There is oxymoron for the alignment of the 2 calls because they should
be the same.

This patch fixes the bug by following i386 System V ABI and apply it to
Linux only since other System V OS (e.g Darwin, PS4 and FreeBSD) don't
want to spend any effort dealing with the ramifications of ABI breaks
at present.

Patch by Wei Xiao (wxiao3)

Differential Revision: https://reviews.llvm.org/D60748

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361934 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/TargetInfo.cpp
test/CodeGen/x86_32-align-linux.c [new file with mode: 0644]
test/CodeGen/x86_32-arguments-linux.c