Registry Mirror
Skip to content

File tree

‎compiler/rustc_codegen_llvm/src/va_arg.rs‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,15 +1061,28 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
10611061
let stability = target.supports_c_variadic_definitions();
10621062

10631063
match target.arch {
1064-
Arch::X86 => emit_ptr_va_arg(
1065-
bx,
1066-
addr,
1067-
layout,
1068-
PassMode::Direct,
1069-
SlotSize::Bytes4,
1070-
if target.is_like_windows { AllowHigherAlign::No } else { AllowHigherAlign::Yes },
1071-
ForceRightAdjust::No,
1072-
),
1064+
Arch::X86 => {
1065+
// A small deviation from clang to get the right behavior for f128.
1066+
//
1067+
// Note that i64 and f64 have an alignment of only 4 on this architecture.
1068+
// We need to be careful when adding future types with an alignment bigger
1069+
// than 4 (e.g. i128), clang has a bunch of custom logic for them.
1070+
let allow_higher_align = if layout.ty == bx.tcx().types.f128 {
1071+
AllowHigherAlign::Yes
1072+
} else {
1073+
AllowHigherAlign::No
1074+
};
1075+
1076+
emit_ptr_va_arg(
1077+
bx,
1078+
addr,
1079+
layout,
1080+
PassMode::Direct,
1081+
SlotSize::Bytes4,
1082+
allow_higher_align,
1083+
ForceRightAdjust::No,
1084+
)
1085+
}
10731086
Arch::Arm64EC => emit_ptr_va_arg(
10741087
bx,
10751088
addr,

‎tests/assembly-llvm/c-variadic/x86-linux.rs‎

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//@ [I686] compile-flags: -Copt-level=3 -Cllvm-args=-x86-asm-syntax=intel
1010
//@ [I686] compile-flags: --target i686-unknown-linux-gnu
1111
//@ needs-llvm-components: x86
12-
#![feature(no_core, lang_items, intrinsics, rustc_attrs)]
12+
#![feature(no_core, lang_items, intrinsics, rustc_attrs, f128)]
1313
#![no_core]
1414
#![crate_type = "lib"]
1515

@@ -64,20 +64,55 @@ unsafe extern "C" fn read_f64(ap: &mut VaList<'_>) -> f64 {
6464
ap.next_arg()
6565
}
6666

67+
#[unsafe(no_mangle)]
68+
unsafe extern "C" fn read_f128(ap: &mut VaList<'_>) -> f128 {
69+
// CHECK-LABEL: read_f128
70+
71+
// X86_64: mov ecx, dword ptr [rdi + 4]
72+
// X86_64-NEXT: cmp rcx, 160
73+
// X86_64-NEXT: ja .LBB1_2
74+
// X86_64-NEXT: mov rax, rcx
75+
// X86_64-NEXT: add rax, qword ptr [rdi + 16]
76+
// X86_64-NEXT: add ecx, 16
77+
// X86_64-NEXT: mov dword ptr [rdi + 4], ecx
78+
// X86_64-NEXT: movaps xmm0, xmmword ptr [rax]
79+
// X86_64-NEXT: ret
80+
// X86_64-NEXT: .LBB1_2:
81+
// X86_64-NEXT: mov rax, qword ptr [rdi + 8]
82+
// X86_64-NEXT: add rax, 15
83+
// X86_64-NEXT: and rax, -16
84+
// X86_64-NEXT: lea rcx, [rax + 16]
85+
// X86_64-NEXT: mov qword ptr [rdi + 8], rcx
86+
// X86_64-NEXT: movaps xmm0, xmmword ptr [rax]
87+
// X86_64-NEXT: ret
88+
89+
// I686: mov ecx, dword ptr [esp + 12]
90+
// I686-NEXT: mov eax, dword ptr [esp + 8]
91+
// I686-NEXT: mov edx, dword ptr [ecx]
92+
// I686-NEXT: add edx, 15
93+
// I686-NEXT: and edx, -16
94+
// I686-NEXT: lea esi, [edx + 16]
95+
// I686-NEXT: mov dword ptr [ecx], esi
96+
// I686-NEXT: movaps xmm0, xmmword ptr [edx]
97+
// I686-NEXT: movaps xmmword ptr [eax], xmm0
98+
// I686-NEXT: pop esi
99+
ap.next_arg()
100+
}
101+
67102
#[unsafe(no_mangle)]
68103
unsafe extern "C" fn read_i32(ap: &mut VaList<'_>) -> i32 {
69104
// CHECK-LABEL: read_i32
70105
//
71106
// X86_64: mov ecx, dword ptr [rdi]
72107
// X86_64-NEXT: cmp rcx, 40
73-
// X86_64-NEXT: ja .LBB1_2
108+
// X86_64-NEXT: ja .LBB2_2
74109
// X86_64-NEXT: mov rax, rcx
75110
// X86_64-NEXT: add rax, qword ptr [rdi + 16]
76111
// X86_64-NEXT: add ecx, 8
77112
// X86_64-NEXT: mov dword ptr [rdi], ecx
78113
// X86_64-NEXT: mov eax, dword ptr [rax]
79114
// X86_64-NEXT: ret
80-
// X86_64-NEXT: .LBB1_2:
115+
// X86_64-NEXT: .LBB2_2:
81116
// X86_64-NEXT: mov rax, qword ptr [rdi + 8]
82117
// X86_64-NEXT: lea rcx, [rax + 8]
83118
// X86_64-NEXT: mov qword ptr [rdi + 8], rcx
@@ -86,14 +121,14 @@ unsafe extern "C" fn read_i32(ap: &mut VaList<'_>) -> i32 {
86121

87122
// X86_64-NEXT_GNUX32: mov ecx, dword ptr [edi]
88123
// X86_64-NEXT_GNUX32-NEXT: cmp ecx, 40
89-
// X86_64-NEXT_GNUX32-NEXT: ja .LBB1_2
124+
// X86_64-NEXT_GNUX32-NEXT: ja .LBB2_2
90125
// X86_64-NEXT_GNUX32-NEXT: mov eax, dword ptr [edi + 12]
91126
// X86_64-NEXT_GNUX32-NEXT: add eax, ecx
92127
// X86_64-NEXT_GNUX32-NEXT: add ecx, 8
93128
// X86_64-NEXT_GNUX32-NEXT: mov dword ptr [edi], ecx
94129
// X86_64-NEXT_GNUX32-NEXT: mov eax, dword ptr [eax]
95130
// X86_64-NEXT_GNUX32-NEXT: ret
96-
// X86_64-NEXT_GNUX32-NEXT: .LBB1_2:
131+
// X86_64-NEXT_GNUX32-NEXT: .LBB2_2:
97132
// X86_64-NEXT_GNUX32-NEXT: mov eax, dword ptr [edi + 8]
98133
// X86_64-NEXT_GNUX32-NEXT: lea ecx, [rax + 8]
99134
// X86_64-NEXT_GNUX32-NEXT: mov dword ptr [edi + 8], ecx
@@ -115,14 +150,14 @@ unsafe extern "C" fn read_i64(ap: &mut VaList<'_>) -> i64 {
115150

116151
// X86_64: mov ecx, dword ptr [rdi]
117152
// X86_64-NEXT: cmp rcx, 40
118-
// X86_64-NEXT: ja .LBB2_2
153+
// X86_64-NEXT: ja .LBB3_2
119154
// X86_64-NEXT: mov rax, rcx
120155
// X86_64-NEXT: add rax, qword ptr [rdi + 16]
121156
// X86_64-NEXT: add ecx, 8
122157
// X86_64-NEXT: mov dword ptr [rdi], ecx
123158
// X86_64-NEXT: mov rax, qword ptr [rax]
124159
// X86_64-NEXT: ret
125-
// X86_64-NEXT: .LBB2_2:
160+
// X86_64-NEXT: .LBB3_2:
126161
// X86_64-NEXT: mov rax, qword ptr [rdi + 8]
127162
// X86_64-NEXT: lea rcx, [rax + 8]
128163
// X86_64-NEXT: mov qword ptr [rdi + 8], rcx
@@ -131,7 +166,7 @@ unsafe extern "C" fn read_i64(ap: &mut VaList<'_>) -> i64 {
131166

132167
// X86_64-NEXT_GNUX32: mov ecx, dword ptr [edi]
133168
// X86_64-NEXT_GNUX32-NEXT: cmp ecx, 40
134-
// X86_64-NEXT_GNUX32-NEXT: ja .LBB2_2
169+
// X86_64-NEXT_GNUX32-NEXT: ja .LBB3_2
135170
// X86_64-NEXT_GNUX32-NEXT: mov eax, dword ptr [edi + 12]
136171
// X86_64-NEXT_GNUX32-NEXT: add eax, ecx
137172
// X86_64-NEXT_GNUX32-NEXT: add ecx, 8
@@ -162,14 +197,14 @@ unsafe extern "C" fn read_i128(ap: &mut VaList<'_>) -> i128 {
162197
//
163198
// X86_64: mov ecx, dword ptr [rdi]
164199
// X86_64-NEXT: cmp rcx, 32
165-
// X86_64-NEXT: ja .LBB3_2
200+
// X86_64-NEXT: ja .LBB4_2
166201
// X86_64-NEXT: mov rdx, qword ptr [rdi + 16]
167202
// X86_64-NEXT: mov rax, qword ptr [rdx + rcx]
168203
// X86_64-NEXT: mov rdx, qword ptr [rdx + rcx + 8]
169204
// X86_64-NEXT: add ecx, 16
170205
// X86_64-NEXT: mov dword ptr [rdi], ecx
171206
// X86_64-NEXT: ret
172-
// X86_64-NEXT: .LBB3_2:
207+
// X86_64-NEXT: .LBB4_2:
173208
// X86_64-NEXT: mov rcx, qword ptr [rdi + 8]
174209
// X86_64-NEXT: add rcx, 15
175210
// X86_64-NEXT: and rcx, -16
@@ -181,7 +216,7 @@ unsafe extern "C" fn read_i128(ap: &mut VaList<'_>) -> i128 {
181216

182217
// X86_64-NEXT_GNUX32: mov ecx, dword ptr [edi]
183218
// X86_64-NEXT_GNUX32-NEXT: cmp ecx, 32
184-
// X86_64-NEXT_GNUX32-NEXT: ja .LBB3_2
219+
// X86_64-NEXT_GNUX32-NEXT: ja .LBB4_2
185220
// X86_64-NEXT_GNUX32-NEXT: mov edx, dword ptr [edi + 12]
186221
// X86_64-NEXT_GNUX32-NEXT: mov rax, qword ptr [edx + ecx]
187222
// X86_64-NEXT_GNUX32-NEXT: mov rdx, qword ptr [edx + ecx + 8]

0 commit comments

Comments
 (0)