-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rust_for_linux: -Zreg-struct-return commandline flag for X86 (#116973)
- Loading branch information
Showing
15 changed files
with
136 additions
and
4 deletions.
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 |
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,63 @@ | ||
// 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. | ||
|
||
//@ compile-flags: --target i686-unknown-linux-gnu -Zreg-struct-return -O -C no-prepopulate-passes | ||
//@ needs-llvm-components: x86 | ||
|
||
#![crate_type = "lib"] | ||
#![no_std] | ||
#![no_core] | ||
#![feature(no_core, lang_items)] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
#[lang = "copy"] | ||
trait Copy {} | ||
|
||
#[repr(C)] | ||
pub struct Foo { | ||
x: u32, | ||
y: u32, | ||
} | ||
|
||
pub mod tests { | ||
use Foo; | ||
|
||
// CHECK: i64 @f1() | ||
#[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 } | ||
} | ||
|
||
// CHECK: i64 @f3() | ||
#[no_mangle] | ||
pub extern "C" fn f3() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
|
||
// CHECK: i64 @f4() | ||
#[no_mangle] | ||
pub extern "cdecl" fn f4() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
|
||
// CHECK: i64 @f5() | ||
#[no_mangle] | ||
pub extern "stdcall" fn f5() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
|
||
// CHECK: i64 @f6() | ||
#[no_mangle] | ||
pub extern "thiscall" fn f6() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
} |
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 | ||
|