-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Aarch64 call abi does not zeroext (and one cannot assume it does so) #97800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 10 commits into
rust-lang:master
from
pnkfelix:issue-97463-fix-aarch64-call-abi-does-not-zeroext
Sep 16, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7913b85
unit tests that inspect LLVM output directly. This relies on a human …
pnkfelix b2777ab
End-to-end regression test for 97463.
pnkfelix 8ae5a55
fix issue 97463 using change suggested by nbdd0121.
pnkfelix dfdb017
experiment: trying to encode the end-to-end test as a ui test via rus…
pnkfelix 99c0f91
fix typo, thanks wesley
pnkfelix 9bf3d5a
Ignore test on wasm
wesleywiser 59cc718
Update codegen tests to accommodate the potential presence/absence of…
pnkfelix ed9b12d
rustdoc doesn't like bare urls
wesleywiser d73614a
Do not run run-make test tied to unix-style `$(CC)` on MSVC host.
pnkfelix a2de75a
fix typo in comment noted by bjorn3.
pnkfelix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; | ||
use crate::abi::{HasDataLayout, TyAbiInterface}; | ||
|
||
/// Given integer-types M and register width N (e.g. M=u16 and N=32 bits), the | ||
/// `ParamExtension` policy specifies how a uM value should be treated when | ||
/// passed via register or stack-slot of width N. See also rust-lang/rust#97463. | ||
#[derive(Copy, Clone, PartialEq)] | ||
pub enum ParamExtension { | ||
/// Indicates that when passing an i8/i16, either as a function argument or | ||
/// as a return value, it must be sign-extended to 32 bits, and likewise a | ||
/// u8/u16 must be zero-extended to 32-bits. (This variant is here to | ||
/// accommodate Apple's deviation from the usual AArch64 ABI as defined by | ||
/// ARM.) | ||
/// | ||
/// See also: <https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Pass-Arguments-to-Functions-Correctly> | ||
ExtendTo32Bits, | ||
|
||
/// Indicates that no sign- nor zero-extension is performed: if a value of | ||
/// type with bitwidth M is passed as function argument or return value, | ||
/// then M bits are copied into the least significant M bits, and the | ||
/// remaining bits of the register (or word of memory) are untouched. | ||
NoExtension, | ||
} | ||
|
||
fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform> | ||
where | ||
Ty: TyAbiInterface<'a, C> + Copy, | ||
|
@@ -24,13 +45,16 @@ where | |
}) | ||
} | ||
|
||
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) | ||
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, param_policy: ParamExtension) | ||
where | ||
Ty: TyAbiInterface<'a, C> + Copy, | ||
C: HasDataLayout, | ||
{ | ||
if !ret.layout.is_aggregate() { | ||
ret.extend_integer_width_to(32); | ||
match param_policy { | ||
ParamExtension::ExtendTo32Bits => ret.extend_integer_width_to(32), | ||
ParamExtension::NoExtension => {} | ||
} | ||
return; | ||
} | ||
if let Some(uniform) = is_homogeneous_aggregate(cx, ret) { | ||
|
@@ -46,13 +70,16 @@ where | |
ret.make_indirect(); | ||
} | ||
|
||
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) | ||
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, param_policy: ParamExtension) | ||
where | ||
Ty: TyAbiInterface<'a, C> + Copy, | ||
C: HasDataLayout, | ||
{ | ||
if !arg.layout.is_aggregate() { | ||
arg.extend_integer_width_to(32); | ||
match param_policy { | ||
ParamExtension::ExtendTo32Bits => arg.extend_integer_width_to(32), | ||
ParamExtension::NoExtension => {} | ||
} | ||
Comment on lines
+79
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I wonder if we should pull this logic into a method on |
||
return; | ||
} | ||
if let Some(uniform) = is_homogeneous_aggregate(cx, arg) { | ||
|
@@ -68,19 +95,19 @@ where | |
arg.make_indirect(); | ||
} | ||
|
||
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) | ||
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, param_policy: ParamExtension) | ||
where | ||
Ty: TyAbiInterface<'a, C> + Copy, | ||
C: HasDataLayout, | ||
{ | ||
if !fn_abi.ret.is_ignore() { | ||
classify_ret(cx, &mut fn_abi.ret); | ||
classify_ret(cx, &mut fn_abi.ret, param_policy); | ||
} | ||
|
||
for arg in &mut fn_abi.args { | ||
if arg.is_ignore() { | ||
continue; | ||
} | ||
classify_arg(cx, arg); | ||
classify_arg(cx, arg, param_policy); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.