-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Windows x86: Change i128 to return via the vector ABI #134290
Open
tgross35
wants to merge
3
commits into
rust-lang:master
Choose a base branch
from
tgross35:windows-i128-callconv
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−8
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//! Verify that Rust implements the expected calling convention for `i128`/`u128`. | ||
|
||
//@ revisions: MSVC MINGW | ||
//@ add-core-stubs | ||
//@ [MSVC] needs-llvm-components: x86 | ||
//@ [MINGW] needs-llvm-components: x86 | ||
//@ [MSVC] compile-flags: --target x86_64-pc-windows-msvc | ||
//@ [MINGW] compile-flags: --target x86_64-pc-windows-gnu | ||
//@ [MSVC] filecheck-flags: --check-prefix=WIN | ||
//@ [MINGW] filecheck-flags: --check-prefix=WIN | ||
|
||
#![crate_type = "lib"] | ||
#![no_std] | ||
#![no_core] | ||
#![feature(no_core, lang_items)] | ||
|
||
extern crate minicore; | ||
|
||
extern "C" { | ||
fn extern_call(arg0: i128); | ||
fn extern_ret() -> i128; | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn pass(_arg0: u32, arg1: i128) { | ||
// CHECK-LABEL: @pass( | ||
// i128 is passed indirectly on Windows. It should load the pointer to the stack and pass | ||
// a pointer to that allocation. | ||
// WIN-SAME: %_arg0, ptr{{.*}} %arg1) | ||
// WIN: [[PASS:%[_0-9]+]] = alloca [16 x i8], align 16 | ||
// WIN: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1 | ||
// WIN: store i128 [[LOADED]], ptr [[PASS]] | ||
// WIN: call void @extern_call | ||
unsafe { extern_call(arg1) }; | ||
} | ||
|
||
// Check that we produce the correct return ABI | ||
#[no_mangle] | ||
pub extern "C" fn ret(_arg0: u32, arg1: i128) -> i128 { | ||
// CHECK-LABEL: @ret( | ||
// i128 is returned in xmm0 on Windows | ||
// FIXME(#134288): This may change for the `-msvc` targets in the future. | ||
// WIN-SAME: i32{{.*}} %_arg0, ptr{{.*}} %arg1) | ||
// WIN: [[LOADED:%[_0-9]+]] = load <16 x i8>, ptr %arg1 | ||
// WIN-NEXT: ret <16 x i8> [[LOADED]] | ||
arg1 | ||
} | ||
|
||
// Check that we consume the correct return ABI | ||
#[no_mangle] | ||
pub extern "C" fn forward(dst: *mut i128) { | ||
// CHECK-LABEL: @forward | ||
// WIN-SAME: ptr{{.*}} %dst) | ||
// WIN: [[RETURNED:%[_0-9]+]] = tail call <16 x i8> @extern_ret() | ||
// WIN: store <16 x i8> [[RETURNED]], ptr %dst | ||
// WIN: ret void | ||
unsafe { *dst = extern_ret() }; | ||
} | ||
|
||
#[repr(C)] | ||
struct RetAggregate { | ||
a: i32, | ||
b: i128, | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn ret_aggregate(_arg0: u32, arg1: i128) -> RetAggregate { | ||
// CHECK-LABEL: @ret_aggregate( | ||
// Aggregates should also be returned indirectly | ||
// WIN-SAME: ptr{{.*}}sret([32 x i8]){{.*}}[[RET:%[_0-9]+]], i32{{.*}}%_arg0, ptr{{.*}}%arg1) | ||
// WIN: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1 | ||
// WIN: [[GEP:%[_0-9]+]] = getelementptr{{.*}}, ptr [[RET]] | ||
// WIN: store i128 [[LOADED]], ptr [[GEP]] | ||
// WIN: ret void | ||
RetAggregate { a: 1, b: arg1 } | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, no clue where I was going with that. Will fix.