Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8433241

Browse files
committed
Auto merge of rust-lang#137365 - workingjubilee:deconditionalize-aarch64-abi-code, r=<try>
compiler: Make extension of `{i,u}{8,16}` unconditional for AAPCS r? `@ghost` Testing a hypothesis... try-job: aarch64-apple try-job: aarch64-gnu try-job: aarch64-gnu-debug try-job: arm-android try-job: dist-aarch64-apple try-job: dist-aarch64-linux try-job: dist-aarch64-msvc try-job: dist-android try-job: test-various
2 parents a18bd8a + 137c1de commit 8433241

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

compiler/rustc_target/src/callconv/aarch64.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn softfloat_float_abi<Ty>(target: &Target, arg: &mut ArgAbi<'_, Ty>) {
7373
}
7474
}
7575

76-
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, kind: AbiKind)
76+
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
7777
where
7878
Ty: TyAbiInterface<'a, C> + Copy,
7979
C: HasDataLayout + HasTargetSpec,
@@ -83,12 +83,10 @@ where
8383
return;
8484
}
8585
if !ret.layout.is_aggregate() {
86-
if kind == AbiKind::DarwinPCS {
87-
// On Darwin, when returning an i8/i16, it must be sign-extended to 32 bits,
88-
// and likewise a u8/u16 must be zero-extended to 32-bits.
89-
// See also: <https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Pass-Arguments-to-Functions-Correctly>
90-
ret.extend_integer_width_to(32)
91-
}
86+
// Even if AAPCS does not demand sign extension of smaller-than-32-bit integer returns,
87+
// Darwin requires it: <https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Pass-Arguments-to-Functions-Correctly>
88+
// It is harmless to do so in every case. If you ask for only 16 bits, don't inspect the other 48!
89+
ret.extend_integer_width_to(32);
9290
softfloat_float_abi(cx.target_spec(), ret);
9391
return;
9492
}
@@ -115,14 +113,11 @@ where
115113
return;
116114
}
117115
if !arg.layout.is_aggregate() {
118-
if kind == AbiKind::DarwinPCS {
119-
// On Darwin, when passing an i8/i16, it must be sign-extended to 32 bits,
120-
// and likewise a u8/u16 must be zero-extended to 32-bits.
121-
// See also: <https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Pass-Arguments-to-Functions-Correctly>
122-
arg.extend_integer_width_to(32);
123-
}
116+
// Even if AAPCS does not demand sign extension of smaller-than-32-bit integer arguments,
117+
// Darwin requires it: <https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Pass-Arguments-to-Functions-Correctly>
118+
// It is harmless to do so in every case. If you ask for only 16 bits, don't inspect the other 48!
119+
arg.extend_integer_width_to(32);
124120
softfloat_float_abi(cx.target_spec(), arg);
125-
126121
return;
127122
}
128123
if let Some(uniform) = is_homogeneous_aggregate(cx, arg) {
@@ -156,7 +151,7 @@ where
156151
C: HasDataLayout + HasTargetSpec,
157152
{
158153
if !fn_abi.ret.is_ignore() {
159-
classify_ret(cx, &mut fn_abi.ret, kind);
154+
classify_ret(cx, &mut fn_abi.ret);
160155
}
161156

162157
for arg in fn_abi.args.iter_mut() {

0 commit comments

Comments
 (0)