-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rust_for_linux: -Zreg-struct-return commandline flag for X86 (#116973) #130777
Merged
+279
−4
Merged
Changes from all commits
Commits
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
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
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
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
15 changes: 15 additions & 0 deletions
15
src/doc/unstable-book/src/compiler-flags/reg-struct-return.md
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,15 @@ | ||
# `reg-struct-return` | ||
|
||
The tracking issue for this feature is: https://github.com/rust-lang/rust/issues/116973. | ||
|
||
------------------------ | ||
|
||
Option -Zreg-struct-return causes the compiler to return small structs in registers | ||
instead of on the stack for extern "C"-like functions. | ||
It is UNSOUND to link together crates that use different values for this flag. | ||
It is only supported on `x86`. | ||
|
||
It is equivalent to [Clang]'s and [GCC]'s `-freg-struct-return`. | ||
|
||
[Clang]: https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-freg-struct-return | ||
[GCC]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-freg-struct-return |
workingjubilee marked this conversation as resolved.
Show resolved
Hide resolved
|
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,206 @@ | ||
// Checks how `reg-struct-return` flag works with different calling conventions: | ||
// Return struct with 8/16/32/64 bit size will be converted into i8/i16/i32/i64 | ||
// (like abi_return_struct_as_int target spec). | ||
// x86 only. | ||
|
||
//@ revisions: ENABLED DISABLED | ||
//@ add-core-stubs | ||
//@ compile-flags: --target i686-unknown-linux-gnu -O -C no-prepopulate-passes | ||
//@ [ENABLED] compile-flags: -Zreg-struct-return | ||
//@ needs-llvm-components: x86 | ||
|
||
#![crate_type = "lib"] | ||
#![no_std] | ||
#![no_core] | ||
#![feature(no_core, lang_items)] | ||
|
||
extern crate minicore; | ||
use minicore::*; | ||
|
||
#[repr(C)] | ||
pub struct Foo { | ||
x: u32, | ||
y: u32, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Foo1 { | ||
x: u32, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Foo2 { | ||
x: bool, | ||
y: bool, | ||
z: i16, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Foo3 { | ||
x: i16, | ||
y: bool, | ||
z: bool, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Foo4 { | ||
x: char, | ||
y: bool, | ||
z: u8, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Foo5 { | ||
x: u32, | ||
y: u16, | ||
z: u8, | ||
a: bool, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct FooOversize1 { | ||
x: u32, | ||
y: u32, | ||
z: u32, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct FooOversize2 { | ||
f0: u16, | ||
f1: u16, | ||
f2: u16, | ||
f3: u16, | ||
f4: u16, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct FooFloat1 { | ||
x: f32, | ||
y: f32, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct FooFloat2 { | ||
x: f64, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct FooFloat3 { | ||
x: f32, | ||
} | ||
|
||
pub mod tests { | ||
use { | ||
Foo, Foo1, Foo2, Foo3, Foo4, Foo5, FooFloat1, FooFloat2, FooFloat3, FooOversize1, | ||
FooOversize2, | ||
}; | ||
|
||
// ENABLED: i64 @f1() | ||
// DISABLED: void @f1(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "fastcall" fn f1() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
|
||
// CHECK: { i32, i32 } @f2() | ||
#[no_mangle] | ||
pub extern "Rust" fn f2() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
|
||
// ENABLED: i64 @f3() | ||
// DISABLED: void @f3(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f3() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
|
||
// ENABLED: i64 @f4() | ||
// DISABLED: void @f4(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "cdecl" fn f4() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
|
||
// ENABLED: i64 @f5() | ||
// DISABLED: void @f5(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "stdcall" fn f5() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
|
||
// ENABLED: i64 @f6() | ||
// DISABLED: void @f6(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "thiscall" fn f6() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
|
||
// ENABLED: i32 @f7() | ||
// DISABLED: void @f7(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f7() -> Foo1 { | ||
Foo1 { x: 1 } | ||
} | ||
|
||
// ENABLED: i32 @f8() | ||
// DISABLED: void @f8(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f8() -> Foo2 { | ||
Foo2 { x: true, y: false, z: 5 } | ||
} | ||
|
||
// ENABLED: i32 @f9() | ||
// DISABLED: void @f9(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f9() -> Foo3 { | ||
Foo3 { x: 5, y: false, z: true } | ||
} | ||
|
||
// ENABLED: i64 @f10() | ||
// DISABLED: void @f10(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f10() -> Foo4 { | ||
Foo4 { x: 'x', y: true, z: 170 } | ||
} | ||
|
||
// ENABLED: i64 @f11() | ||
// DISABLED: void @f11(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f11() -> Foo5 { | ||
Foo5 { x: 1, y: 2, z: 3, a: true } | ||
} | ||
|
||
// CHECK: void @f12(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f12() -> FooOversize1 { | ||
FooOversize1 { x: 1, y: 2, z: 3 } | ||
} | ||
|
||
// CHECK: void @f13(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f13() -> FooOversize2 { | ||
FooOversize2 { f0: 1, f1: 2, f2: 3, f3: 4, f4: 5 } | ||
} | ||
|
||
// ENABLED: i64 @f14() | ||
// DISABLED: void @f14(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f14() -> FooFloat1 { | ||
FooFloat1 { x: 1.0, y: 1.0 } | ||
} | ||
|
||
// ENABLED: double @f15() | ||
// DISABLED: void @f15(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f15() -> FooFloat2 { | ||
FooFloat2 { x: 1.0 } | ||
} | ||
|
||
// ENABLED: float @f16() | ||
// DISABLED: void @f16(ptr {{.*}}sret | ||
#[no_mangle] | ||
pub extern "C" fn f16() -> FooFloat3 { | ||
FooFloat3 { x: 1.0 } | ||
} | ||
Comment on lines
+193
to
+205
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. Hrm. Tried to disable float features and the LLVMIR we emit for matching the C ABI on such a "soft float" target didn't undergo a substantial change. I should probably take a closer look at that later. |
||
} |
4 changes: 4 additions & 0 deletions
4
tests/ui/invalid-compile-flags/reg-struct-return/requires-x86.aarch64.stderr
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,4 @@ | ||
error: `-Zreg-struct-return` is only supported on x86 | ||
|
||
error: aborting due to 1 previous error | ||
|
21 changes: 21 additions & 0 deletions
21
tests/ui/invalid-compile-flags/reg-struct-return/requires-x86.rs
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,21 @@ | ||
//@ revisions: x86 x86_64 aarch64 | ||
|
||
//@ compile-flags: -Zreg-struct-return | ||
|
||
//@[x86] check-pass | ||
//@[x86] needs-llvm-components: x86 | ||
//@[x86] compile-flags: --target i686-unknown-linux-gnu | ||
|
||
//@[x86_64] check-fail | ||
//@[x86_64] needs-llvm-components: x86 | ||
//@[x86_64] compile-flags: --target x86_64-unknown-linux-gnu | ||
//@[x86_64] error-pattern: `-Zreg-struct-return` is only supported on x86 | ||
|
||
//@[aarch64] check-fail | ||
//@[aarch64] needs-llvm-components: aarch64 | ||
//@[aarch64] compile-flags: --target aarch64-unknown-linux-gnu | ||
//@[aarch64] error-pattern: `-Zreg-struct-return` is only supported on x86 | ||
|
||
#![feature(no_core)] | ||
#![no_core] | ||
#![no_main] |
4 changes: 4 additions & 0 deletions
4
tests/ui/invalid-compile-flags/reg-struct-return/requires-x86.x86_64.stderr
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,4 @@ | ||
error: `-Zreg-struct-return` is only supported on x86 | ||
|
||
error: aborting due to 1 previous error | ||
|
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.
We should test this slightly more exhaustively. I'd like to see
{ bool, bool, i16 }
... I am not aware of a reason it should differ in handling, mind.{ char, bool, u8 }