diff options
Diffstat (limited to 'tests')
6 files changed, 107 insertions, 0 deletions
diff --git a/tests/assembly/x86_64-function-return.rs b/tests/assembly/x86_64-function-return.rs new file mode 100644 index 00000000000..0fcaca2d491 --- /dev/null +++ b/tests/assembly/x86_64-function-return.rs @@ -0,0 +1,30 @@ +// Test that the function return is (not) converted into a jump to the thunk +// when the `-Zfunction-return={keep,thunk-extern}` flag is (not) set. + +// revisions: unset keep thunk-extern keep-thunk-extern thunk-extern-keep +// assembly-output: emit-asm +// compile-flags: -O +// [keep] compile-flags: -Zfunction-return=keep +// [thunk-extern] compile-flags: -Zfunction-return=thunk-extern +// [keep-thunk-extern] compile-flags: -Zfunction-return=keep -Zfunction-return=thunk-extern +// [thunk-extern-keep] compile-flags: -Zfunction-return=thunk-extern -Zfunction-return=keep +// only-x86_64 +// ignore-x86_64-apple-darwin Symbol is called `___x86_return_thunk` (Darwin's extra underscore) +// ignore-sgx Tests incompatible with LVI mitigations + +#![crate_type = "lib"] + +// CHECK-LABEL: foo: +#[no_mangle] +pub unsafe fn foo() { + // unset: ret + // unset-NOT: jmp __x86_return_thunk + // keep: ret + // keep-NOT: jmp __x86_return_thunk + // thunk-extern: jmp __x86_return_thunk + // thunk-extern-NOT: ret + // keep-thunk-extern: jmp __x86_return_thunk + // keep-thunk-extern-NOT: ret + // thunk-extern-keep: ret + // thunk-extern-keep-NOT: jmp __x86_return_thunk +} diff --git a/tests/codegen/function-return.rs b/tests/codegen/function-return.rs new file mode 100644 index 00000000000..d832d19ac39 --- /dev/null +++ b/tests/codegen/function-return.rs @@ -0,0 +1,28 @@ +// Test that the `fn_ret_thunk_extern` function attribute is (not) emitted when +// the `-Zfunction-return={keep,thunk-extern}` flag is (not) set. + +// revisions: unset keep thunk-extern keep-thunk-extern thunk-extern-keep +// needs-llvm-components: x86 +// compile-flags: --target x86_64-unknown-linux-gnu +// [keep] compile-flags: -Zfunction-return=keep +// [thunk-extern] compile-flags: -Zfunction-return=thunk-extern +// [keep-thunk-extern] compile-flags: -Zfunction-return=keep -Zfunction-return=thunk-extern +// [thunk-extern-keep] compile-flags: -Zfunction-return=thunk-extern -Zfunction-return=keep + +#![crate_type = "lib"] +#![feature(no_core, lang_items)] +#![no_core] + +#[lang = "sized"] +trait Sized {} + +#[no_mangle] +pub fn foo() { + // CHECK: @foo() unnamed_addr #0 + + // unset-NOT: fn_ret_thunk_extern + // keep-NOT: fn_ret_thunk_extern + // thunk-extern: attributes #0 = { {{.*}}fn_ret_thunk_extern{{.*}} } + // keep-thunk-extern: attributes #0 = { {{.*}}fn_ret_thunk_extern{{.*}} } + // thunk-extern-keep-NOT: fn_ret_thunk_extern +} diff --git a/tests/ui/invalid-compile-flags/function-return/requires-x86-or-x86_64.aarch64.stderr b/tests/ui/invalid-compile-flags/function-return/requires-x86-or-x86_64.aarch64.stderr new file mode 100644 index 00000000000..a4fe77f5cbb --- /dev/null +++ b/tests/ui/invalid-compile-flags/function-return/requires-x86-or-x86_64.aarch64.stderr @@ -0,0 +1,4 @@ +error: `-Zfunction-return` (except `keep`) is only supported on x86 and x86_64 + +error: aborting due to 1 previous error + diff --git a/tests/ui/invalid-compile-flags/function-return/requires-x86-or-x86_64.rs b/tests/ui/invalid-compile-flags/function-return/requires-x86-or-x86_64.rs new file mode 100644 index 00000000000..15a88ebdb11 --- /dev/null +++ b/tests/ui/invalid-compile-flags/function-return/requires-x86-or-x86_64.rs @@ -0,0 +1,20 @@ +// revisions: x86 x86_64 aarch64 + +// compile-flags: -Zfunction-return=thunk-extern + +//[x86] check-pass +//[x86] needs-llvm-components: x86 +//[x86] compile-flags: --target i686-unknown-linux-gnu + +//[x86_64] check-pass +//[x86_64] needs-llvm-components: x86 +//[x86_64] compile-flags: --target x86_64-unknown-linux-gnu + +//[aarch64] check-fail +//[aarch64] needs-llvm-components: aarch64 +//[aarch64] compile-flags: --target aarch64-unknown-linux-gnu +//[aarch64] error-pattern: `-Zfunction-return` (except `keep`) is only supported on x86 and x86_64 + +#![feature(no_core)] +#![no_core] +#![no_main] diff --git a/tests/ui/invalid-compile-flags/function-return/thunk-extern-requires-non-large-code-model.large.stderr b/tests/ui/invalid-compile-flags/function-return/thunk-extern-requires-non-large-code-model.large.stderr new file mode 100644 index 00000000000..683b3213d07 --- /dev/null +++ b/tests/ui/invalid-compile-flags/function-return/thunk-extern-requires-non-large-code-model.large.stderr @@ -0,0 +1,4 @@ +error: `-Zfunction-return=thunk-extern` is only supported on non-large code models + +error: aborting due to 1 previous error + diff --git a/tests/ui/invalid-compile-flags/function-return/thunk-extern-requires-non-large-code-model.rs b/tests/ui/invalid-compile-flags/function-return/thunk-extern-requires-non-large-code-model.rs new file mode 100644 index 00000000000..f925905de36 --- /dev/null +++ b/tests/ui/invalid-compile-flags/function-return/thunk-extern-requires-non-large-code-model.rs @@ -0,0 +1,21 @@ +// revisions: small kernel medium large + +// needs-llvm-components: x86 +// compile-flags: --target x86_64-unknown-linux-gnu -Zfunction-return=thunk-extern + +//[small] check-pass +//[small] compile-flags: -Ccode-model=small + +//[kernel] check-pass +//[kernel] compile-flags: -Ccode-model=kernel + +//[medium] check-pass +//[medium] compile-flags: -Ccode-model=medium + +//[large] check-fail +//[large] compile-flags: -Ccode-model=large +//[large] error-pattern: `-Zfunction-return=thunk-extern` is only supported on non-large code models + +#![feature(no_core)] +#![no_core] +#![no_main] |
