From f036faeb3581c1079516667d43a77e2d23963c0a Mon Sep 17 00:00:00 2001 From: Kevin Per Date: Thu, 15 Aug 2019 11:37:19 +0200 Subject: [PATCH 1/7] Grouping ABI test #62401 --- .../run-pass/abi/abi-sysv64-arg-passing.rs | 366 ++++++++++++++++++ .../run-pass/abi/abi-sysv64-register-usage.rs | 95 +++++ src/test/run-pass/abi/abort-on-c-abi.rs | 36 ++ src/test/run-pass/abi/anon-extern-mod.rs | 17 + .../anon-extern-mod-cross-crate-1.rs | 9 + .../run-pass/abi/auxiliary/foreign_lib.rs | 38 ++ src/test/run-pass/abi/c-stack-as-value.rs | 17 + src/test/run-pass/abi/cabi-int-widening.rs | 14 + .../anon-extern-mod-cross-crate-1.rs | 9 + .../anon-extern-mod-cross-crate-1.rs | 9 + .../auxiliary/extern-crosscrate-source.rs | 31 ++ .../run-pass/abi/extern/extern-call-deep.rs | 39 ++ .../run-pass/abi/extern/extern-call-deep2.rs | 44 +++ .../abi/extern/extern-call-indirect.rs | 38 ++ .../run-pass/abi/extern/extern-call-scrub.rs | 48 +++ .../abi/extern/extern-pass-TwoU16s.rs | 25 ++ .../run-pass/abi/extern/extern-pass-TwoU8s.rs | 25 ++ .../run-pass/abi/extern/extern-pass-char.rs | 16 + .../run-pass/abi/extern/extern-pass-double.rs | 13 + .../run-pass/abi/extern/extern-pass-empty.rs | 55 +++ .../abi/extern/extern-return-TwoU16s.rs | 21 + .../abi/extern/extern-return-TwoU32s.rs | 21 + .../abi/extern/extern-return-TwoU64s.rs | 21 + .../abi/extern/extern-return-TwoU8s.rs | 21 + .../abi/foreign/auxiliary/foreign_lib.rs | 38 ++ .../abi/foreign/foreign-call-no-runtime.rs | 55 +++ .../abi/foreign/foreign-fn-with-byval.rs | 32 ++ .../run-pass/abi/foreign/foreign-no-abi.rs | 22 ++ .../abi/issues/auxiliary/issue-25185-1.rs | 8 + src/test/run-pass/abi/issues/issue-28676.rs | 35 ++ src/test/run-pass/abi/lib-defaults.rs | 16 + .../run-pass/abi/macros/macros-in-extern.rs | 30 ++ .../abi/mir/mir_codegen_calls_variadic.rs | 22 ++ .../abi/numbers-arithmetic/i128-ffi.rs | 31 ++ .../abi/proc_macro/macros-in-extern.rs | 24 ++ .../abi/rfcs/rfc1717/library-override.rs | 14 + .../run-pass/abi/segfault-no-out-of-stack.rs | 48 +++ src/test/run-pass/abi/stack-probes.rs | 67 ++++ .../abi/statics/static-mut-foreign.rs | 41 ++ .../abi/structs-enums/struct-return.rs | 64 +++ .../run-pass/abi/union/union-c-interop.rs | 37 ++ src/test/run-pass/abi/variadic-ffi.rs | 83 ++++ 42 files changed, 1695 insertions(+) create mode 100644 src/test/run-pass/abi/abi-sysv64-arg-passing.rs create mode 100644 src/test/run-pass/abi/abi-sysv64-register-usage.rs create mode 100644 src/test/run-pass/abi/abort-on-c-abi.rs create mode 100644 src/test/run-pass/abi/anon-extern-mod.rs create mode 100644 src/test/run-pass/abi/auxiliary/anon-extern-mod-cross-crate-1.rs create mode 100644 src/test/run-pass/abi/auxiliary/foreign_lib.rs create mode 100644 src/test/run-pass/abi/c-stack-as-value.rs create mode 100644 src/test/run-pass/abi/cabi-int-widening.rs create mode 100644 src/test/run-pass/abi/consts/auxiliary/anon-extern-mod-cross-crate-1.rs create mode 100644 src/test/run-pass/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs create mode 100644 src/test/run-pass/abi/extern/auxiliary/extern-crosscrate-source.rs create mode 100644 src/test/run-pass/abi/extern/extern-call-deep.rs create mode 100644 src/test/run-pass/abi/extern/extern-call-deep2.rs create mode 100644 src/test/run-pass/abi/extern/extern-call-indirect.rs create mode 100644 src/test/run-pass/abi/extern/extern-call-scrub.rs create mode 100644 src/test/run-pass/abi/extern/extern-pass-TwoU16s.rs create mode 100644 src/test/run-pass/abi/extern/extern-pass-TwoU8s.rs create mode 100644 src/test/run-pass/abi/extern/extern-pass-char.rs create mode 100644 src/test/run-pass/abi/extern/extern-pass-double.rs create mode 100644 src/test/run-pass/abi/extern/extern-pass-empty.rs create mode 100644 src/test/run-pass/abi/extern/extern-return-TwoU16s.rs create mode 100644 src/test/run-pass/abi/extern/extern-return-TwoU32s.rs create mode 100644 src/test/run-pass/abi/extern/extern-return-TwoU64s.rs create mode 100644 src/test/run-pass/abi/extern/extern-return-TwoU8s.rs create mode 100644 src/test/run-pass/abi/foreign/auxiliary/foreign_lib.rs create mode 100644 src/test/run-pass/abi/foreign/foreign-call-no-runtime.rs create mode 100644 src/test/run-pass/abi/foreign/foreign-fn-with-byval.rs create mode 100644 src/test/run-pass/abi/foreign/foreign-no-abi.rs create mode 100644 src/test/run-pass/abi/issues/auxiliary/issue-25185-1.rs create mode 100644 src/test/run-pass/abi/issues/issue-28676.rs create mode 100644 src/test/run-pass/abi/lib-defaults.rs create mode 100644 src/test/run-pass/abi/macros/macros-in-extern.rs create mode 100644 src/test/run-pass/abi/mir/mir_codegen_calls_variadic.rs create mode 100644 src/test/run-pass/abi/numbers-arithmetic/i128-ffi.rs create mode 100644 src/test/run-pass/abi/proc_macro/macros-in-extern.rs create mode 100644 src/test/run-pass/abi/rfcs/rfc1717/library-override.rs create mode 100644 src/test/run-pass/abi/segfault-no-out-of-stack.rs create mode 100644 src/test/run-pass/abi/stack-probes.rs create mode 100644 src/test/run-pass/abi/statics/static-mut-foreign.rs create mode 100644 src/test/run-pass/abi/structs-enums/struct-return.rs create mode 100644 src/test/run-pass/abi/union/union-c-interop.rs create mode 100644 src/test/run-pass/abi/variadic-ffi.rs diff --git a/src/test/run-pass/abi/abi-sysv64-arg-passing.rs b/src/test/run-pass/abi/abi-sysv64-arg-passing.rs new file mode 100644 index 00000000000..fdf0573b5e3 --- /dev/null +++ b/src/test/run-pass/abi/abi-sysv64-arg-passing.rs @@ -0,0 +1,366 @@ +// Checks if the "sysv64" calling convention behaves the same as the +// "C" calling convention on platforms where both should be the same + +// This file contains versions of the following run-pass tests with +// the calling convention changed to "sysv64" + +// cabi-int-widening +// extern-pass-char +// extern-pass-u32 +// extern-pass-u64 +// extern-pass-double +// extern-pass-empty +// extern-pass-TwoU8s +// extern-pass-TwoU16s +// extern-pass-TwoU32s +// extern-pass-TwoU64s +// extern-return-TwoU8s +// extern-return-TwoU16s +// extern-return-TwoU32s +// extern-return-TwoU64s +// foreign-fn-with-byval +// issue-28676 +// issue-62350-sysv-neg-reg-counts +// struct-return + +// ignore-android +// ignore-arm +// ignore-aarch64 +// ignore-windows + +// note: windows is ignored as rust_test_helpers does not have the sysv64 abi on windows + +#[allow(dead_code)] +#[allow(improper_ctypes)] + +#[cfg(target_arch = "x86_64")] +mod tests { + #[repr(C)] + #[derive(Copy, Clone, PartialEq, Debug)] + pub struct TwoU8s { + one: u8, two: u8 + } + + #[repr(C)] + #[derive(Copy, Clone, PartialEq, Debug)] + pub struct TwoU16s { + one: u16, two: u16 + } + + #[repr(C)] + #[derive(Copy, Clone, PartialEq, Debug)] + pub struct TwoU32s { + one: u32, two: u32 + } + + #[repr(C)] + #[derive(Copy, Clone, PartialEq, Debug)] + pub struct TwoU64s { + one: u64, two: u64 + } + + #[repr(C)] + pub struct ManyInts { + arg1: i8, + arg2: i16, + arg3: i32, + arg4: i16, + arg5: i8, + arg6: TwoU8s, + } + + #[repr(C)] + pub struct Empty; + + #[repr(C)] + #[derive(Copy, Clone)] + pub struct S { + x: u64, + y: u64, + z: u64, + } + + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Quad { a: u64, b: u64, c: u64, d: u64 } + + #[derive(Copy, Clone)] + pub struct QuadFloats { a: f32, b: f32, c: f32, d: f32 } + + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Floats { a: f64, b: u8, c: f64 } + + #[link(name = "rust_test_helpers", kind = "static")] + extern "sysv64" { + pub fn rust_int8_to_int32(_: i8) -> i32; + pub fn rust_dbg_extern_identity_u8(v: u8) -> u8; + pub fn rust_dbg_extern_identity_u32(v: u32) -> u32; + pub fn rust_dbg_extern_identity_u64(v: u64) -> u64; + pub fn rust_dbg_extern_identity_double(v: f64) -> f64; + pub fn rust_dbg_extern_empty_struct(v1: ManyInts, e: Empty, v2: ManyInts); + pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s; + pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s; + pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s; + pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s; + pub fn rust_dbg_extern_return_TwoU8s() -> TwoU8s; + pub fn rust_dbg_extern_return_TwoU16s() -> TwoU16s; + pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s; + pub fn rust_dbg_extern_return_TwoU64s() -> TwoU64s; + pub fn get_x(x: S) -> u64; + pub fn get_y(x: S) -> u64; + pub fn get_z(x: S) -> u64; + pub fn get_c_many_params(_: *const (), _: *const (), + _: *const (), _: *const (), f: Quad) -> u64; + pub fn get_c_exhaust_sysv64_ints( + _: *const (), + _: *const (), + _: *const (), + _: *const (), + _: *const (), + _: *const (), + _: *const (), + h: QuadFloats, + ) -> f32; + pub fn rust_dbg_abi_1(q: Quad) -> Quad; + pub fn rust_dbg_abi_2(f: Floats) -> Floats; + } + + pub fn cabi_int_widening() { + let x = unsafe { + rust_int8_to_int32(-1) + }; + + assert!(x == -1); + } + + pub fn extern_pass_char() { + unsafe { + assert_eq!(22, rust_dbg_extern_identity_u8(22)); + } + } + + pub fn extern_pass_u32() { + unsafe { + assert_eq!(22, rust_dbg_extern_identity_u32(22)); + } + } + + pub fn extern_pass_u64() { + unsafe { + assert_eq!(22, rust_dbg_extern_identity_u64(22)); + } + } + + pub fn extern_pass_double() { + unsafe { + assert_eq!(22.0_f64, rust_dbg_extern_identity_double(22.0_f64)); + } + } + + pub fn extern_pass_empty() { + unsafe { + let x = ManyInts { + arg1: 2, + arg2: 3, + arg3: 4, + arg4: 5, + arg5: 6, + arg6: TwoU8s { one: 7, two: 8, } + }; + let y = ManyInts { + arg1: 1, + arg2: 2, + arg3: 3, + arg4: 4, + arg5: 5, + arg6: TwoU8s { one: 6, two: 7, } + }; + let empty = Empty; + rust_dbg_extern_empty_struct(x, empty, y); + } + } + + pub fn extern_pass_twou8s() { + unsafe { + let x = TwoU8s {one: 22, two: 23}; + let y = rust_dbg_extern_identity_TwoU8s(x); + assert_eq!(x, y); + } + } + + pub fn extern_pass_twou16s() { + unsafe { + let x = TwoU16s {one: 22, two: 23}; + let y = rust_dbg_extern_identity_TwoU16s(x); + assert_eq!(x, y); + } + } + + pub fn extern_pass_twou32s() { + unsafe { + let x = TwoU32s {one: 22, two: 23}; + let y = rust_dbg_extern_identity_TwoU32s(x); + assert_eq!(x, y); + } + } + + pub fn extern_pass_twou64s() { + unsafe { + let x = TwoU64s {one: 22, two: 23}; + let y = rust_dbg_extern_identity_TwoU64s(x); + assert_eq!(x, y); + } + } + + pub fn extern_return_twou8s() { + unsafe { + let y = rust_dbg_extern_return_TwoU8s(); + assert_eq!(y.one, 10); + assert_eq!(y.two, 20); + } + } + + pub fn extern_return_twou16s() { + unsafe { + let y = rust_dbg_extern_return_TwoU16s(); + assert_eq!(y.one, 10); + assert_eq!(y.two, 20); + } + } + + pub fn extern_return_twou32s() { + unsafe { + let y = rust_dbg_extern_return_TwoU32s(); + assert_eq!(y.one, 10); + assert_eq!(y.two, 20); + } + } + + pub fn extern_return_twou64s() { + unsafe { + let y = rust_dbg_extern_return_TwoU64s(); + assert_eq!(y.one, 10); + assert_eq!(y.two, 20); + } + } + + #[inline(never)] + fn indirect_call(func: unsafe extern "sysv64" fn(s: S) -> u64, s: S) -> u64 { + unsafe { + func(s) + } + } + + pub fn foreign_fn_with_byval() { + let s = S { x: 1, y: 2, z: 3 }; + assert_eq!(s.x, indirect_call(get_x, s)); + assert_eq!(s.y, indirect_call(get_y, s)); + assert_eq!(s.z, indirect_call(get_z, s)); + } + + fn test() { + use std::ptr; + unsafe { + let null = ptr::null(); + let q = Quad { + a: 1, + b: 2, + c: 3, + d: 4 + }; + assert_eq!(get_c_many_params(null, null, null, null, q), q.c); + } + } + + pub fn issue_28676() { + test(); + } + + fn test_62350() { + use std::ptr; + unsafe { + let null = ptr::null(); + let q = QuadFloats { + a: 10.2, + b: 20.3, + c: 30.4, + d: 40.5 + }; + assert_eq!( + get_c_exhaust_sysv64_ints(null, null, null, null, null, null, null, q), + q.c, + ); + } + } + + pub fn issue_62350() { + test_62350(); + } + + fn test1() { + unsafe { + let q = Quad { a: 0xaaaa_aaaa_aaaa_aaaa, + b: 0xbbbb_bbbb_bbbb_bbbb, + c: 0xcccc_cccc_cccc_cccc, + d: 0xdddd_dddd_dddd_dddd }; + let qq = rust_dbg_abi_1(q); + println!("a: {:x}", qq.a as usize); + println!("b: {:x}", qq.b as usize); + println!("c: {:x}", qq.c as usize); + println!("d: {:x}", qq.d as usize); + assert_eq!(qq.a, q.c + 1); + assert_eq!(qq.b, q.d - 1); + assert_eq!(qq.c, q.a + 1); + assert_eq!(qq.d, q.b - 1); + } + } + + fn test2() { + unsafe { + let f = Floats { a: 1.234567890e-15_f64, + b: 0b_1010_1010, + c: 1.0987654321e-15_f64 }; + let ff = rust_dbg_abi_2(f); + println!("a: {}", ff.a as f64); + println!("b: {}", ff.b as usize); + println!("c: {}", ff.c as f64); + assert_eq!(ff.a, f.c + 1.0f64); + assert_eq!(ff.b, 0xff); + assert_eq!(ff.c, f.a - 1.0f64); + } + } + + pub fn struct_return() { + test1(); + test2(); + } +} + +#[cfg(target_arch = "x86_64")] +fn main() { + use tests::*; + cabi_int_widening(); + extern_pass_char(); + extern_pass_u32(); + extern_pass_u64(); + extern_pass_double(); + extern_pass_empty(); + extern_pass_twou8s(); + extern_pass_twou16s(); + extern_pass_twou32s(); + extern_pass_twou64s(); + extern_return_twou8s(); + extern_return_twou16s(); + extern_return_twou32s(); + extern_return_twou64s(); + foreign_fn_with_byval(); + issue_28676(); + issue_62350(); + struct_return(); +} + +#[cfg(not(target_arch = "x86_64"))] +fn main() { + +} diff --git a/src/test/run-pass/abi/abi-sysv64-register-usage.rs b/src/test/run-pass/abi/abi-sysv64-register-usage.rs new file mode 100644 index 00000000000..a0d6e968252 --- /dev/null +++ b/src/test/run-pass/abi/abi-sysv64-register-usage.rs @@ -0,0 +1,95 @@ +// Checks if the correct registers are being used to pass arguments +// when the sysv64 ABI is specified. + +// ignore-android +// ignore-arm +// ignore-aarch64 + +#![feature(asm)] + +#[cfg(target_arch = "x86_64")] +pub extern "sysv64" fn all_the_registers(rdi: i64, rsi: i64, rdx: i64, + rcx: i64, r8 : i64, r9 : i64, + xmm0: f32, xmm1: f32, xmm2: f32, + xmm3: f32, xmm4: f32, xmm5: f32, + xmm6: f32, xmm7: f32) -> i64 { + assert_eq!(rdi, 1); + assert_eq!(rsi, 2); + assert_eq!(rdx, 3); + assert_eq!(rcx, 4); + assert_eq!(r8, 5); + assert_eq!(r9, 6); + assert_eq!(xmm0, 1.0f32); + assert_eq!(xmm1, 2.0f32); + assert_eq!(xmm2, 4.0f32); + assert_eq!(xmm3, 8.0f32); + assert_eq!(xmm4, 16.0f32); + assert_eq!(xmm5, 32.0f32); + assert_eq!(xmm6, 64.0f32); + assert_eq!(xmm7, 128.0f32); + 42 +} + +// this struct contains 8 i64's, while only 6 can be passed in registers. +#[cfg(target_arch = "x86_64")] +#[derive(PartialEq, Eq, Debug)] +pub struct LargeStruct(i64, i64, i64, i64, i64, i64, i64, i64); + +#[cfg(target_arch = "x86_64")] +#[inline(never)] +pub extern "sysv64" fn large_struct_by_val(mut foo: LargeStruct) -> LargeStruct { + foo.0 *= 1; + foo.1 *= 2; + foo.2 *= 3; + foo.3 *= 4; + foo.4 *= 5; + foo.5 *= 6; + foo.6 *= 7; + foo.7 *= 8; + foo +} + +#[cfg(target_arch = "x86_64")] +pub fn main() { + let result: i64; + unsafe { + asm!("mov rdi, 1; + mov rsi, 2; + mov rdx, 3; + mov rcx, 4; + mov r8, 5; + mov r9, 6; + mov eax, 0x3F800000; + movd xmm0, eax; + mov eax, 0x40000000; + movd xmm1, eax; + mov eax, 0x40800000; + movd xmm2, eax; + mov eax, 0x41000000; + movd xmm3, eax; + mov eax, 0x41800000; + movd xmm4, eax; + mov eax, 0x42000000; + movd xmm5, eax; + mov eax, 0x42800000; + movd xmm6, eax; + mov eax, 0x43000000; + movd xmm7, eax; + call r10 + " + : "={rax}"(result) + : "{r10}"(all_the_registers as usize) + : "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r11", "cc", "memory" + : "intel", "alignstack" + ) + } + assert_eq!(result, 42); + + assert_eq!( + large_struct_by_val(LargeStruct(1, 2, 3, 4, 5, 6, 7, 8)), + LargeStruct(1, 4, 9, 16, 25, 36, 49, 64) + ); +} + +#[cfg(not(target_arch = "x86_64"))] +pub fn main() {} diff --git a/src/test/run-pass/abi/abort-on-c-abi.rs b/src/test/run-pass/abi/abort-on-c-abi.rs new file mode 100644 index 00000000000..110f3eee1ef --- /dev/null +++ b/src/test/run-pass/abi/abort-on-c-abi.rs @@ -0,0 +1,36 @@ +#![allow(unused_must_use)] +// Since we mark some ABIs as "nounwind" to LLVM, we must make sure that +// we never unwind through them. + +// ignore-cloudabi no env and process +// ignore-emscripten no processes +// ignore-sgx no processes + +use std::{env, panic}; +use std::io::prelude::*; +use std::io; +use std::process::{Command, Stdio}; + +extern "C" fn panic_in_ffi() { + panic!("Test"); +} + +fn test() { + let _ = panic::catch_unwind(|| { panic_in_ffi(); }); + // The process should have aborted by now. + io::stdout().write(b"This should never be printed.\n"); + let _ = io::stdout().flush(); +} + +fn main() { + let args: Vec = env::args().collect(); + if args.len() > 1 && args[1] == "test" { + return test(); + } + + let mut p = Command::new(&args[0]) + .stdout(Stdio::piped()) + .stdin(Stdio::piped()) + .arg("test").spawn().unwrap(); + assert!(!p.wait().unwrap().success()); +} diff --git a/src/test/run-pass/abi/anon-extern-mod.rs b/src/test/run-pass/abi/anon-extern-mod.rs new file mode 100644 index 00000000000..6d7e3f3cd5c --- /dev/null +++ b/src/test/run-pass/abi/anon-extern-mod.rs @@ -0,0 +1,17 @@ +// pretty-expanded FIXME #23616 +// ignore-wasm32-bare no libc to test ffi with + +#![feature(rustc_private)] + +extern crate libc; + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + fn rust_get_test_int() -> libc::intptr_t; +} + +pub fn main() { + unsafe { + let _ = rust_get_test_int(); + } +} diff --git a/src/test/run-pass/abi/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/run-pass/abi/auxiliary/anon-extern-mod-cross-crate-1.rs new file mode 100644 index 00000000000..948b5e688eb --- /dev/null +++ b/src/test/run-pass/abi/auxiliary/anon-extern-mod-cross-crate-1.rs @@ -0,0 +1,9 @@ +#![crate_name="anonexternmod"] +#![feature(rustc_private)] + +extern crate libc; + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_get_test_int() -> libc::intptr_t; +} diff --git a/src/test/run-pass/abi/auxiliary/foreign_lib.rs b/src/test/run-pass/abi/auxiliary/foreign_lib.rs new file mode 100644 index 00000000000..de6b0e2118a --- /dev/null +++ b/src/test/run-pass/abi/auxiliary/foreign_lib.rs @@ -0,0 +1,38 @@ +#![crate_name="foreign_lib"] + +#![feature(rustc_private)] + +pub mod rustrt { + extern crate libc; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn rust_get_test_int() -> libc::intptr_t; + } +} + +pub mod rustrt2 { + extern crate libc; + + extern { + pub fn rust_get_test_int() -> libc::intptr_t; + } +} + +pub mod rustrt3 { + // Different type, but same ABI (on all supported platforms). + // Ensures that we don't ICE or trigger LLVM asserts when + // importing the same symbol under different types. + // See https://github.com/rust-lang/rust/issues/32740. + extern { + pub fn rust_get_test_int() -> *const u8; + } +} + +pub fn local_uses() { + unsafe { + let x = rustrt::rust_get_test_int(); + assert_eq!(x, rustrt2::rust_get_test_int()); + assert_eq!(x as *const _, rustrt3::rust_get_test_int()); + } +} diff --git a/src/test/run-pass/abi/c-stack-as-value.rs b/src/test/run-pass/abi/c-stack-as-value.rs new file mode 100644 index 00000000000..3b997295c12 --- /dev/null +++ b/src/test/run-pass/abi/c-stack-as-value.rs @@ -0,0 +1,17 @@ +// pretty-expanded FIXME #23616 +// ignore-wasm32-bare no libc to test ffi with + +#![feature(rustc_private)] + +mod rustrt { + extern crate libc; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn rust_get_test_int() -> libc::intptr_t; + } +} + +pub fn main() { + let _foo = rustrt::rust_get_test_int; +} diff --git a/src/test/run-pass/abi/cabi-int-widening.rs b/src/test/run-pass/abi/cabi-int-widening.rs new file mode 100644 index 00000000000..f6524c6a3d9 --- /dev/null +++ b/src/test/run-pass/abi/cabi-int-widening.rs @@ -0,0 +1,14 @@ +// ignore-wasm32-bare no libc to test ffi with + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + fn rust_int8_to_int32(_: i8) -> i32; +} + +fn main() { + let x = unsafe { + rust_int8_to_int32(-1) + }; + + assert!(x == -1); +} diff --git a/src/test/run-pass/abi/consts/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/run-pass/abi/consts/auxiliary/anon-extern-mod-cross-crate-1.rs new file mode 100644 index 00000000000..948b5e688eb --- /dev/null +++ b/src/test/run-pass/abi/consts/auxiliary/anon-extern-mod-cross-crate-1.rs @@ -0,0 +1,9 @@ +#![crate_name="anonexternmod"] +#![feature(rustc_private)] + +extern crate libc; + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_get_test_int() -> libc::intptr_t; +} diff --git a/src/test/run-pass/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/run-pass/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs new file mode 100644 index 00000000000..948b5e688eb --- /dev/null +++ b/src/test/run-pass/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs @@ -0,0 +1,9 @@ +#![crate_name="anonexternmod"] +#![feature(rustc_private)] + +extern crate libc; + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_get_test_int() -> libc::intptr_t; +} diff --git a/src/test/run-pass/abi/extern/auxiliary/extern-crosscrate-source.rs b/src/test/run-pass/abi/extern/auxiliary/extern-crosscrate-source.rs new file mode 100644 index 00000000000..d4568d38e25 --- /dev/null +++ b/src/test/run-pass/abi/extern/auxiliary/extern-crosscrate-source.rs @@ -0,0 +1,31 @@ +#![crate_name="externcallback"] +#![crate_type = "lib"] +#![feature(rustc_private)] + +extern crate libc; + +pub mod rustrt { + extern crate libc; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, + data: libc::uintptr_t) + -> libc::uintptr_t; + } +} + +pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t { + unsafe { + println!("n = {}", n); + rustrt::rust_dbg_call(cb, n) + } +} + +pub extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { + if data == 1 { + data + } else { + fact(data - 1) * data + } +} diff --git a/src/test/run-pass/abi/extern/extern-call-deep.rs b/src/test/run-pass/abi/extern/extern-call-deep.rs new file mode 100644 index 00000000000..81f884dada9 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-call-deep.rs @@ -0,0 +1,39 @@ +// run-pass +// ignore-wasm32-bare no libc to test ffi with +// ignore-emscripten blows the JS stack + +#![feature(rustc_private)] + +extern crate libc; + +mod rustrt { + extern crate libc; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, + data: libc::uintptr_t) + -> libc::uintptr_t; + } +} + +extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { + if data == 1 { + data + } else { + count(data - 1) + 1 + } +} + +fn count(n: libc::uintptr_t) -> libc::uintptr_t { + unsafe { + println!("n = {}", n); + rustrt::rust_dbg_call(cb, n) + } +} + +pub fn main() { + let result = count(1000); + println!("result = {}", result); + assert_eq!(result, 1000); +} diff --git a/src/test/run-pass/abi/extern/extern-call-deep2.rs b/src/test/run-pass/abi/extern/extern-call-deep2.rs new file mode 100644 index 00000000000..b31489b1e10 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-call-deep2.rs @@ -0,0 +1,44 @@ +// run-pass +#![allow(unused_must_use)] +// ignore-emscripten no threads support + +#![feature(rustc_private)] + +extern crate libc; +use std::thread; + +mod rustrt { + extern crate libc; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, + data: libc::uintptr_t) + -> libc::uintptr_t; + } +} + +extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { + if data == 1 { + data + } else { + count(data - 1) + 1 + } +} + +fn count(n: libc::uintptr_t) -> libc::uintptr_t { + unsafe { + println!("n = {}", n); + rustrt::rust_dbg_call(cb, n) + } +} + +pub fn main() { + // Make sure we're on a thread with small Rust stacks (main currently + // has a large stack) + thread::spawn(move|| { + let result = count(1000); + println!("result = {}", result); + assert_eq!(result, 1000); + }).join(); +} diff --git a/src/test/run-pass/abi/extern/extern-call-indirect.rs b/src/test/run-pass/abi/extern/extern-call-indirect.rs new file mode 100644 index 00000000000..158b54e4b8c --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-call-indirect.rs @@ -0,0 +1,38 @@ +// run-pass +// ignore-wasm32-bare no libc to test ffi with + +#![feature(rustc_private)] + +extern crate libc; + +mod rustrt { + extern crate libc; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, + data: libc::uintptr_t) + -> libc::uintptr_t; + } +} + +extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { + if data == 1 { + data + } else { + fact(data - 1) * data + } +} + +fn fact(n: libc::uintptr_t) -> libc::uintptr_t { + unsafe { + println!("n = {}", n); + rustrt::rust_dbg_call(cb, n) + } +} + +pub fn main() { + let result = fact(10); + println!("result = {}", result); + assert_eq!(result, 3628800); +} diff --git a/src/test/run-pass/abi/extern/extern-call-scrub.rs b/src/test/run-pass/abi/extern/extern-call-scrub.rs new file mode 100644 index 00000000000..a7b1065c9e1 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-call-scrub.rs @@ -0,0 +1,48 @@ +// run-pass +#![allow(unused_must_use)] +// This time we're testing repeatedly going up and down both stacks to +// make sure the stack pointers are maintained properly in both +// directions + +// ignore-emscripten no threads support + +#![feature(rustc_private)] + +extern crate libc; +use std::thread; + +mod rustrt { + extern crate libc; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, + data: libc::uintptr_t) + -> libc::uintptr_t; + } +} + +extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { + if data == 1 { + data + } else { + count(data - 1) + count(data - 1) + } +} + +fn count(n: libc::uintptr_t) -> libc::uintptr_t { + unsafe { + println!("n = {}", n); + rustrt::rust_dbg_call(cb, n) + } +} + +pub fn main() { + // Make sure we're on a thread with small Rust stacks (main currently + // has a large stack) + thread::spawn(move|| { + let result = count(12); + println!("result = {}", result); + assert_eq!(result, 2048); + }).join(); +} diff --git a/src/test/run-pass/abi/extern/extern-pass-TwoU16s.rs b/src/test/run-pass/abi/extern/extern-pass-TwoU16s.rs new file mode 100644 index 00000000000..285bce2e19c --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-pass-TwoU16s.rs @@ -0,0 +1,25 @@ +// run-pass +#![allow(improper_ctypes)] + +// ignore-wasm32-bare no libc for ffi testing + +// Test a foreign function that accepts and returns a struct +// by value. + +#[derive(Copy, Clone, PartialEq, Debug)] +pub struct TwoU16s { + one: u16, two: u16 +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s; +} + +pub fn main() { + unsafe { + let x = TwoU16s {one: 22, two: 23}; + let y = rust_dbg_extern_identity_TwoU16s(x); + assert_eq!(x, y); + } +} diff --git a/src/test/run-pass/abi/extern/extern-pass-TwoU8s.rs b/src/test/run-pass/abi/extern/extern-pass-TwoU8s.rs new file mode 100644 index 00000000000..53a6a0f29f8 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-pass-TwoU8s.rs @@ -0,0 +1,25 @@ +// run-pass +#![allow(improper_ctypes)] + +// ignore-wasm32-bare no libc for ffi testing + +// Test a foreign function that accepts and returns a struct +// by value. + +#[derive(Copy, Clone, PartialEq, Debug)] +pub struct TwoU8s { + one: u8, two: u8 +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s; +} + +pub fn main() { + unsafe { + let x = TwoU8s {one: 22, two: 23}; + let y = rust_dbg_extern_identity_TwoU8s(x); + assert_eq!(x, y); + } +} diff --git a/src/test/run-pass/abi/extern/extern-pass-char.rs b/src/test/run-pass/abi/extern/extern-pass-char.rs new file mode 100644 index 00000000000..22f841b4552 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-pass-char.rs @@ -0,0 +1,16 @@ +// run-pass +// ignore-wasm32-bare no libc for ffi testing + +// Test a function that takes/returns a u8. + + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_identity_u8(v: u8) -> u8; +} + +pub fn main() { + unsafe { + assert_eq!(22, rust_dbg_extern_identity_u8(22)); + } +} diff --git a/src/test/run-pass/abi/extern/extern-pass-double.rs b/src/test/run-pass/abi/extern/extern-pass-double.rs new file mode 100644 index 00000000000..dbd0a2dfa48 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-pass-double.rs @@ -0,0 +1,13 @@ +// run-pass +// ignore-wasm32-bare no libc for ffi testing + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_identity_double(v: f64) -> f64; +} + +pub fn main() { + unsafe { + assert_eq!(22.0_f64, rust_dbg_extern_identity_double(22.0_f64)); + } +} diff --git a/src/test/run-pass/abi/extern/extern-pass-empty.rs b/src/test/run-pass/abi/extern/extern-pass-empty.rs new file mode 100644 index 00000000000..07099a24204 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-pass-empty.rs @@ -0,0 +1,55 @@ +// run-pass +#![allow(improper_ctypes)] // FIXME: this test is inherently not FFI-safe. + +// Test a foreign function that accepts empty struct. + +// pretty-expanded FIXME #23616 +// ignore-msvc +// ignore-emscripten emcc asserts on an empty struct as an argument + +#[repr(C)] +struct TwoU8s { + one: u8, + two: u8, +} + +#[repr(C)] +struct ManyInts { + arg1: i8, + arg2: i16, + arg3: i32, + arg4: i16, + arg5: i8, + arg6: TwoU8s, +} + +#[repr(C)] +struct Empty; + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + fn rust_dbg_extern_empty_struct(v1: ManyInts, e: Empty, v2: ManyInts); +} + +pub fn main() { + unsafe { + let x = ManyInts { + arg1: 2, + arg2: 3, + arg3: 4, + arg4: 5, + arg5: 6, + arg6: TwoU8s { one: 7, two: 8, } + }; + let y = ManyInts { + arg1: 1, + arg2: 2, + arg3: 3, + arg4: 4, + arg5: 5, + arg6: TwoU8s { one: 6, two: 7, } + }; + let empty = Empty; + rust_dbg_extern_empty_struct(x, empty, y); + } +} diff --git a/src/test/run-pass/abi/extern/extern-return-TwoU16s.rs b/src/test/run-pass/abi/extern/extern-return-TwoU16s.rs new file mode 100644 index 00000000000..dd884ee77fe --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-return-TwoU16s.rs @@ -0,0 +1,21 @@ +// run-pass +#![allow(improper_ctypes)] + +// ignore-wasm32-bare no libc to test ffi with + +pub struct TwoU16s { + one: u16, two: u16 +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_return_TwoU16s() -> TwoU16s; +} + +pub fn main() { + unsafe { + let y = rust_dbg_extern_return_TwoU16s(); + assert_eq!(y.one, 10); + assert_eq!(y.two, 20); + } +} diff --git a/src/test/run-pass/abi/extern/extern-return-TwoU32s.rs b/src/test/run-pass/abi/extern/extern-return-TwoU32s.rs new file mode 100644 index 00000000000..d6aaf5c9eaf --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-return-TwoU32s.rs @@ -0,0 +1,21 @@ +// run-pass +#![allow(improper_ctypes)] + +// ignore-wasm32-bare no libc to test ffi with + +pub struct TwoU32s { + one: u32, two: u32 +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s; +} + +pub fn main() { + unsafe { + let y = rust_dbg_extern_return_TwoU32s(); + assert_eq!(y.one, 10); + assert_eq!(y.two, 20); + } +} diff --git a/src/test/run-pass/abi/extern/extern-return-TwoU64s.rs b/src/test/run-pass/abi/extern/extern-return-TwoU64s.rs new file mode 100644 index 00000000000..c5e4ebadc18 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-return-TwoU64s.rs @@ -0,0 +1,21 @@ +// run-pass +#![allow(improper_ctypes)] + +// ignore-wasm32-bare no libc to test ffi with + +pub struct TwoU64s { + one: u64, two: u64 +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_return_TwoU64s() -> TwoU64s; +} + +pub fn main() { + unsafe { + let y = rust_dbg_extern_return_TwoU64s(); + assert_eq!(y.one, 10); + assert_eq!(y.two, 20); + } +} diff --git a/src/test/run-pass/abi/extern/extern-return-TwoU8s.rs b/src/test/run-pass/abi/extern/extern-return-TwoU8s.rs new file mode 100644 index 00000000000..a7cd21b2073 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-return-TwoU8s.rs @@ -0,0 +1,21 @@ +// run-pass +#![allow(improper_ctypes)] + +// ignore-wasm32-bare no libc to test ffi with + +pub struct TwoU8s { + one: u8, two: u8 +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_return_TwoU8s() -> TwoU8s; +} + +pub fn main() { + unsafe { + let y = rust_dbg_extern_return_TwoU8s(); + assert_eq!(y.one, 10); + assert_eq!(y.two, 20); + } +} diff --git a/src/test/run-pass/abi/foreign/auxiliary/foreign_lib.rs b/src/test/run-pass/abi/foreign/auxiliary/foreign_lib.rs new file mode 100644 index 00000000000..de6b0e2118a --- /dev/null +++ b/src/test/run-pass/abi/foreign/auxiliary/foreign_lib.rs @@ -0,0 +1,38 @@ +#![crate_name="foreign_lib"] + +#![feature(rustc_private)] + +pub mod rustrt { + extern crate libc; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn rust_get_test_int() -> libc::intptr_t; + } +} + +pub mod rustrt2 { + extern crate libc; + + extern { + pub fn rust_get_test_int() -> libc::intptr_t; + } +} + +pub mod rustrt3 { + // Different type, but same ABI (on all supported platforms). + // Ensures that we don't ICE or trigger LLVM asserts when + // importing the same symbol under different types. + // See https://github.com/rust-lang/rust/issues/32740. + extern { + pub fn rust_get_test_int() -> *const u8; + } +} + +pub fn local_uses() { + unsafe { + let x = rustrt::rust_get_test_int(); + assert_eq!(x, rustrt2::rust_get_test_int()); + assert_eq!(x as *const _, rustrt3::rust_get_test_int()); + } +} diff --git a/src/test/run-pass/abi/foreign/foreign-call-no-runtime.rs b/src/test/run-pass/abi/foreign/foreign-call-no-runtime.rs new file mode 100644 index 00000000000..c6afa07ad05 --- /dev/null +++ b/src/test/run-pass/abi/foreign/foreign-call-no-runtime.rs @@ -0,0 +1,55 @@ +// run-pass +// ignore-emscripten no threads support + +#![feature(rustc_private)] + +extern crate libc; + +use std::mem; +use std::thread; + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t), + data: libc::uintptr_t) -> libc::uintptr_t; +} + +pub fn main() { + unsafe { + thread::spawn(move|| { + let i: isize = 100; + rust_dbg_call(callback_isize, mem::transmute(&i)); + }).join().unwrap(); + + thread::spawn(move|| { + let i: i32 = 100; + rust_dbg_call(callback_i32, mem::transmute(&i)); + }).join().unwrap(); + + thread::spawn(move|| { + let i: i64 = 100; + rust_dbg_call(callback_i64, mem::transmute(&i)); + }).join().unwrap(); + } +} + +extern fn callback_isize(data: libc::uintptr_t) { + unsafe { + let data: *const isize = mem::transmute(data); + assert_eq!(*data, 100); + } +} + +extern fn callback_i64(data: libc::uintptr_t) { + unsafe { + let data: *const i64 = mem::transmute(data); + assert_eq!(*data, 100); + } +} + +extern fn callback_i32(data: libc::uintptr_t) { + unsafe { + let data: *const i32 = mem::transmute(data); + assert_eq!(*data, 100); + } +} diff --git a/src/test/run-pass/abi/foreign/foreign-fn-with-byval.rs b/src/test/run-pass/abi/foreign/foreign-fn-with-byval.rs new file mode 100644 index 00000000000..3a35599aa57 --- /dev/null +++ b/src/test/run-pass/abi/foreign/foreign-fn-with-byval.rs @@ -0,0 +1,32 @@ +// run-pass +#![allow(improper_ctypes)] + +// ignore-wasm32-bare no libc to test ffi with + +#[derive(Copy, Clone)] +pub struct S { + x: u64, + y: u64, + z: u64, +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn get_x(x: S) -> u64; + pub fn get_y(x: S) -> u64; + pub fn get_z(x: S) -> u64; +} + +#[inline(never)] +fn indirect_call(func: unsafe extern fn(s: S) -> u64, s: S) -> u64 { + unsafe { + func(s) + } +} + +fn main() { + let s = S { x: 1, y: 2, z: 3 }; + assert_eq!(s.x, indirect_call(get_x, s)); + assert_eq!(s.y, indirect_call(get_y, s)); + assert_eq!(s.z, indirect_call(get_z, s)); +} diff --git a/src/test/run-pass/abi/foreign/foreign-no-abi.rs b/src/test/run-pass/abi/foreign/foreign-no-abi.rs new file mode 100644 index 00000000000..2f33fb47656 --- /dev/null +++ b/src/test/run-pass/abi/foreign/foreign-no-abi.rs @@ -0,0 +1,22 @@ +// run-pass +// ABI is cdecl by default + +// ignore-wasm32-bare no libc to test ffi with +// pretty-expanded FIXME #23616 + +#![feature(rustc_private)] + +mod rustrt { + extern crate libc; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn rust_get_test_int() -> libc::intptr_t; + } +} + +pub fn main() { + unsafe { + rustrt::rust_get_test_int(); + } +} diff --git a/src/test/run-pass/abi/issues/auxiliary/issue-25185-1.rs b/src/test/run-pass/abi/issues/auxiliary/issue-25185-1.rs new file mode 100644 index 00000000000..77a4787ba94 --- /dev/null +++ b/src/test/run-pass/abi/issues/auxiliary/issue-25185-1.rs @@ -0,0 +1,8 @@ +// no-prefer-dynamic + +#![crate_type = "rlib"] + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_identity_u32(u: u32) -> u32; +} diff --git a/src/test/run-pass/abi/issues/issue-28676.rs b/src/test/run-pass/abi/issues/issue-28676.rs new file mode 100644 index 00000000000..2b83478ca61 --- /dev/null +++ b/src/test/run-pass/abi/issues/issue-28676.rs @@ -0,0 +1,35 @@ +// run-pass +#![allow(dead_code)] +#![allow(improper_ctypes)] + +// ignore-wasm32-bare no libc to test ffi with + +#[derive(Copy, Clone)] +pub struct Quad { a: u64, b: u64, c: u64, d: u64 } + +mod rustrt { + use super::Quad; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn get_c_many_params(_: *const (), _: *const (), + _: *const (), _: *const (), f: Quad) -> u64; + } +} + +fn test() { + unsafe { + let null = std::ptr::null(); + let q = Quad { + a: 1, + b: 2, + c: 3, + d: 4 + }; + assert_eq!(rustrt::get_c_many_params(null, null, null, null, q), q.c); + } +} + +pub fn main() { + test(); +} diff --git a/src/test/run-pass/abi/lib-defaults.rs b/src/test/run-pass/abi/lib-defaults.rs new file mode 100644 index 00000000000..dcf537866c5 --- /dev/null +++ b/src/test/run-pass/abi/lib-defaults.rs @@ -0,0 +1,16 @@ +// dont-check-compiler-stderr (rust-lang/rust#54222) + +// ignore-wasm32-bare no libc to test ffi with + +// compile-flags: -lrust_test_helpers + +#[link(name = "rust_test_helpers", kind = "static")] +extern "C" { + pub fn rust_dbg_extern_identity_u32(x: u32) -> u32; +} + +fn main() { + unsafe { + rust_dbg_extern_identity_u32(42); + } +} diff --git a/src/test/run-pass/abi/macros/macros-in-extern.rs b/src/test/run-pass/abi/macros/macros-in-extern.rs new file mode 100644 index 00000000000..28abef5cf4e --- /dev/null +++ b/src/test/run-pass/abi/macros/macros-in-extern.rs @@ -0,0 +1,30 @@ +// run-pass +// ignore-wasm32 + +#![feature(decl_macro, macros_in_extern)] + +macro_rules! returns_isize( + ($ident:ident) => ( + fn $ident() -> isize; + ) +); + +macro takes_u32_returns_u32($ident:ident) { + fn $ident (arg: u32) -> u32; +} + +macro_rules! emits_nothing( + () => () +); + +fn main() { + assert_eq!(unsafe { rust_get_test_int() }, 1isize); + assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEFu32); +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + returns_isize!(rust_get_test_int); + takes_u32_returns_u32!(rust_dbg_extern_identity_u32); + emits_nothing!(); +} diff --git a/src/test/run-pass/abi/mir/mir_codegen_calls_variadic.rs b/src/test/run-pass/abi/mir/mir_codegen_calls_variadic.rs new file mode 100644 index 00000000000..dc9fee03b77 --- /dev/null +++ b/src/test/run-pass/abi/mir/mir_codegen_calls_variadic.rs @@ -0,0 +1,22 @@ +// run-pass +// ignore-wasm32-bare no libc to test ffi with + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + fn rust_interesting_average(_: i64, ...) -> f64; +} + +fn test(a: i64, b: i64, c: i64, d: i64, e: i64, f: T, g: U) -> i64 { + unsafe { + rust_interesting_average(6, a, a as f64, + b, b as f64, + c, c as f64, + d, d as f64, + e, e as f64, + f, g) as i64 + } +} + +fn main(){ + assert_eq!(test(10, 20, 30, 40, 50, 60_i64, 60.0_f64), 70); +} diff --git a/src/test/run-pass/abi/numbers-arithmetic/i128-ffi.rs b/src/test/run-pass/abi/numbers-arithmetic/i128-ffi.rs new file mode 100644 index 00000000000..19edf9779f3 --- /dev/null +++ b/src/test/run-pass/abi/numbers-arithmetic/i128-ffi.rs @@ -0,0 +1,31 @@ +// run-pass +#![allow(improper_ctypes)] + +// MSVC doesn't support 128 bit integers, and other Windows +// C compilers have very inconsistent views on how the ABI +// should look like. + +// ignore-windows +// ignore-32bit + +#[link(name = "rust_test_helpers", kind = "static")] +extern "C" { + fn identity(f: u128) -> u128; + fn square(f: i128) -> i128; + fn sub(f: i128, f: i128) -> i128; +} + +fn main() { + unsafe { + let a = 0x734C_C2F2_A521; + let b = 0x33EE_0E2A_54E2_59DA_A0E7_8E41; + let b_out = identity(b); + assert_eq!(b, b_out); + let a_square = square(a); + assert_eq!(b, a_square as u128); + let k = 0x1234_5678_9ABC_DEFF_EDCB_A987_6543_210; + let k_d = 0x2468_ACF1_3579_BDFF_DB97_530E_CA86_420; + let k_out = sub(k_d, k); + assert_eq!(k, k_out); + } +} diff --git a/src/test/run-pass/abi/proc_macro/macros-in-extern.rs b/src/test/run-pass/abi/proc_macro/macros-in-extern.rs new file mode 100644 index 00000000000..99e3f7d14fd --- /dev/null +++ b/src/test/run-pass/abi/proc_macro/macros-in-extern.rs @@ -0,0 +1,24 @@ +// aux-build:test-macros.rs +// ignore-wasm32 + +#![feature(macros_in_extern)] + +extern crate test_macros; + +use test_macros::{nop_attr, no_output, emit_input}; + +fn main() { + assert_eq!(unsafe { rust_get_test_int() }, 1isize); + assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEF); +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + #[no_output] + fn some_definitely_unknown_symbol_which_should_be_removed(); + + #[nop_attr] + fn rust_get_test_int() -> isize; + + emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;); +} diff --git a/src/test/run-pass/abi/rfcs/rfc1717/library-override.rs b/src/test/run-pass/abi/rfcs/rfc1717/library-override.rs new file mode 100644 index 00000000000..014ccac31b7 --- /dev/null +++ b/src/test/run-pass/abi/rfcs/rfc1717/library-override.rs @@ -0,0 +1,14 @@ +// run-pass +// ignore-wasm32-bare no libc to test ffi with +// compile-flags: -lstatic=wronglibrary:rust_test_helpers + +#[link(name = "wronglibrary", kind = "dylib")] +extern "C" { + pub fn rust_dbg_extern_identity_u32(x: u32) -> u32; +} + +fn main() { + unsafe { + rust_dbg_extern_identity_u32(42); + } +} diff --git a/src/test/run-pass/abi/segfault-no-out-of-stack.rs b/src/test/run-pass/abi/segfault-no-out-of-stack.rs new file mode 100644 index 00000000000..e90efface68 --- /dev/null +++ b/src/test/run-pass/abi/segfault-no-out-of-stack.rs @@ -0,0 +1,48 @@ +#![allow(unused_imports)] +// ignore-cloudabi can't run commands +// ignore-emscripten can't run commands +// ignore-sgx no processes + +#![feature(rustc_private)] + +extern crate libc; + +use std::process::{Command, ExitStatus}; +use std::env; + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + fn rust_get_null_ptr() -> *mut ::libc::c_char; +} + +#[cfg(unix)] +fn check_status(status: std::process::ExitStatus) +{ + use libc; + use std::os::unix::process::ExitStatusExt; + + assert!(status.signal() == Some(libc::SIGSEGV) + || status.signal() == Some(libc::SIGBUS)); +} + +#[cfg(not(unix))] +fn check_status(status: std::process::ExitStatus) +{ + assert!(!status.success()); +} + +fn main() { + let args: Vec = env::args().collect(); + if args.len() > 1 && args[1] == "segfault" { + unsafe { *rust_get_null_ptr() = 1; }; // trigger a segfault + } else { + let segfault = Command::new(&args[0]).arg("segfault").output().unwrap(); + let stderr = String::from_utf8_lossy(&segfault.stderr); + let stdout = String::from_utf8_lossy(&segfault.stdout); + println!("stdout: {}", stdout); + println!("stderr: {}", stderr); + println!("status: {}", segfault.status); + check_status(segfault.status); + assert!(!stderr.contains("has overflowed its stack")); + } +} diff --git a/src/test/run-pass/abi/stack-probes.rs b/src/test/run-pass/abi/stack-probes.rs new file mode 100644 index 00000000000..773d0ace90e --- /dev/null +++ b/src/test/run-pass/abi/stack-probes.rs @@ -0,0 +1,67 @@ +// ignore-arm +// ignore-aarch64 +// ignore-mips +// ignore-mips64 +// ignore-powerpc +// ignore-s390x +// ignore-sparc +// ignore-sparc64 +// ignore-wasm +// ignore-cloudabi no processes +// ignore-emscripten no processes +// ignore-sgx no processes +// ignore-musl FIXME #31506 + +use std::mem; +use std::process::Command; +use std::thread; +use std::env; + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + #[link_name = "rust_dbg_extern_identity_u64"] + fn black_box(u: u64); +} + +fn main() { + let args = env::args().skip(1).collect::>(); + if args.len() > 0 { + match &args[0][..] { + "main-thread" => recurse(&[]), + "child-thread" => thread::spawn(|| recurse(&[])).join().unwrap(), + _ => panic!(), + } + return + } + + let me = env::current_exe().unwrap(); + + // The linux kernel has some different behavior for the main thread because + // the main thread's stack can typically grow. We can't always guarantee + // that we report stack overflow on the main thread, see #43052 for some + // details + if cfg!(not(target_os = "linux")) { + assert_overflow(Command::new(&me).arg("main-thread")); + } + assert_overflow(Command::new(&me).arg("child-thread")); +} + +#[allow(unconditional_recursion)] +fn recurse(array: &[u64]) { + unsafe { black_box(array.as_ptr() as u64); } + #[allow(deprecated)] + let local: [_; 1024] = unsafe { mem::uninitialized() }; + recurse(&local); +} + +fn assert_overflow(cmd: &mut Command) { + let output = cmd.output().unwrap(); + assert!(!output.status.success()); + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + println!("status: {}", output.status); + println!("stdout: {}", stdout); + println!("stderr: {}", stderr); + assert!(stdout.is_empty()); + assert!(stderr.contains("has overflowed its stack\n")); +} diff --git a/src/test/run-pass/abi/statics/static-mut-foreign.rs b/src/test/run-pass/abi/statics/static-mut-foreign.rs new file mode 100644 index 00000000000..5d6fa416b98 --- /dev/null +++ b/src/test/run-pass/abi/statics/static-mut-foreign.rs @@ -0,0 +1,41 @@ +// run-pass +// Constants (static variables) can be used to match in patterns, but mutable +// statics cannot. This ensures that there's some form of error if this is +// attempted. + +// ignore-wasm32-bare no libc to test ffi with + +#![feature(rustc_private)] + +extern crate libc; + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + static mut rust_dbg_static_mut: libc::c_int; + pub fn rust_dbg_static_mut_check_four(); +} + +unsafe fn static_bound(_: &'static libc::c_int) {} + +fn static_bound_set(a: &'static mut libc::c_int) { + *a = 3; +} + +unsafe fn run() { + assert_eq!(rust_dbg_static_mut, 3); + rust_dbg_static_mut = 4; + assert_eq!(rust_dbg_static_mut, 4); + rust_dbg_static_mut_check_four(); + rust_dbg_static_mut += 1; + assert_eq!(rust_dbg_static_mut, 5); + rust_dbg_static_mut *= 3; + assert_eq!(rust_dbg_static_mut, 15); + rust_dbg_static_mut = -3; + assert_eq!(rust_dbg_static_mut, -3); + static_bound(&rust_dbg_static_mut); + static_bound_set(&mut rust_dbg_static_mut); +} + +pub fn main() { + unsafe { run() } +} diff --git a/src/test/run-pass/abi/structs-enums/struct-return.rs b/src/test/run-pass/abi/structs-enums/struct-return.rs new file mode 100644 index 00000000000..5930fc4acbb --- /dev/null +++ b/src/test/run-pass/abi/structs-enums/struct-return.rs @@ -0,0 +1,64 @@ +// run-pass +#![allow(dead_code)] +// ignore-wasm32-bare no libc to test ffi with + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Quad { a: u64, b: u64, c: u64, d: u64 } + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Floats { a: f64, b: u8, c: f64 } + +mod rustrt { + use super::{Floats, Quad}; + + #[link(name = "rust_test_helpers", kind = "static")] + extern { + pub fn rust_dbg_abi_1(q: Quad) -> Quad; + pub fn rust_dbg_abi_2(f: Floats) -> Floats; + } +} + +fn test1() { + unsafe { + let q = Quad { a: 0xaaaa_aaaa_aaaa_aaaa, + b: 0xbbbb_bbbb_bbbb_bbbb, + c: 0xcccc_cccc_cccc_cccc, + d: 0xdddd_dddd_dddd_dddd }; + let qq = rustrt::rust_dbg_abi_1(q); + println!("a: {:x}", qq.a as usize); + println!("b: {:x}", qq.b as usize); + println!("c: {:x}", qq.c as usize); + println!("d: {:x}", qq.d as usize); + assert_eq!(qq.a, q.c + 1); + assert_eq!(qq.b, q.d - 1); + assert_eq!(qq.c, q.a + 1); + assert_eq!(qq.d, q.b - 1); + } +} + +#[cfg(target_pointer_width = "64")] +fn test2() { + unsafe { + let f = Floats { a: 1.234567890e-15_f64, + b: 0b_1010_1010, + c: 1.0987654321e-15_f64 }; + let ff = rustrt::rust_dbg_abi_2(f); + println!("a: {}", ff.a as f64); + println!("b: {}", ff.b as usize); + println!("c: {}", ff.c as f64); + assert_eq!(ff.a, f.c + 1.0f64); + assert_eq!(ff.b, 0xff); + assert_eq!(ff.c, f.a - 1.0f64); + } +} + +#[cfg(target_pointer_width = "32")] +fn test2() { +} + +pub fn main() { + test1(); + test2(); +} diff --git a/src/test/run-pass/abi/union/union-c-interop.rs b/src/test/run-pass/abi/union/union-c-interop.rs new file mode 100644 index 00000000000..00f04d5b7ff --- /dev/null +++ b/src/test/run-pass/abi/union/union-c-interop.rs @@ -0,0 +1,37 @@ +// run-pass +#![allow(non_snake_case)] + +// ignore-wasm32-bare no libc to test ffi with + +#[derive(Clone, Copy)] +#[repr(C)] +struct LARGE_INTEGER_U { + LowPart: u32, + HighPart: u32, +} + +#[derive(Clone, Copy)] +#[repr(C)] +union LARGE_INTEGER { + __unnamed__: LARGE_INTEGER_U, + u: LARGE_INTEGER_U, + QuadPart: u64, +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern "C" { + fn increment_all_parts(_: LARGE_INTEGER) -> LARGE_INTEGER; +} + +fn main() { + unsafe { + let mut li = LARGE_INTEGER { QuadPart: 0 }; + let li_c = increment_all_parts(li); + li.__unnamed__.LowPart += 1; + li.__unnamed__.HighPart += 1; + li.u.LowPart += 1; + li.u.HighPart += 1; + li.QuadPart += 1; + assert_eq!(li.QuadPart, li_c.QuadPart); + } +} diff --git a/src/test/run-pass/abi/variadic-ffi.rs b/src/test/run-pass/abi/variadic-ffi.rs new file mode 100644 index 00000000000..d6fbb1773b2 --- /dev/null +++ b/src/test/run-pass/abi/variadic-ffi.rs @@ -0,0 +1,83 @@ +// ignore-wasm32-bare no libc to test ffi with +#![feature(c_variadic)] + +use std::ffi::VaList; + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + fn rust_interesting_average(_: u64, ...) -> f64; + + // FIXME: we need to disable this lint for `VaList`, + // since it contains a `MaybeUninit` on the asmjs target, + // and this type isn't FFI-safe. This is OK for now, + // since the type is layout-compatible with `i32`. + #[cfg_attr(target_arch = "asmjs", allow(improper_ctypes))] + fn rust_valist_interesting_average(_: u64, _: VaList) -> f64; +} + +pub unsafe extern "C" fn test_valist_forward(n: u64, mut ap: ...) -> f64 { + rust_valist_interesting_average(n, ap.as_va_list()) +} + +pub unsafe extern "C" fn test_va_copy(_: u64, mut ap: ...) { + let mut ap2 = ap.clone(); + assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 30); + + // Advance one pair in the copy before checking + let mut ap2 = ap.clone(); + let _ = ap2.arg::(); + let _ = ap2.arg::(); + assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 50); + + // Advance one pair in the original + let _ = ap.arg::(); + let _ = ap.arg::(); + + let mut ap2 = ap.clone(); + assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 50); + + let mut ap2 = ap.clone(); + let _ = ap2.arg::(); + let _ = ap2.arg::(); + assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 70); +} + +pub fn main() { + // Call without variadic arguments + unsafe { + assert!(rust_interesting_average(0).is_nan()); + } + + // Call with direct arguments + unsafe { + assert_eq!(rust_interesting_average(1, 10i64, 10.0f64) as i64, 20); + } + + // Call with named arguments, variable number of them + let (x1, x2, x3, x4) = (10i64, 10.0f64, 20i64, 20.0f64); + unsafe { + assert_eq!(rust_interesting_average(2, x1, x2, x3, x4) as i64, 30); + } + + // A function that takes a function pointer + unsafe fn call(fp: unsafe extern fn(u64, ...) -> f64) { + let (x1, x2, x3, x4) = (10i64, 10.0f64, 20i64, 20.0f64); + assert_eq!(fp(2, x1, x2, x3, x4) as i64, 30); + } + + unsafe { + call(rust_interesting_average); + + // Make a function pointer, pass indirectly + let x: unsafe extern fn(u64, ...) -> f64 = rust_interesting_average; + call(x); + } + + unsafe { + assert_eq!(test_valist_forward(2, 10i64, 10f64, 20i64, 20f64) as i64, 30); + } + + unsafe { + test_va_copy(4, 10i64, 10f64, 20i64, 20f64, 30i64, 30f64, 40i64, 40f64); + } +} From 98325eb592f537e87100199c0c67682306df3fa4 Mon Sep 17 00:00:00 2001 From: Kevin Per Date: Tue, 9 Jul 2019 09:05:45 +0200 Subject: [PATCH 2/7] Grouping ABI tests (2) #62401 --- .../abi/extern/extern-pass-TwoU32s.rs | 25 +++++++++++++++++++ .../abi/extern/extern-pass-TwoU64s.rs | 25 +++++++++++++++++++ .../run-pass/abi/extern/extern-pass-u32.rs | 16 ++++++++++++ .../run-pass/abi/extern/extern-pass-u64.rs | 16 ++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 src/test/run-pass/abi/extern/extern-pass-TwoU32s.rs create mode 100644 src/test/run-pass/abi/extern/extern-pass-TwoU64s.rs create mode 100644 src/test/run-pass/abi/extern/extern-pass-u32.rs create mode 100644 src/test/run-pass/abi/extern/extern-pass-u64.rs diff --git a/src/test/run-pass/abi/extern/extern-pass-TwoU32s.rs b/src/test/run-pass/abi/extern/extern-pass-TwoU32s.rs new file mode 100644 index 00000000000..fb18aa8d22f --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-pass-TwoU32s.rs @@ -0,0 +1,25 @@ +// run-pass +#![allow(improper_ctypes)] + +// ignore-wasm32-bare no libc for ffi testing + +// Test a foreign function that accepts and returns a struct +// by value. + +#[derive(Copy, Clone, PartialEq, Debug)] +pub struct TwoU32s { + one: u32, two: u32 +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s; +} + +pub fn main() { + unsafe { + let x = TwoU32s {one: 22, two: 23}; + let y = rust_dbg_extern_identity_TwoU32s(x); + assert_eq!(x, y); + } +} diff --git a/src/test/run-pass/abi/extern/extern-pass-TwoU64s.rs b/src/test/run-pass/abi/extern/extern-pass-TwoU64s.rs new file mode 100644 index 00000000000..419648263aa --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-pass-TwoU64s.rs @@ -0,0 +1,25 @@ +// run-pass +#![allow(improper_ctypes)] + +// ignore-wasm32-bare no libc for ffi testing + +// Test a foreign function that accepts and returns a struct +// by value. + +#[derive(Copy, Clone, PartialEq, Debug)] +pub struct TwoU64s { + one: u64, two: u64 +} + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s; +} + +pub fn main() { + unsafe { + let x = TwoU64s {one: 22, two: 23}; + let y = rust_dbg_extern_identity_TwoU64s(x); + assert_eq!(x, y); + } +} diff --git a/src/test/run-pass/abi/extern/extern-pass-u32.rs b/src/test/run-pass/abi/extern/extern-pass-u32.rs new file mode 100644 index 00000000000..f2efdb7d366 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-pass-u32.rs @@ -0,0 +1,16 @@ +// run-pass +// ignore-wasm32-bare no libc for ffi testing + +// Test a function that takes/returns a u32. + + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_identity_u32(v: u32) -> u32; +} + +pub fn main() { + unsafe { + assert_eq!(22, rust_dbg_extern_identity_u32(22)); + } +} diff --git a/src/test/run-pass/abi/extern/extern-pass-u64.rs b/src/test/run-pass/abi/extern/extern-pass-u64.rs new file mode 100644 index 00000000000..975446d430c --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-pass-u64.rs @@ -0,0 +1,16 @@ +// run-pass +// ignore-wasm32-bare no libc for ffi testing + +// Test a call to a function that takes/returns a u64. + + +#[link(name = "rust_test_helpers", kind = "static")] +extern { + pub fn rust_dbg_extern_identity_u64(v: u64) -> u64; +} + +pub fn main() { + unsafe { + assert_eq!(22, rust_dbg_extern_identity_u64(22)); + } +} From cac53fe3f24f9862d7faa85296f348e17c729bc4 Mon Sep 17 00:00:00 2001 From: Kevin Per Date: Thu, 11 Jul 2019 19:40:09 +0200 Subject: [PATCH 3/7] Fixing broken tests #62401 The grouping led to a lot of `mv`. Therefore, some relative paths were wrong. In this commit the dependent files were also moved so that the paths work again. --- .../anon-extern-mod-cross-crate-2.rs | 14 ++++++++++ .../run-pass/abi/duplicated-external-mods.rs | 8 ++++++ .../run-pass/abi/extern/extern-crosscrate.rs | 21 +++++++++++++++ src/test/run-pass/abi/foreign/foreign-dupe.rs | 17 ++++++++++++ .../run-pass/abi/invoke-external-foreign.rs | 16 ++++++++++++ .../abi/issues/auxiliary/issue-25185-2.rs | 3 +++ src/test/run-pass/abi/issues/issue-25185.rs | 13 ++++++++++ .../abi/proc_macro/auxiliary/test-macros.rs | 26 +++++++++++++++++++ src/test/run-pass/abi/stack-probes-lto.rs | 18 +++++++++++++ 9 files changed, 136 insertions(+) create mode 100644 src/test/run-pass/abi/cross-crate/anon-extern-mod-cross-crate-2.rs create mode 100644 src/test/run-pass/abi/duplicated-external-mods.rs create mode 100644 src/test/run-pass/abi/extern/extern-crosscrate.rs create mode 100644 src/test/run-pass/abi/foreign/foreign-dupe.rs create mode 100644 src/test/run-pass/abi/invoke-external-foreign.rs create mode 100644 src/test/run-pass/abi/issues/auxiliary/issue-25185-2.rs create mode 100644 src/test/run-pass/abi/issues/issue-25185.rs create mode 100644 src/test/run-pass/abi/proc_macro/auxiliary/test-macros.rs create mode 100644 src/test/run-pass/abi/stack-probes-lto.rs diff --git a/src/test/run-pass/abi/cross-crate/anon-extern-mod-cross-crate-2.rs b/src/test/run-pass/abi/cross-crate/anon-extern-mod-cross-crate-2.rs new file mode 100644 index 00000000000..77168be5374 --- /dev/null +++ b/src/test/run-pass/abi/cross-crate/anon-extern-mod-cross-crate-2.rs @@ -0,0 +1,14 @@ +// run-pass +// aux-build:anon-extern-mod-cross-crate-1.rs +// pretty-expanded FIXME #23616 +// ignore-wasm32-bare no libc to test ffi with + +extern crate anonexternmod; + +use anonexternmod::rust_get_test_int; + +pub fn main() { + unsafe { + rust_get_test_int(); + } +} diff --git a/src/test/run-pass/abi/duplicated-external-mods.rs b/src/test/run-pass/abi/duplicated-external-mods.rs new file mode 100644 index 00000000000..f2c1e1f6540 --- /dev/null +++ b/src/test/run-pass/abi/duplicated-external-mods.rs @@ -0,0 +1,8 @@ +// aux-build:anon-extern-mod-cross-crate-1.rs +// aux-build:anon-extern-mod-cross-crate-1.rs +// pretty-expanded FIXME #23616 +// ignore-wasm32-bare no libc to test ffi with + +extern crate anonexternmod; + +pub fn main() { } diff --git a/src/test/run-pass/abi/extern/extern-crosscrate.rs b/src/test/run-pass/abi/extern/extern-crosscrate.rs new file mode 100644 index 00000000000..123ce20ca26 --- /dev/null +++ b/src/test/run-pass/abi/extern/extern-crosscrate.rs @@ -0,0 +1,21 @@ +// run-pass +// aux-build:extern-crosscrate-source.rs +// ignore-wasm32-bare no libc to test ffi with + +#![feature(rustc_private)] + +extern crate externcallback; +extern crate libc; + +fn fact(n: libc::uintptr_t) -> libc::uintptr_t { + unsafe { + println!("n = {}", n); + externcallback::rustrt::rust_dbg_call(externcallback::cb, n) + } +} + +pub fn main() { + let result = fact(10); + println!("result = {}", result); + assert_eq!(result, 3628800); +} diff --git a/src/test/run-pass/abi/foreign/foreign-dupe.rs b/src/test/run-pass/abi/foreign/foreign-dupe.rs new file mode 100644 index 00000000000..3c9f0f583d4 --- /dev/null +++ b/src/test/run-pass/abi/foreign/foreign-dupe.rs @@ -0,0 +1,17 @@ +// run-pass +// aux-build:foreign_lib.rs +// ignore-wasm32-bare no libc to test ffi with + +// Check that we can still call duplicated extern (imported) functions +// which were declared in another crate. See issues #32740 and #32783. + + +extern crate foreign_lib; + +pub fn main() { + unsafe { + let x = foreign_lib::rustrt::rust_get_test_int(); + assert_eq!(x, foreign_lib::rustrt2::rust_get_test_int()); + assert_eq!(x as *const _, foreign_lib::rustrt3::rust_get_test_int()); + } +} diff --git a/src/test/run-pass/abi/invoke-external-foreign.rs b/src/test/run-pass/abi/invoke-external-foreign.rs new file mode 100644 index 00000000000..d34933cde42 --- /dev/null +++ b/src/test/run-pass/abi/invoke-external-foreign.rs @@ -0,0 +1,16 @@ +// aux-build:foreign_lib.rs +// ignore-wasm32-bare no libc to test ffi with + +// The purpose of this test is to check that we can +// successfully (and safely) invoke external, cdecl +// functions from outside the crate. + +// pretty-expanded FIXME #23616 + +extern crate foreign_lib; + +pub fn main() { + unsafe { + let _foo = foreign_lib::rustrt::rust_get_test_int(); + } +} diff --git a/src/test/run-pass/abi/issues/auxiliary/issue-25185-2.rs b/src/test/run-pass/abi/issues/auxiliary/issue-25185-2.rs new file mode 100644 index 00000000000..7ce3df255a3 --- /dev/null +++ b/src/test/run-pass/abi/issues/auxiliary/issue-25185-2.rs @@ -0,0 +1,3 @@ +extern crate issue_25185_1; + +pub use issue_25185_1::rust_dbg_extern_identity_u32; diff --git a/src/test/run-pass/abi/issues/issue-25185.rs b/src/test/run-pass/abi/issues/issue-25185.rs new file mode 100644 index 00000000000..383c9a1e9c4 --- /dev/null +++ b/src/test/run-pass/abi/issues/issue-25185.rs @@ -0,0 +1,13 @@ +// run-pass +// aux-build:issue-25185-1.rs +// aux-build:issue-25185-2.rs +// ignore-wasm32-bare no libc for ffi testing + +extern crate issue_25185_2; + +fn main() { + let x = unsafe { + issue_25185_2::rust_dbg_extern_identity_u32(1) + }; + assert_eq!(x, 1); +} diff --git a/src/test/run-pass/abi/proc_macro/auxiliary/test-macros.rs b/src/test/run-pass/abi/proc_macro/auxiliary/test-macros.rs new file mode 100644 index 00000000000..15fe3804f9b --- /dev/null +++ b/src/test/run-pass/abi/proc_macro/auxiliary/test-macros.rs @@ -0,0 +1,26 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_attribute] +pub fn nop_attr(_attr: TokenStream, input: TokenStream) -> TokenStream { + assert!(_attr.to_string().is_empty()); + input +} + +#[proc_macro_attribute] +pub fn no_output(_attr: TokenStream, _input: TokenStream) -> TokenStream { + assert!(_attr.to_string().is_empty()); + assert!(!_input.to_string().is_empty()); + "".parse().unwrap() +} + +#[proc_macro] +pub fn emit_input(input: TokenStream) -> TokenStream { + input +} diff --git a/src/test/run-pass/abi/stack-probes-lto.rs b/src/test/run-pass/abi/stack-probes-lto.rs new file mode 100644 index 00000000000..1274f032a3e --- /dev/null +++ b/src/test/run-pass/abi/stack-probes-lto.rs @@ -0,0 +1,18 @@ +// ignore-arm +// ignore-aarch64 +// ignore-mips +// ignore-mips64 +// ignore-powerpc +// ignore-s390x +// ignore-sparc +// ignore-sparc64 +// ignore-wasm +// ignore-cloudabi no processes +// ignore-emscripten no processes +// ignore-sgx no processes +// ignore-musl FIXME #31506 +// ignore-pretty +// compile-flags: -C lto +// no-prefer-dynamic + +include!("stack-probes.rs"); From df713dd39709bfdc34f364cd78d345a29d7b9d8a Mon Sep 17 00:00:00 2001 From: Kevin Per Date: Thu, 15 Aug 2019 16:00:54 +0200 Subject: [PATCH 4/7] Group all ui tests and move to abi #62593 --- src/test/ui/{ => abi}/abi-sysv64-arg-passing.rs | 0 src/test/ui/{ => abi}/abi-sysv64-register-usage.rs | 0 src/test/ui/{ => abi}/abort-on-c-abi.rs | 0 src/test/ui/{ => abi}/anon-extern-mod.rs | 0 src/test/ui/{ => abi}/auxiliary/anon-extern-mod-cross-crate-1.rs | 0 src/test/ui/{ => abi}/auxiliary/foreign_lib.rs | 0 src/test/ui/{ => abi}/c-stack-as-value.rs | 0 src/test/ui/{ => abi}/cabi-int-widening.rs | 0 .../{ => abi}/consts/auxiliary/anon-extern-mod-cross-crate-1.rs | 0 .../ui/{ => abi}/cross-crate/anon-extern-mod-cross-crate-2.rs | 0 .../cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs | 0 src/test/ui/{ => abi}/duplicated-external-mods.rs | 0 .../ui/{ => abi}/extern/auxiliary/extern-crosscrate-source.rs | 0 src/test/ui/{ => abi}/extern/extern-call-deep.rs | 0 src/test/ui/{ => abi}/extern/extern-call-deep2.rs | 0 src/test/ui/{ => abi}/extern/extern-call-direct.rs | 0 src/test/ui/{ => abi}/extern/extern-call-indirect.rs | 0 src/test/ui/{ => abi}/extern/extern-call-scrub.rs | 0 src/test/ui/{ => abi}/extern/extern-crosscrate.rs | 0 src/test/ui/{ => abi}/extern/extern-pass-TwoU16s.rs | 0 src/test/ui/{ => abi}/extern/extern-pass-TwoU32s.rs | 0 src/test/ui/{ => abi}/extern/extern-pass-TwoU64s.rs | 0 src/test/ui/{ => abi}/extern/extern-pass-TwoU8s.rs | 0 src/test/ui/{ => abi}/extern/extern-pass-char.rs | 0 src/test/ui/{ => abi}/extern/extern-pass-double.rs | 0 src/test/ui/{ => abi}/extern/extern-pass-empty.rs | 0 src/test/ui/{ => abi}/extern/extern-pass-u32.rs | 0 src/test/ui/{ => abi}/extern/extern-pass-u64.rs | 0 src/test/ui/{ => abi}/extern/extern-return-TwoU16s.rs | 0 src/test/ui/{ => abi}/extern/extern-return-TwoU32s.rs | 0 src/test/ui/{ => abi}/extern/extern-return-TwoU64s.rs | 0 src/test/ui/{ => abi}/extern/extern-return-TwoU8s.rs | 0 src/test/ui/{ => abi}/foreign/auxiliary/foreign_lib.rs | 0 src/test/ui/{ => abi}/foreign/foreign-call-no-runtime.rs | 0 src/test/ui/{ => abi}/foreign/foreign-dupe.rs | 0 src/test/ui/{ => abi}/foreign/foreign-fn-with-byval.rs | 0 src/test/ui/{ => abi}/foreign/foreign-no-abi.rs | 0 src/test/ui/{ => abi}/invoke-external-foreign.rs | 0 src/test/ui/{ => abi}/lib-defaults.rs | 0 src/test/ui/{ => abi}/macros/macros-in-extern.rs | 0 src/test/ui/{ => abi}/macros/macros-in-extern.stderr | 0 src/test/ui/{ => abi}/mir/mir_codegen_calls_variadic.rs | 0 src/test/ui/{ => abi}/numbers-arithmetic/i128-ffi.rs | 0 src/test/ui/{ => abi}/proc-macro/auxiliary/test-macros.rs | 0 src/test/ui/{ => abi}/proc-macro/macros-in-extern.rs | 0 src/test/ui/{ => abi}/proc-macro/macros-in-extern.stderr | 0 src/test/ui/{ => abi}/segfault-no-out-of-stack.rs | 0 src/test/ui/{ => abi}/stack-probes-lto.rs | 0 src/test/ui/{ => abi}/stack-probes.rs | 0 src/test/ui/{ => abi}/statics/static-mut-foreign.rs | 0 src/test/ui/{structs-enums => abi/struct-enums}/struct-return.rs | 0 src/test/ui/{ => abi}/union/union-c-interop.rs | 0 src/test/ui/{ => abi}/variadic-ffi.rs | 0 53 files changed, 0 insertions(+), 0 deletions(-) rename src/test/ui/{ => abi}/abi-sysv64-arg-passing.rs (100%) rename src/test/ui/{ => abi}/abi-sysv64-register-usage.rs (100%) rename src/test/ui/{ => abi}/abort-on-c-abi.rs (100%) rename src/test/ui/{ => abi}/anon-extern-mod.rs (100%) rename src/test/ui/{ => abi}/auxiliary/anon-extern-mod-cross-crate-1.rs (100%) rename src/test/ui/{ => abi}/auxiliary/foreign_lib.rs (100%) rename src/test/ui/{ => abi}/c-stack-as-value.rs (100%) rename src/test/ui/{ => abi}/cabi-int-widening.rs (100%) rename src/test/ui/{ => abi}/consts/auxiliary/anon-extern-mod-cross-crate-1.rs (100%) rename src/test/ui/{ => abi}/cross-crate/anon-extern-mod-cross-crate-2.rs (100%) rename src/test/ui/{ => abi}/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs (100%) rename src/test/ui/{ => abi}/duplicated-external-mods.rs (100%) rename src/test/ui/{ => abi}/extern/auxiliary/extern-crosscrate-source.rs (100%) rename src/test/ui/{ => abi}/extern/extern-call-deep.rs (100%) rename src/test/ui/{ => abi}/extern/extern-call-deep2.rs (100%) rename src/test/ui/{ => abi}/extern/extern-call-direct.rs (100%) rename src/test/ui/{ => abi}/extern/extern-call-indirect.rs (100%) rename src/test/ui/{ => abi}/extern/extern-call-scrub.rs (100%) rename src/test/ui/{ => abi}/extern/extern-crosscrate.rs (100%) rename src/test/ui/{ => abi}/extern/extern-pass-TwoU16s.rs (100%) rename src/test/ui/{ => abi}/extern/extern-pass-TwoU32s.rs (100%) rename src/test/ui/{ => abi}/extern/extern-pass-TwoU64s.rs (100%) rename src/test/ui/{ => abi}/extern/extern-pass-TwoU8s.rs (100%) rename src/test/ui/{ => abi}/extern/extern-pass-char.rs (100%) rename src/test/ui/{ => abi}/extern/extern-pass-double.rs (100%) rename src/test/ui/{ => abi}/extern/extern-pass-empty.rs (100%) rename src/test/ui/{ => abi}/extern/extern-pass-u32.rs (100%) rename src/test/ui/{ => abi}/extern/extern-pass-u64.rs (100%) rename src/test/ui/{ => abi}/extern/extern-return-TwoU16s.rs (100%) rename src/test/ui/{ => abi}/extern/extern-return-TwoU32s.rs (100%) rename src/test/ui/{ => abi}/extern/extern-return-TwoU64s.rs (100%) rename src/test/ui/{ => abi}/extern/extern-return-TwoU8s.rs (100%) rename src/test/ui/{ => abi}/foreign/auxiliary/foreign_lib.rs (100%) rename src/test/ui/{ => abi}/foreign/foreign-call-no-runtime.rs (100%) rename src/test/ui/{ => abi}/foreign/foreign-dupe.rs (100%) rename src/test/ui/{ => abi}/foreign/foreign-fn-with-byval.rs (100%) rename src/test/ui/{ => abi}/foreign/foreign-no-abi.rs (100%) rename src/test/ui/{ => abi}/invoke-external-foreign.rs (100%) rename src/test/ui/{ => abi}/lib-defaults.rs (100%) rename src/test/ui/{ => abi}/macros/macros-in-extern.rs (100%) rename src/test/ui/{ => abi}/macros/macros-in-extern.stderr (100%) rename src/test/ui/{ => abi}/mir/mir_codegen_calls_variadic.rs (100%) rename src/test/ui/{ => abi}/numbers-arithmetic/i128-ffi.rs (100%) rename src/test/ui/{ => abi}/proc-macro/auxiliary/test-macros.rs (100%) rename src/test/ui/{ => abi}/proc-macro/macros-in-extern.rs (100%) rename src/test/ui/{ => abi}/proc-macro/macros-in-extern.stderr (100%) rename src/test/ui/{ => abi}/segfault-no-out-of-stack.rs (100%) rename src/test/ui/{ => abi}/stack-probes-lto.rs (100%) rename src/test/ui/{ => abi}/stack-probes.rs (100%) rename src/test/ui/{ => abi}/statics/static-mut-foreign.rs (100%) rename src/test/ui/{structs-enums => abi/struct-enums}/struct-return.rs (100%) rename src/test/ui/{ => abi}/union/union-c-interop.rs (100%) rename src/test/ui/{ => abi}/variadic-ffi.rs (100%) diff --git a/src/test/ui/abi-sysv64-arg-passing.rs b/src/test/ui/abi/abi-sysv64-arg-passing.rs similarity index 100% rename from src/test/ui/abi-sysv64-arg-passing.rs rename to src/test/ui/abi/abi-sysv64-arg-passing.rs diff --git a/src/test/ui/abi-sysv64-register-usage.rs b/src/test/ui/abi/abi-sysv64-register-usage.rs similarity index 100% rename from src/test/ui/abi-sysv64-register-usage.rs rename to src/test/ui/abi/abi-sysv64-register-usage.rs diff --git a/src/test/ui/abort-on-c-abi.rs b/src/test/ui/abi/abort-on-c-abi.rs similarity index 100% rename from src/test/ui/abort-on-c-abi.rs rename to src/test/ui/abi/abort-on-c-abi.rs diff --git a/src/test/ui/anon-extern-mod.rs b/src/test/ui/abi/anon-extern-mod.rs similarity index 100% rename from src/test/ui/anon-extern-mod.rs rename to src/test/ui/abi/anon-extern-mod.rs diff --git a/src/test/ui/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/ui/abi/auxiliary/anon-extern-mod-cross-crate-1.rs similarity index 100% rename from src/test/ui/auxiliary/anon-extern-mod-cross-crate-1.rs rename to src/test/ui/abi/auxiliary/anon-extern-mod-cross-crate-1.rs diff --git a/src/test/ui/auxiliary/foreign_lib.rs b/src/test/ui/abi/auxiliary/foreign_lib.rs similarity index 100% rename from src/test/ui/auxiliary/foreign_lib.rs rename to src/test/ui/abi/auxiliary/foreign_lib.rs diff --git a/src/test/ui/c-stack-as-value.rs b/src/test/ui/abi/c-stack-as-value.rs similarity index 100% rename from src/test/ui/c-stack-as-value.rs rename to src/test/ui/abi/c-stack-as-value.rs diff --git a/src/test/ui/cabi-int-widening.rs b/src/test/ui/abi/cabi-int-widening.rs similarity index 100% rename from src/test/ui/cabi-int-widening.rs rename to src/test/ui/abi/cabi-int-widening.rs diff --git a/src/test/ui/consts/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/ui/abi/consts/auxiliary/anon-extern-mod-cross-crate-1.rs similarity index 100% rename from src/test/ui/consts/auxiliary/anon-extern-mod-cross-crate-1.rs rename to src/test/ui/abi/consts/auxiliary/anon-extern-mod-cross-crate-1.rs diff --git a/src/test/ui/cross-crate/anon-extern-mod-cross-crate-2.rs b/src/test/ui/abi/cross-crate/anon-extern-mod-cross-crate-2.rs similarity index 100% rename from src/test/ui/cross-crate/anon-extern-mod-cross-crate-2.rs rename to src/test/ui/abi/cross-crate/anon-extern-mod-cross-crate-2.rs diff --git a/src/test/ui/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/ui/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs similarity index 100% rename from src/test/ui/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs rename to src/test/ui/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs diff --git a/src/test/ui/duplicated-external-mods.rs b/src/test/ui/abi/duplicated-external-mods.rs similarity index 100% rename from src/test/ui/duplicated-external-mods.rs rename to src/test/ui/abi/duplicated-external-mods.rs diff --git a/src/test/ui/extern/auxiliary/extern-crosscrate-source.rs b/src/test/ui/abi/extern/auxiliary/extern-crosscrate-source.rs similarity index 100% rename from src/test/ui/extern/auxiliary/extern-crosscrate-source.rs rename to src/test/ui/abi/extern/auxiliary/extern-crosscrate-source.rs diff --git a/src/test/ui/extern/extern-call-deep.rs b/src/test/ui/abi/extern/extern-call-deep.rs similarity index 100% rename from src/test/ui/extern/extern-call-deep.rs rename to src/test/ui/abi/extern/extern-call-deep.rs diff --git a/src/test/ui/extern/extern-call-deep2.rs b/src/test/ui/abi/extern/extern-call-deep2.rs similarity index 100% rename from src/test/ui/extern/extern-call-deep2.rs rename to src/test/ui/abi/extern/extern-call-deep2.rs diff --git a/src/test/ui/extern/extern-call-direct.rs b/src/test/ui/abi/extern/extern-call-direct.rs similarity index 100% rename from src/test/ui/extern/extern-call-direct.rs rename to src/test/ui/abi/extern/extern-call-direct.rs diff --git a/src/test/ui/extern/extern-call-indirect.rs b/src/test/ui/abi/extern/extern-call-indirect.rs similarity index 100% rename from src/test/ui/extern/extern-call-indirect.rs rename to src/test/ui/abi/extern/extern-call-indirect.rs diff --git a/src/test/ui/extern/extern-call-scrub.rs b/src/test/ui/abi/extern/extern-call-scrub.rs similarity index 100% rename from src/test/ui/extern/extern-call-scrub.rs rename to src/test/ui/abi/extern/extern-call-scrub.rs diff --git a/src/test/ui/extern/extern-crosscrate.rs b/src/test/ui/abi/extern/extern-crosscrate.rs similarity index 100% rename from src/test/ui/extern/extern-crosscrate.rs rename to src/test/ui/abi/extern/extern-crosscrate.rs diff --git a/src/test/ui/extern/extern-pass-TwoU16s.rs b/src/test/ui/abi/extern/extern-pass-TwoU16s.rs similarity index 100% rename from src/test/ui/extern/extern-pass-TwoU16s.rs rename to src/test/ui/abi/extern/extern-pass-TwoU16s.rs diff --git a/src/test/ui/extern/extern-pass-TwoU32s.rs b/src/test/ui/abi/extern/extern-pass-TwoU32s.rs similarity index 100% rename from src/test/ui/extern/extern-pass-TwoU32s.rs rename to src/test/ui/abi/extern/extern-pass-TwoU32s.rs diff --git a/src/test/ui/extern/extern-pass-TwoU64s.rs b/src/test/ui/abi/extern/extern-pass-TwoU64s.rs similarity index 100% rename from src/test/ui/extern/extern-pass-TwoU64s.rs rename to src/test/ui/abi/extern/extern-pass-TwoU64s.rs diff --git a/src/test/ui/extern/extern-pass-TwoU8s.rs b/src/test/ui/abi/extern/extern-pass-TwoU8s.rs similarity index 100% rename from src/test/ui/extern/extern-pass-TwoU8s.rs rename to src/test/ui/abi/extern/extern-pass-TwoU8s.rs diff --git a/src/test/ui/extern/extern-pass-char.rs b/src/test/ui/abi/extern/extern-pass-char.rs similarity index 100% rename from src/test/ui/extern/extern-pass-char.rs rename to src/test/ui/abi/extern/extern-pass-char.rs diff --git a/src/test/ui/extern/extern-pass-double.rs b/src/test/ui/abi/extern/extern-pass-double.rs similarity index 100% rename from src/test/ui/extern/extern-pass-double.rs rename to src/test/ui/abi/extern/extern-pass-double.rs diff --git a/src/test/ui/extern/extern-pass-empty.rs b/src/test/ui/abi/extern/extern-pass-empty.rs similarity index 100% rename from src/test/ui/extern/extern-pass-empty.rs rename to src/test/ui/abi/extern/extern-pass-empty.rs diff --git a/src/test/ui/extern/extern-pass-u32.rs b/src/test/ui/abi/extern/extern-pass-u32.rs similarity index 100% rename from src/test/ui/extern/extern-pass-u32.rs rename to src/test/ui/abi/extern/extern-pass-u32.rs diff --git a/src/test/ui/extern/extern-pass-u64.rs b/src/test/ui/abi/extern/extern-pass-u64.rs similarity index 100% rename from src/test/ui/extern/extern-pass-u64.rs rename to src/test/ui/abi/extern/extern-pass-u64.rs diff --git a/src/test/ui/extern/extern-return-TwoU16s.rs b/src/test/ui/abi/extern/extern-return-TwoU16s.rs similarity index 100% rename from src/test/ui/extern/extern-return-TwoU16s.rs rename to src/test/ui/abi/extern/extern-return-TwoU16s.rs diff --git a/src/test/ui/extern/extern-return-TwoU32s.rs b/src/test/ui/abi/extern/extern-return-TwoU32s.rs similarity index 100% rename from src/test/ui/extern/extern-return-TwoU32s.rs rename to src/test/ui/abi/extern/extern-return-TwoU32s.rs diff --git a/src/test/ui/extern/extern-return-TwoU64s.rs b/src/test/ui/abi/extern/extern-return-TwoU64s.rs similarity index 100% rename from src/test/ui/extern/extern-return-TwoU64s.rs rename to src/test/ui/abi/extern/extern-return-TwoU64s.rs diff --git a/src/test/ui/extern/extern-return-TwoU8s.rs b/src/test/ui/abi/extern/extern-return-TwoU8s.rs similarity index 100% rename from src/test/ui/extern/extern-return-TwoU8s.rs rename to src/test/ui/abi/extern/extern-return-TwoU8s.rs diff --git a/src/test/ui/foreign/auxiliary/foreign_lib.rs b/src/test/ui/abi/foreign/auxiliary/foreign_lib.rs similarity index 100% rename from src/test/ui/foreign/auxiliary/foreign_lib.rs rename to src/test/ui/abi/foreign/auxiliary/foreign_lib.rs diff --git a/src/test/ui/foreign/foreign-call-no-runtime.rs b/src/test/ui/abi/foreign/foreign-call-no-runtime.rs similarity index 100% rename from src/test/ui/foreign/foreign-call-no-runtime.rs rename to src/test/ui/abi/foreign/foreign-call-no-runtime.rs diff --git a/src/test/ui/foreign/foreign-dupe.rs b/src/test/ui/abi/foreign/foreign-dupe.rs similarity index 100% rename from src/test/ui/foreign/foreign-dupe.rs rename to src/test/ui/abi/foreign/foreign-dupe.rs diff --git a/src/test/ui/foreign/foreign-fn-with-byval.rs b/src/test/ui/abi/foreign/foreign-fn-with-byval.rs similarity index 100% rename from src/test/ui/foreign/foreign-fn-with-byval.rs rename to src/test/ui/abi/foreign/foreign-fn-with-byval.rs diff --git a/src/test/ui/foreign/foreign-no-abi.rs b/src/test/ui/abi/foreign/foreign-no-abi.rs similarity index 100% rename from src/test/ui/foreign/foreign-no-abi.rs rename to src/test/ui/abi/foreign/foreign-no-abi.rs diff --git a/src/test/ui/invoke-external-foreign.rs b/src/test/ui/abi/invoke-external-foreign.rs similarity index 100% rename from src/test/ui/invoke-external-foreign.rs rename to src/test/ui/abi/invoke-external-foreign.rs diff --git a/src/test/ui/lib-defaults.rs b/src/test/ui/abi/lib-defaults.rs similarity index 100% rename from src/test/ui/lib-defaults.rs rename to src/test/ui/abi/lib-defaults.rs diff --git a/src/test/ui/macros/macros-in-extern.rs b/src/test/ui/abi/macros/macros-in-extern.rs similarity index 100% rename from src/test/ui/macros/macros-in-extern.rs rename to src/test/ui/abi/macros/macros-in-extern.rs diff --git a/src/test/ui/macros/macros-in-extern.stderr b/src/test/ui/abi/macros/macros-in-extern.stderr similarity index 100% rename from src/test/ui/macros/macros-in-extern.stderr rename to src/test/ui/abi/macros/macros-in-extern.stderr diff --git a/src/test/ui/mir/mir_codegen_calls_variadic.rs b/src/test/ui/abi/mir/mir_codegen_calls_variadic.rs similarity index 100% rename from src/test/ui/mir/mir_codegen_calls_variadic.rs rename to src/test/ui/abi/mir/mir_codegen_calls_variadic.rs diff --git a/src/test/ui/numbers-arithmetic/i128-ffi.rs b/src/test/ui/abi/numbers-arithmetic/i128-ffi.rs similarity index 100% rename from src/test/ui/numbers-arithmetic/i128-ffi.rs rename to src/test/ui/abi/numbers-arithmetic/i128-ffi.rs diff --git a/src/test/ui/proc-macro/auxiliary/test-macros.rs b/src/test/ui/abi/proc-macro/auxiliary/test-macros.rs similarity index 100% rename from src/test/ui/proc-macro/auxiliary/test-macros.rs rename to src/test/ui/abi/proc-macro/auxiliary/test-macros.rs diff --git a/src/test/ui/proc-macro/macros-in-extern.rs b/src/test/ui/abi/proc-macro/macros-in-extern.rs similarity index 100% rename from src/test/ui/proc-macro/macros-in-extern.rs rename to src/test/ui/abi/proc-macro/macros-in-extern.rs diff --git a/src/test/ui/proc-macro/macros-in-extern.stderr b/src/test/ui/abi/proc-macro/macros-in-extern.stderr similarity index 100% rename from src/test/ui/proc-macro/macros-in-extern.stderr rename to src/test/ui/abi/proc-macro/macros-in-extern.stderr diff --git a/src/test/ui/segfault-no-out-of-stack.rs b/src/test/ui/abi/segfault-no-out-of-stack.rs similarity index 100% rename from src/test/ui/segfault-no-out-of-stack.rs rename to src/test/ui/abi/segfault-no-out-of-stack.rs diff --git a/src/test/ui/stack-probes-lto.rs b/src/test/ui/abi/stack-probes-lto.rs similarity index 100% rename from src/test/ui/stack-probes-lto.rs rename to src/test/ui/abi/stack-probes-lto.rs diff --git a/src/test/ui/stack-probes.rs b/src/test/ui/abi/stack-probes.rs similarity index 100% rename from src/test/ui/stack-probes.rs rename to src/test/ui/abi/stack-probes.rs diff --git a/src/test/ui/statics/static-mut-foreign.rs b/src/test/ui/abi/statics/static-mut-foreign.rs similarity index 100% rename from src/test/ui/statics/static-mut-foreign.rs rename to src/test/ui/abi/statics/static-mut-foreign.rs diff --git a/src/test/ui/structs-enums/struct-return.rs b/src/test/ui/abi/struct-enums/struct-return.rs similarity index 100% rename from src/test/ui/structs-enums/struct-return.rs rename to src/test/ui/abi/struct-enums/struct-return.rs diff --git a/src/test/ui/union/union-c-interop.rs b/src/test/ui/abi/union/union-c-interop.rs similarity index 100% rename from src/test/ui/union/union-c-interop.rs rename to src/test/ui/abi/union/union-c-interop.rs diff --git a/src/test/ui/variadic-ffi.rs b/src/test/ui/abi/variadic-ffi.rs similarity index 100% rename from src/test/ui/variadic-ffi.rs rename to src/test/ui/abi/variadic-ffi.rs From a90d0876d17c8ce3cb903c867acd70cb8379de60 Mon Sep 17 00:00:00 2001 From: Kevin Per Date: Thu, 15 Aug 2019 17:05:49 +0200 Subject: [PATCH 5/7] Move `test-macros.rs` back to `ui` to fix tests #62593 --- src/test/ui/{abi => }/proc-macro/auxiliary/test-macros.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/test/ui/{abi => }/proc-macro/auxiliary/test-macros.rs (100%) diff --git a/src/test/ui/abi/proc-macro/auxiliary/test-macros.rs b/src/test/ui/proc-macro/auxiliary/test-macros.rs similarity index 100% rename from src/test/ui/abi/proc-macro/auxiliary/test-macros.rs rename to src/test/ui/proc-macro/auxiliary/test-macros.rs From 4a8ff5bb7c31c90a5be3e4d6a2e7e7211b4c8745 Mon Sep 17 00:00:00 2001 From: Kevin Per Date: Thu, 15 Aug 2019 17:07:38 +0200 Subject: [PATCH 6/7] Remove `run-pass` directory #62593 --- .../run-pass/abi/abi-sysv64-arg-passing.rs | 366 ------------------ .../run-pass/abi/abi-sysv64-register-usage.rs | 95 ----- src/test/run-pass/abi/abort-on-c-abi.rs | 36 -- src/test/run-pass/abi/anon-extern-mod.rs | 17 - .../anon-extern-mod-cross-crate-1.rs | 9 - .../run-pass/abi/auxiliary/foreign_lib.rs | 38 -- src/test/run-pass/abi/c-stack-as-value.rs | 17 - src/test/run-pass/abi/cabi-int-widening.rs | 14 - .../anon-extern-mod-cross-crate-1.rs | 9 - .../anon-extern-mod-cross-crate-2.rs | 14 - .../anon-extern-mod-cross-crate-1.rs | 9 - .../run-pass/abi/duplicated-external-mods.rs | 8 - .../auxiliary/extern-crosscrate-source.rs | 31 -- .../run-pass/abi/extern/extern-call-deep.rs | 39 -- .../run-pass/abi/extern/extern-call-deep2.rs | 44 --- .../abi/extern/extern-call-indirect.rs | 38 -- .../run-pass/abi/extern/extern-call-scrub.rs | 48 --- .../run-pass/abi/extern/extern-crosscrate.rs | 21 - .../abi/extern/extern-pass-TwoU16s.rs | 25 -- .../abi/extern/extern-pass-TwoU32s.rs | 25 -- .../abi/extern/extern-pass-TwoU64s.rs | 25 -- .../run-pass/abi/extern/extern-pass-TwoU8s.rs | 25 -- .../run-pass/abi/extern/extern-pass-char.rs | 16 - .../run-pass/abi/extern/extern-pass-double.rs | 13 - .../run-pass/abi/extern/extern-pass-empty.rs | 55 --- .../run-pass/abi/extern/extern-pass-u32.rs | 16 - .../run-pass/abi/extern/extern-pass-u64.rs | 16 - .../abi/extern/extern-return-TwoU16s.rs | 21 - .../abi/extern/extern-return-TwoU32s.rs | 21 - .../abi/extern/extern-return-TwoU64s.rs | 21 - .../abi/extern/extern-return-TwoU8s.rs | 21 - .../abi/foreign/auxiliary/foreign_lib.rs | 38 -- .../abi/foreign/foreign-call-no-runtime.rs | 55 --- src/test/run-pass/abi/foreign/foreign-dupe.rs | 17 - .../abi/foreign/foreign-fn-with-byval.rs | 32 -- .../run-pass/abi/foreign/foreign-no-abi.rs | 22 -- .../run-pass/abi/invoke-external-foreign.rs | 16 - .../abi/issues/auxiliary/issue-25185-1.rs | 8 - .../abi/issues/auxiliary/issue-25185-2.rs | 3 - src/test/run-pass/abi/issues/issue-25185.rs | 13 - src/test/run-pass/abi/issues/issue-28676.rs | 35 -- src/test/run-pass/abi/lib-defaults.rs | 16 - .../run-pass/abi/macros/macros-in-extern.rs | 30 -- .../abi/mir/mir_codegen_calls_variadic.rs | 22 -- .../abi/numbers-arithmetic/i128-ffi.rs | 31 -- .../abi/proc_macro/auxiliary/test-macros.rs | 26 -- .../abi/proc_macro/macros-in-extern.rs | 24 -- .../abi/rfcs/rfc1717/library-override.rs | 14 - .../run-pass/abi/segfault-no-out-of-stack.rs | 48 --- src/test/run-pass/abi/stack-probes-lto.rs | 18 - src/test/run-pass/abi/stack-probes.rs | 67 ---- .../abi/statics/static-mut-foreign.rs | 41 -- .../abi/structs-enums/struct-return.rs | 64 --- .../run-pass/abi/union/union-c-interop.rs | 37 -- src/test/run-pass/abi/variadic-ffi.rs | 83 ---- 55 files changed, 1913 deletions(-) delete mode 100644 src/test/run-pass/abi/abi-sysv64-arg-passing.rs delete mode 100644 src/test/run-pass/abi/abi-sysv64-register-usage.rs delete mode 100644 src/test/run-pass/abi/abort-on-c-abi.rs delete mode 100644 src/test/run-pass/abi/anon-extern-mod.rs delete mode 100644 src/test/run-pass/abi/auxiliary/anon-extern-mod-cross-crate-1.rs delete mode 100644 src/test/run-pass/abi/auxiliary/foreign_lib.rs delete mode 100644 src/test/run-pass/abi/c-stack-as-value.rs delete mode 100644 src/test/run-pass/abi/cabi-int-widening.rs delete mode 100644 src/test/run-pass/abi/consts/auxiliary/anon-extern-mod-cross-crate-1.rs delete mode 100644 src/test/run-pass/abi/cross-crate/anon-extern-mod-cross-crate-2.rs delete mode 100644 src/test/run-pass/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs delete mode 100644 src/test/run-pass/abi/duplicated-external-mods.rs delete mode 100644 src/test/run-pass/abi/extern/auxiliary/extern-crosscrate-source.rs delete mode 100644 src/test/run-pass/abi/extern/extern-call-deep.rs delete mode 100644 src/test/run-pass/abi/extern/extern-call-deep2.rs delete mode 100644 src/test/run-pass/abi/extern/extern-call-indirect.rs delete mode 100644 src/test/run-pass/abi/extern/extern-call-scrub.rs delete mode 100644 src/test/run-pass/abi/extern/extern-crosscrate.rs delete mode 100644 src/test/run-pass/abi/extern/extern-pass-TwoU16s.rs delete mode 100644 src/test/run-pass/abi/extern/extern-pass-TwoU32s.rs delete mode 100644 src/test/run-pass/abi/extern/extern-pass-TwoU64s.rs delete mode 100644 src/test/run-pass/abi/extern/extern-pass-TwoU8s.rs delete mode 100644 src/test/run-pass/abi/extern/extern-pass-char.rs delete mode 100644 src/test/run-pass/abi/extern/extern-pass-double.rs delete mode 100644 src/test/run-pass/abi/extern/extern-pass-empty.rs delete mode 100644 src/test/run-pass/abi/extern/extern-pass-u32.rs delete mode 100644 src/test/run-pass/abi/extern/extern-pass-u64.rs delete mode 100644 src/test/run-pass/abi/extern/extern-return-TwoU16s.rs delete mode 100644 src/test/run-pass/abi/extern/extern-return-TwoU32s.rs delete mode 100644 src/test/run-pass/abi/extern/extern-return-TwoU64s.rs delete mode 100644 src/test/run-pass/abi/extern/extern-return-TwoU8s.rs delete mode 100644 src/test/run-pass/abi/foreign/auxiliary/foreign_lib.rs delete mode 100644 src/test/run-pass/abi/foreign/foreign-call-no-runtime.rs delete mode 100644 src/test/run-pass/abi/foreign/foreign-dupe.rs delete mode 100644 src/test/run-pass/abi/foreign/foreign-fn-with-byval.rs delete mode 100644 src/test/run-pass/abi/foreign/foreign-no-abi.rs delete mode 100644 src/test/run-pass/abi/invoke-external-foreign.rs delete mode 100644 src/test/run-pass/abi/issues/auxiliary/issue-25185-1.rs delete mode 100644 src/test/run-pass/abi/issues/auxiliary/issue-25185-2.rs delete mode 100644 src/test/run-pass/abi/issues/issue-25185.rs delete mode 100644 src/test/run-pass/abi/issues/issue-28676.rs delete mode 100644 src/test/run-pass/abi/lib-defaults.rs delete mode 100644 src/test/run-pass/abi/macros/macros-in-extern.rs delete mode 100644 src/test/run-pass/abi/mir/mir_codegen_calls_variadic.rs delete mode 100644 src/test/run-pass/abi/numbers-arithmetic/i128-ffi.rs delete mode 100644 src/test/run-pass/abi/proc_macro/auxiliary/test-macros.rs delete mode 100644 src/test/run-pass/abi/proc_macro/macros-in-extern.rs delete mode 100644 src/test/run-pass/abi/rfcs/rfc1717/library-override.rs delete mode 100644 src/test/run-pass/abi/segfault-no-out-of-stack.rs delete mode 100644 src/test/run-pass/abi/stack-probes-lto.rs delete mode 100644 src/test/run-pass/abi/stack-probes.rs delete mode 100644 src/test/run-pass/abi/statics/static-mut-foreign.rs delete mode 100644 src/test/run-pass/abi/structs-enums/struct-return.rs delete mode 100644 src/test/run-pass/abi/union/union-c-interop.rs delete mode 100644 src/test/run-pass/abi/variadic-ffi.rs diff --git a/src/test/run-pass/abi/abi-sysv64-arg-passing.rs b/src/test/run-pass/abi/abi-sysv64-arg-passing.rs deleted file mode 100644 index fdf0573b5e3..00000000000 --- a/src/test/run-pass/abi/abi-sysv64-arg-passing.rs +++ /dev/null @@ -1,366 +0,0 @@ -// Checks if the "sysv64" calling convention behaves the same as the -// "C" calling convention on platforms where both should be the same - -// This file contains versions of the following run-pass tests with -// the calling convention changed to "sysv64" - -// cabi-int-widening -// extern-pass-char -// extern-pass-u32 -// extern-pass-u64 -// extern-pass-double -// extern-pass-empty -// extern-pass-TwoU8s -// extern-pass-TwoU16s -// extern-pass-TwoU32s -// extern-pass-TwoU64s -// extern-return-TwoU8s -// extern-return-TwoU16s -// extern-return-TwoU32s -// extern-return-TwoU64s -// foreign-fn-with-byval -// issue-28676 -// issue-62350-sysv-neg-reg-counts -// struct-return - -// ignore-android -// ignore-arm -// ignore-aarch64 -// ignore-windows - -// note: windows is ignored as rust_test_helpers does not have the sysv64 abi on windows - -#[allow(dead_code)] -#[allow(improper_ctypes)] - -#[cfg(target_arch = "x86_64")] -mod tests { - #[repr(C)] - #[derive(Copy, Clone, PartialEq, Debug)] - pub struct TwoU8s { - one: u8, two: u8 - } - - #[repr(C)] - #[derive(Copy, Clone, PartialEq, Debug)] - pub struct TwoU16s { - one: u16, two: u16 - } - - #[repr(C)] - #[derive(Copy, Clone, PartialEq, Debug)] - pub struct TwoU32s { - one: u32, two: u32 - } - - #[repr(C)] - #[derive(Copy, Clone, PartialEq, Debug)] - pub struct TwoU64s { - one: u64, two: u64 - } - - #[repr(C)] - pub struct ManyInts { - arg1: i8, - arg2: i16, - arg3: i32, - arg4: i16, - arg5: i8, - arg6: TwoU8s, - } - - #[repr(C)] - pub struct Empty; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct S { - x: u64, - y: u64, - z: u64, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct Quad { a: u64, b: u64, c: u64, d: u64 } - - #[derive(Copy, Clone)] - pub struct QuadFloats { a: f32, b: f32, c: f32, d: f32 } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct Floats { a: f64, b: u8, c: f64 } - - #[link(name = "rust_test_helpers", kind = "static")] - extern "sysv64" { - pub fn rust_int8_to_int32(_: i8) -> i32; - pub fn rust_dbg_extern_identity_u8(v: u8) -> u8; - pub fn rust_dbg_extern_identity_u32(v: u32) -> u32; - pub fn rust_dbg_extern_identity_u64(v: u64) -> u64; - pub fn rust_dbg_extern_identity_double(v: f64) -> f64; - pub fn rust_dbg_extern_empty_struct(v1: ManyInts, e: Empty, v2: ManyInts); - pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s; - pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s; - pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s; - pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s; - pub fn rust_dbg_extern_return_TwoU8s() -> TwoU8s; - pub fn rust_dbg_extern_return_TwoU16s() -> TwoU16s; - pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s; - pub fn rust_dbg_extern_return_TwoU64s() -> TwoU64s; - pub fn get_x(x: S) -> u64; - pub fn get_y(x: S) -> u64; - pub fn get_z(x: S) -> u64; - pub fn get_c_many_params(_: *const (), _: *const (), - _: *const (), _: *const (), f: Quad) -> u64; - pub fn get_c_exhaust_sysv64_ints( - _: *const (), - _: *const (), - _: *const (), - _: *const (), - _: *const (), - _: *const (), - _: *const (), - h: QuadFloats, - ) -> f32; - pub fn rust_dbg_abi_1(q: Quad) -> Quad; - pub fn rust_dbg_abi_2(f: Floats) -> Floats; - } - - pub fn cabi_int_widening() { - let x = unsafe { - rust_int8_to_int32(-1) - }; - - assert!(x == -1); - } - - pub fn extern_pass_char() { - unsafe { - assert_eq!(22, rust_dbg_extern_identity_u8(22)); - } - } - - pub fn extern_pass_u32() { - unsafe { - assert_eq!(22, rust_dbg_extern_identity_u32(22)); - } - } - - pub fn extern_pass_u64() { - unsafe { - assert_eq!(22, rust_dbg_extern_identity_u64(22)); - } - } - - pub fn extern_pass_double() { - unsafe { - assert_eq!(22.0_f64, rust_dbg_extern_identity_double(22.0_f64)); - } - } - - pub fn extern_pass_empty() { - unsafe { - let x = ManyInts { - arg1: 2, - arg2: 3, - arg3: 4, - arg4: 5, - arg5: 6, - arg6: TwoU8s { one: 7, two: 8, } - }; - let y = ManyInts { - arg1: 1, - arg2: 2, - arg3: 3, - arg4: 4, - arg5: 5, - arg6: TwoU8s { one: 6, two: 7, } - }; - let empty = Empty; - rust_dbg_extern_empty_struct(x, empty, y); - } - } - - pub fn extern_pass_twou8s() { - unsafe { - let x = TwoU8s {one: 22, two: 23}; - let y = rust_dbg_extern_identity_TwoU8s(x); - assert_eq!(x, y); - } - } - - pub fn extern_pass_twou16s() { - unsafe { - let x = TwoU16s {one: 22, two: 23}; - let y = rust_dbg_extern_identity_TwoU16s(x); - assert_eq!(x, y); - } - } - - pub fn extern_pass_twou32s() { - unsafe { - let x = TwoU32s {one: 22, two: 23}; - let y = rust_dbg_extern_identity_TwoU32s(x); - assert_eq!(x, y); - } - } - - pub fn extern_pass_twou64s() { - unsafe { - let x = TwoU64s {one: 22, two: 23}; - let y = rust_dbg_extern_identity_TwoU64s(x); - assert_eq!(x, y); - } - } - - pub fn extern_return_twou8s() { - unsafe { - let y = rust_dbg_extern_return_TwoU8s(); - assert_eq!(y.one, 10); - assert_eq!(y.two, 20); - } - } - - pub fn extern_return_twou16s() { - unsafe { - let y = rust_dbg_extern_return_TwoU16s(); - assert_eq!(y.one, 10); - assert_eq!(y.two, 20); - } - } - - pub fn extern_return_twou32s() { - unsafe { - let y = rust_dbg_extern_return_TwoU32s(); - assert_eq!(y.one, 10); - assert_eq!(y.two, 20); - } - } - - pub fn extern_return_twou64s() { - unsafe { - let y = rust_dbg_extern_return_TwoU64s(); - assert_eq!(y.one, 10); - assert_eq!(y.two, 20); - } - } - - #[inline(never)] - fn indirect_call(func: unsafe extern "sysv64" fn(s: S) -> u64, s: S) -> u64 { - unsafe { - func(s) - } - } - - pub fn foreign_fn_with_byval() { - let s = S { x: 1, y: 2, z: 3 }; - assert_eq!(s.x, indirect_call(get_x, s)); - assert_eq!(s.y, indirect_call(get_y, s)); - assert_eq!(s.z, indirect_call(get_z, s)); - } - - fn test() { - use std::ptr; - unsafe { - let null = ptr::null(); - let q = Quad { - a: 1, - b: 2, - c: 3, - d: 4 - }; - assert_eq!(get_c_many_params(null, null, null, null, q), q.c); - } - } - - pub fn issue_28676() { - test(); - } - - fn test_62350() { - use std::ptr; - unsafe { - let null = ptr::null(); - let q = QuadFloats { - a: 10.2, - b: 20.3, - c: 30.4, - d: 40.5 - }; - assert_eq!( - get_c_exhaust_sysv64_ints(null, null, null, null, null, null, null, q), - q.c, - ); - } - } - - pub fn issue_62350() { - test_62350(); - } - - fn test1() { - unsafe { - let q = Quad { a: 0xaaaa_aaaa_aaaa_aaaa, - b: 0xbbbb_bbbb_bbbb_bbbb, - c: 0xcccc_cccc_cccc_cccc, - d: 0xdddd_dddd_dddd_dddd }; - let qq = rust_dbg_abi_1(q); - println!("a: {:x}", qq.a as usize); - println!("b: {:x}", qq.b as usize); - println!("c: {:x}", qq.c as usize); - println!("d: {:x}", qq.d as usize); - assert_eq!(qq.a, q.c + 1); - assert_eq!(qq.b, q.d - 1); - assert_eq!(qq.c, q.a + 1); - assert_eq!(qq.d, q.b - 1); - } - } - - fn test2() { - unsafe { - let f = Floats { a: 1.234567890e-15_f64, - b: 0b_1010_1010, - c: 1.0987654321e-15_f64 }; - let ff = rust_dbg_abi_2(f); - println!("a: {}", ff.a as f64); - println!("b: {}", ff.b as usize); - println!("c: {}", ff.c as f64); - assert_eq!(ff.a, f.c + 1.0f64); - assert_eq!(ff.b, 0xff); - assert_eq!(ff.c, f.a - 1.0f64); - } - } - - pub fn struct_return() { - test1(); - test2(); - } -} - -#[cfg(target_arch = "x86_64")] -fn main() { - use tests::*; - cabi_int_widening(); - extern_pass_char(); - extern_pass_u32(); - extern_pass_u64(); - extern_pass_double(); - extern_pass_empty(); - extern_pass_twou8s(); - extern_pass_twou16s(); - extern_pass_twou32s(); - extern_pass_twou64s(); - extern_return_twou8s(); - extern_return_twou16s(); - extern_return_twou32s(); - extern_return_twou64s(); - foreign_fn_with_byval(); - issue_28676(); - issue_62350(); - struct_return(); -} - -#[cfg(not(target_arch = "x86_64"))] -fn main() { - -} diff --git a/src/test/run-pass/abi/abi-sysv64-register-usage.rs b/src/test/run-pass/abi/abi-sysv64-register-usage.rs deleted file mode 100644 index a0d6e968252..00000000000 --- a/src/test/run-pass/abi/abi-sysv64-register-usage.rs +++ /dev/null @@ -1,95 +0,0 @@ -// Checks if the correct registers are being used to pass arguments -// when the sysv64 ABI is specified. - -// ignore-android -// ignore-arm -// ignore-aarch64 - -#![feature(asm)] - -#[cfg(target_arch = "x86_64")] -pub extern "sysv64" fn all_the_registers(rdi: i64, rsi: i64, rdx: i64, - rcx: i64, r8 : i64, r9 : i64, - xmm0: f32, xmm1: f32, xmm2: f32, - xmm3: f32, xmm4: f32, xmm5: f32, - xmm6: f32, xmm7: f32) -> i64 { - assert_eq!(rdi, 1); - assert_eq!(rsi, 2); - assert_eq!(rdx, 3); - assert_eq!(rcx, 4); - assert_eq!(r8, 5); - assert_eq!(r9, 6); - assert_eq!(xmm0, 1.0f32); - assert_eq!(xmm1, 2.0f32); - assert_eq!(xmm2, 4.0f32); - assert_eq!(xmm3, 8.0f32); - assert_eq!(xmm4, 16.0f32); - assert_eq!(xmm5, 32.0f32); - assert_eq!(xmm6, 64.0f32); - assert_eq!(xmm7, 128.0f32); - 42 -} - -// this struct contains 8 i64's, while only 6 can be passed in registers. -#[cfg(target_arch = "x86_64")] -#[derive(PartialEq, Eq, Debug)] -pub struct LargeStruct(i64, i64, i64, i64, i64, i64, i64, i64); - -#[cfg(target_arch = "x86_64")] -#[inline(never)] -pub extern "sysv64" fn large_struct_by_val(mut foo: LargeStruct) -> LargeStruct { - foo.0 *= 1; - foo.1 *= 2; - foo.2 *= 3; - foo.3 *= 4; - foo.4 *= 5; - foo.5 *= 6; - foo.6 *= 7; - foo.7 *= 8; - foo -} - -#[cfg(target_arch = "x86_64")] -pub fn main() { - let result: i64; - unsafe { - asm!("mov rdi, 1; - mov rsi, 2; - mov rdx, 3; - mov rcx, 4; - mov r8, 5; - mov r9, 6; - mov eax, 0x3F800000; - movd xmm0, eax; - mov eax, 0x40000000; - movd xmm1, eax; - mov eax, 0x40800000; - movd xmm2, eax; - mov eax, 0x41000000; - movd xmm3, eax; - mov eax, 0x41800000; - movd xmm4, eax; - mov eax, 0x42000000; - movd xmm5, eax; - mov eax, 0x42800000; - movd xmm6, eax; - mov eax, 0x43000000; - movd xmm7, eax; - call r10 - " - : "={rax}"(result) - : "{r10}"(all_the_registers as usize) - : "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r11", "cc", "memory" - : "intel", "alignstack" - ) - } - assert_eq!(result, 42); - - assert_eq!( - large_struct_by_val(LargeStruct(1, 2, 3, 4, 5, 6, 7, 8)), - LargeStruct(1, 4, 9, 16, 25, 36, 49, 64) - ); -} - -#[cfg(not(target_arch = "x86_64"))] -pub fn main() {} diff --git a/src/test/run-pass/abi/abort-on-c-abi.rs b/src/test/run-pass/abi/abort-on-c-abi.rs deleted file mode 100644 index 110f3eee1ef..00000000000 --- a/src/test/run-pass/abi/abort-on-c-abi.rs +++ /dev/null @@ -1,36 +0,0 @@ -#![allow(unused_must_use)] -// Since we mark some ABIs as "nounwind" to LLVM, we must make sure that -// we never unwind through them. - -// ignore-cloudabi no env and process -// ignore-emscripten no processes -// ignore-sgx no processes - -use std::{env, panic}; -use std::io::prelude::*; -use std::io; -use std::process::{Command, Stdio}; - -extern "C" fn panic_in_ffi() { - panic!("Test"); -} - -fn test() { - let _ = panic::catch_unwind(|| { panic_in_ffi(); }); - // The process should have aborted by now. - io::stdout().write(b"This should never be printed.\n"); - let _ = io::stdout().flush(); -} - -fn main() { - let args: Vec = env::args().collect(); - if args.len() > 1 && args[1] == "test" { - return test(); - } - - let mut p = Command::new(&args[0]) - .stdout(Stdio::piped()) - .stdin(Stdio::piped()) - .arg("test").spawn().unwrap(); - assert!(!p.wait().unwrap().success()); -} diff --git a/src/test/run-pass/abi/anon-extern-mod.rs b/src/test/run-pass/abi/anon-extern-mod.rs deleted file mode 100644 index 6d7e3f3cd5c..00000000000 --- a/src/test/run-pass/abi/anon-extern-mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -// pretty-expanded FIXME #23616 -// ignore-wasm32-bare no libc to test ffi with - -#![feature(rustc_private)] - -extern crate libc; - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - fn rust_get_test_int() -> libc::intptr_t; -} - -pub fn main() { - unsafe { - let _ = rust_get_test_int(); - } -} diff --git a/src/test/run-pass/abi/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/run-pass/abi/auxiliary/anon-extern-mod-cross-crate-1.rs deleted file mode 100644 index 948b5e688eb..00000000000 --- a/src/test/run-pass/abi/auxiliary/anon-extern-mod-cross-crate-1.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![crate_name="anonexternmod"] -#![feature(rustc_private)] - -extern crate libc; - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_get_test_int() -> libc::intptr_t; -} diff --git a/src/test/run-pass/abi/auxiliary/foreign_lib.rs b/src/test/run-pass/abi/auxiliary/foreign_lib.rs deleted file mode 100644 index de6b0e2118a..00000000000 --- a/src/test/run-pass/abi/auxiliary/foreign_lib.rs +++ /dev/null @@ -1,38 +0,0 @@ -#![crate_name="foreign_lib"] - -#![feature(rustc_private)] - -pub mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn rust_get_test_int() -> libc::intptr_t; - } -} - -pub mod rustrt2 { - extern crate libc; - - extern { - pub fn rust_get_test_int() -> libc::intptr_t; - } -} - -pub mod rustrt3 { - // Different type, but same ABI (on all supported platforms). - // Ensures that we don't ICE or trigger LLVM asserts when - // importing the same symbol under different types. - // See https://github.com/rust-lang/rust/issues/32740. - extern { - pub fn rust_get_test_int() -> *const u8; - } -} - -pub fn local_uses() { - unsafe { - let x = rustrt::rust_get_test_int(); - assert_eq!(x, rustrt2::rust_get_test_int()); - assert_eq!(x as *const _, rustrt3::rust_get_test_int()); - } -} diff --git a/src/test/run-pass/abi/c-stack-as-value.rs b/src/test/run-pass/abi/c-stack-as-value.rs deleted file mode 100644 index 3b997295c12..00000000000 --- a/src/test/run-pass/abi/c-stack-as-value.rs +++ /dev/null @@ -1,17 +0,0 @@ -// pretty-expanded FIXME #23616 -// ignore-wasm32-bare no libc to test ffi with - -#![feature(rustc_private)] - -mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn rust_get_test_int() -> libc::intptr_t; - } -} - -pub fn main() { - let _foo = rustrt::rust_get_test_int; -} diff --git a/src/test/run-pass/abi/cabi-int-widening.rs b/src/test/run-pass/abi/cabi-int-widening.rs deleted file mode 100644 index f6524c6a3d9..00000000000 --- a/src/test/run-pass/abi/cabi-int-widening.rs +++ /dev/null @@ -1,14 +0,0 @@ -// ignore-wasm32-bare no libc to test ffi with - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - fn rust_int8_to_int32(_: i8) -> i32; -} - -fn main() { - let x = unsafe { - rust_int8_to_int32(-1) - }; - - assert!(x == -1); -} diff --git a/src/test/run-pass/abi/consts/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/run-pass/abi/consts/auxiliary/anon-extern-mod-cross-crate-1.rs deleted file mode 100644 index 948b5e688eb..00000000000 --- a/src/test/run-pass/abi/consts/auxiliary/anon-extern-mod-cross-crate-1.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![crate_name="anonexternmod"] -#![feature(rustc_private)] - -extern crate libc; - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_get_test_int() -> libc::intptr_t; -} diff --git a/src/test/run-pass/abi/cross-crate/anon-extern-mod-cross-crate-2.rs b/src/test/run-pass/abi/cross-crate/anon-extern-mod-cross-crate-2.rs deleted file mode 100644 index 77168be5374..00000000000 --- a/src/test/run-pass/abi/cross-crate/anon-extern-mod-cross-crate-2.rs +++ /dev/null @@ -1,14 +0,0 @@ -// run-pass -// aux-build:anon-extern-mod-cross-crate-1.rs -// pretty-expanded FIXME #23616 -// ignore-wasm32-bare no libc to test ffi with - -extern crate anonexternmod; - -use anonexternmod::rust_get_test_int; - -pub fn main() { - unsafe { - rust_get_test_int(); - } -} diff --git a/src/test/run-pass/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/run-pass/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs deleted file mode 100644 index 948b5e688eb..00000000000 --- a/src/test/run-pass/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![crate_name="anonexternmod"] -#![feature(rustc_private)] - -extern crate libc; - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_get_test_int() -> libc::intptr_t; -} diff --git a/src/test/run-pass/abi/duplicated-external-mods.rs b/src/test/run-pass/abi/duplicated-external-mods.rs deleted file mode 100644 index f2c1e1f6540..00000000000 --- a/src/test/run-pass/abi/duplicated-external-mods.rs +++ /dev/null @@ -1,8 +0,0 @@ -// aux-build:anon-extern-mod-cross-crate-1.rs -// aux-build:anon-extern-mod-cross-crate-1.rs -// pretty-expanded FIXME #23616 -// ignore-wasm32-bare no libc to test ffi with - -extern crate anonexternmod; - -pub fn main() { } diff --git a/src/test/run-pass/abi/extern/auxiliary/extern-crosscrate-source.rs b/src/test/run-pass/abi/extern/auxiliary/extern-crosscrate-source.rs deleted file mode 100644 index d4568d38e25..00000000000 --- a/src/test/run-pass/abi/extern/auxiliary/extern-crosscrate-source.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![crate_name="externcallback"] -#![crate_type = "lib"] -#![feature(rustc_private)] - -extern crate libc; - -pub mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t) - -> libc::uintptr_t; - } -} - -pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t { - unsafe { - println!("n = {}", n); - rustrt::rust_dbg_call(cb, n) - } -} - -pub extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { - if data == 1 { - data - } else { - fact(data - 1) * data - } -} diff --git a/src/test/run-pass/abi/extern/extern-call-deep.rs b/src/test/run-pass/abi/extern/extern-call-deep.rs deleted file mode 100644 index 81f884dada9..00000000000 --- a/src/test/run-pass/abi/extern/extern-call-deep.rs +++ /dev/null @@ -1,39 +0,0 @@ -// run-pass -// ignore-wasm32-bare no libc to test ffi with -// ignore-emscripten blows the JS stack - -#![feature(rustc_private)] - -extern crate libc; - -mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t) - -> libc::uintptr_t; - } -} - -extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { - if data == 1 { - data - } else { - count(data - 1) + 1 - } -} - -fn count(n: libc::uintptr_t) -> libc::uintptr_t { - unsafe { - println!("n = {}", n); - rustrt::rust_dbg_call(cb, n) - } -} - -pub fn main() { - let result = count(1000); - println!("result = {}", result); - assert_eq!(result, 1000); -} diff --git a/src/test/run-pass/abi/extern/extern-call-deep2.rs b/src/test/run-pass/abi/extern/extern-call-deep2.rs deleted file mode 100644 index b31489b1e10..00000000000 --- a/src/test/run-pass/abi/extern/extern-call-deep2.rs +++ /dev/null @@ -1,44 +0,0 @@ -// run-pass -#![allow(unused_must_use)] -// ignore-emscripten no threads support - -#![feature(rustc_private)] - -extern crate libc; -use std::thread; - -mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t) - -> libc::uintptr_t; - } -} - -extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { - if data == 1 { - data - } else { - count(data - 1) + 1 - } -} - -fn count(n: libc::uintptr_t) -> libc::uintptr_t { - unsafe { - println!("n = {}", n); - rustrt::rust_dbg_call(cb, n) - } -} - -pub fn main() { - // Make sure we're on a thread with small Rust stacks (main currently - // has a large stack) - thread::spawn(move|| { - let result = count(1000); - println!("result = {}", result); - assert_eq!(result, 1000); - }).join(); -} diff --git a/src/test/run-pass/abi/extern/extern-call-indirect.rs b/src/test/run-pass/abi/extern/extern-call-indirect.rs deleted file mode 100644 index 158b54e4b8c..00000000000 --- a/src/test/run-pass/abi/extern/extern-call-indirect.rs +++ /dev/null @@ -1,38 +0,0 @@ -// run-pass -// ignore-wasm32-bare no libc to test ffi with - -#![feature(rustc_private)] - -extern crate libc; - -mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t) - -> libc::uintptr_t; - } -} - -extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { - if data == 1 { - data - } else { - fact(data - 1) * data - } -} - -fn fact(n: libc::uintptr_t) -> libc::uintptr_t { - unsafe { - println!("n = {}", n); - rustrt::rust_dbg_call(cb, n) - } -} - -pub fn main() { - let result = fact(10); - println!("result = {}", result); - assert_eq!(result, 3628800); -} diff --git a/src/test/run-pass/abi/extern/extern-call-scrub.rs b/src/test/run-pass/abi/extern/extern-call-scrub.rs deleted file mode 100644 index a7b1065c9e1..00000000000 --- a/src/test/run-pass/abi/extern/extern-call-scrub.rs +++ /dev/null @@ -1,48 +0,0 @@ -// run-pass -#![allow(unused_must_use)] -// This time we're testing repeatedly going up and down both stacks to -// make sure the stack pointers are maintained properly in both -// directions - -// ignore-emscripten no threads support - -#![feature(rustc_private)] - -extern crate libc; -use std::thread; - -mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t) - -> libc::uintptr_t; - } -} - -extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { - if data == 1 { - data - } else { - count(data - 1) + count(data - 1) - } -} - -fn count(n: libc::uintptr_t) -> libc::uintptr_t { - unsafe { - println!("n = {}", n); - rustrt::rust_dbg_call(cb, n) - } -} - -pub fn main() { - // Make sure we're on a thread with small Rust stacks (main currently - // has a large stack) - thread::spawn(move|| { - let result = count(12); - println!("result = {}", result); - assert_eq!(result, 2048); - }).join(); -} diff --git a/src/test/run-pass/abi/extern/extern-crosscrate.rs b/src/test/run-pass/abi/extern/extern-crosscrate.rs deleted file mode 100644 index 123ce20ca26..00000000000 --- a/src/test/run-pass/abi/extern/extern-crosscrate.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-pass -// aux-build:extern-crosscrate-source.rs -// ignore-wasm32-bare no libc to test ffi with - -#![feature(rustc_private)] - -extern crate externcallback; -extern crate libc; - -fn fact(n: libc::uintptr_t) -> libc::uintptr_t { - unsafe { - println!("n = {}", n); - externcallback::rustrt::rust_dbg_call(externcallback::cb, n) - } -} - -pub fn main() { - let result = fact(10); - println!("result = {}", result); - assert_eq!(result, 3628800); -} diff --git a/src/test/run-pass/abi/extern/extern-pass-TwoU16s.rs b/src/test/run-pass/abi/extern/extern-pass-TwoU16s.rs deleted file mode 100644 index 285bce2e19c..00000000000 --- a/src/test/run-pass/abi/extern/extern-pass-TwoU16s.rs +++ /dev/null @@ -1,25 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] - -// ignore-wasm32-bare no libc for ffi testing - -// Test a foreign function that accepts and returns a struct -// by value. - -#[derive(Copy, Clone, PartialEq, Debug)] -pub struct TwoU16s { - one: u16, two: u16 -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s; -} - -pub fn main() { - unsafe { - let x = TwoU16s {one: 22, two: 23}; - let y = rust_dbg_extern_identity_TwoU16s(x); - assert_eq!(x, y); - } -} diff --git a/src/test/run-pass/abi/extern/extern-pass-TwoU32s.rs b/src/test/run-pass/abi/extern/extern-pass-TwoU32s.rs deleted file mode 100644 index fb18aa8d22f..00000000000 --- a/src/test/run-pass/abi/extern/extern-pass-TwoU32s.rs +++ /dev/null @@ -1,25 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] - -// ignore-wasm32-bare no libc for ffi testing - -// Test a foreign function that accepts and returns a struct -// by value. - -#[derive(Copy, Clone, PartialEq, Debug)] -pub struct TwoU32s { - one: u32, two: u32 -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s; -} - -pub fn main() { - unsafe { - let x = TwoU32s {one: 22, two: 23}; - let y = rust_dbg_extern_identity_TwoU32s(x); - assert_eq!(x, y); - } -} diff --git a/src/test/run-pass/abi/extern/extern-pass-TwoU64s.rs b/src/test/run-pass/abi/extern/extern-pass-TwoU64s.rs deleted file mode 100644 index 419648263aa..00000000000 --- a/src/test/run-pass/abi/extern/extern-pass-TwoU64s.rs +++ /dev/null @@ -1,25 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] - -// ignore-wasm32-bare no libc for ffi testing - -// Test a foreign function that accepts and returns a struct -// by value. - -#[derive(Copy, Clone, PartialEq, Debug)] -pub struct TwoU64s { - one: u64, two: u64 -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s; -} - -pub fn main() { - unsafe { - let x = TwoU64s {one: 22, two: 23}; - let y = rust_dbg_extern_identity_TwoU64s(x); - assert_eq!(x, y); - } -} diff --git a/src/test/run-pass/abi/extern/extern-pass-TwoU8s.rs b/src/test/run-pass/abi/extern/extern-pass-TwoU8s.rs deleted file mode 100644 index 53a6a0f29f8..00000000000 --- a/src/test/run-pass/abi/extern/extern-pass-TwoU8s.rs +++ /dev/null @@ -1,25 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] - -// ignore-wasm32-bare no libc for ffi testing - -// Test a foreign function that accepts and returns a struct -// by value. - -#[derive(Copy, Clone, PartialEq, Debug)] -pub struct TwoU8s { - one: u8, two: u8 -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s; -} - -pub fn main() { - unsafe { - let x = TwoU8s {one: 22, two: 23}; - let y = rust_dbg_extern_identity_TwoU8s(x); - assert_eq!(x, y); - } -} diff --git a/src/test/run-pass/abi/extern/extern-pass-char.rs b/src/test/run-pass/abi/extern/extern-pass-char.rs deleted file mode 100644 index 22f841b4552..00000000000 --- a/src/test/run-pass/abi/extern/extern-pass-char.rs +++ /dev/null @@ -1,16 +0,0 @@ -// run-pass -// ignore-wasm32-bare no libc for ffi testing - -// Test a function that takes/returns a u8. - - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_identity_u8(v: u8) -> u8; -} - -pub fn main() { - unsafe { - assert_eq!(22, rust_dbg_extern_identity_u8(22)); - } -} diff --git a/src/test/run-pass/abi/extern/extern-pass-double.rs b/src/test/run-pass/abi/extern/extern-pass-double.rs deleted file mode 100644 index dbd0a2dfa48..00000000000 --- a/src/test/run-pass/abi/extern/extern-pass-double.rs +++ /dev/null @@ -1,13 +0,0 @@ -// run-pass -// ignore-wasm32-bare no libc for ffi testing - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_identity_double(v: f64) -> f64; -} - -pub fn main() { - unsafe { - assert_eq!(22.0_f64, rust_dbg_extern_identity_double(22.0_f64)); - } -} diff --git a/src/test/run-pass/abi/extern/extern-pass-empty.rs b/src/test/run-pass/abi/extern/extern-pass-empty.rs deleted file mode 100644 index 07099a24204..00000000000 --- a/src/test/run-pass/abi/extern/extern-pass-empty.rs +++ /dev/null @@ -1,55 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] // FIXME: this test is inherently not FFI-safe. - -// Test a foreign function that accepts empty struct. - -// pretty-expanded FIXME #23616 -// ignore-msvc -// ignore-emscripten emcc asserts on an empty struct as an argument - -#[repr(C)] -struct TwoU8s { - one: u8, - two: u8, -} - -#[repr(C)] -struct ManyInts { - arg1: i8, - arg2: i16, - arg3: i32, - arg4: i16, - arg5: i8, - arg6: TwoU8s, -} - -#[repr(C)] -struct Empty; - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - fn rust_dbg_extern_empty_struct(v1: ManyInts, e: Empty, v2: ManyInts); -} - -pub fn main() { - unsafe { - let x = ManyInts { - arg1: 2, - arg2: 3, - arg3: 4, - arg4: 5, - arg5: 6, - arg6: TwoU8s { one: 7, two: 8, } - }; - let y = ManyInts { - arg1: 1, - arg2: 2, - arg3: 3, - arg4: 4, - arg5: 5, - arg6: TwoU8s { one: 6, two: 7, } - }; - let empty = Empty; - rust_dbg_extern_empty_struct(x, empty, y); - } -} diff --git a/src/test/run-pass/abi/extern/extern-pass-u32.rs b/src/test/run-pass/abi/extern/extern-pass-u32.rs deleted file mode 100644 index f2efdb7d366..00000000000 --- a/src/test/run-pass/abi/extern/extern-pass-u32.rs +++ /dev/null @@ -1,16 +0,0 @@ -// run-pass -// ignore-wasm32-bare no libc for ffi testing - -// Test a function that takes/returns a u32. - - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_identity_u32(v: u32) -> u32; -} - -pub fn main() { - unsafe { - assert_eq!(22, rust_dbg_extern_identity_u32(22)); - } -} diff --git a/src/test/run-pass/abi/extern/extern-pass-u64.rs b/src/test/run-pass/abi/extern/extern-pass-u64.rs deleted file mode 100644 index 975446d430c..00000000000 --- a/src/test/run-pass/abi/extern/extern-pass-u64.rs +++ /dev/null @@ -1,16 +0,0 @@ -// run-pass -// ignore-wasm32-bare no libc for ffi testing - -// Test a call to a function that takes/returns a u64. - - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_identity_u64(v: u64) -> u64; -} - -pub fn main() { - unsafe { - assert_eq!(22, rust_dbg_extern_identity_u64(22)); - } -} diff --git a/src/test/run-pass/abi/extern/extern-return-TwoU16s.rs b/src/test/run-pass/abi/extern/extern-return-TwoU16s.rs deleted file mode 100644 index dd884ee77fe..00000000000 --- a/src/test/run-pass/abi/extern/extern-return-TwoU16s.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] - -// ignore-wasm32-bare no libc to test ffi with - -pub struct TwoU16s { - one: u16, two: u16 -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_return_TwoU16s() -> TwoU16s; -} - -pub fn main() { - unsafe { - let y = rust_dbg_extern_return_TwoU16s(); - assert_eq!(y.one, 10); - assert_eq!(y.two, 20); - } -} diff --git a/src/test/run-pass/abi/extern/extern-return-TwoU32s.rs b/src/test/run-pass/abi/extern/extern-return-TwoU32s.rs deleted file mode 100644 index d6aaf5c9eaf..00000000000 --- a/src/test/run-pass/abi/extern/extern-return-TwoU32s.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] - -// ignore-wasm32-bare no libc to test ffi with - -pub struct TwoU32s { - one: u32, two: u32 -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s; -} - -pub fn main() { - unsafe { - let y = rust_dbg_extern_return_TwoU32s(); - assert_eq!(y.one, 10); - assert_eq!(y.two, 20); - } -} diff --git a/src/test/run-pass/abi/extern/extern-return-TwoU64s.rs b/src/test/run-pass/abi/extern/extern-return-TwoU64s.rs deleted file mode 100644 index c5e4ebadc18..00000000000 --- a/src/test/run-pass/abi/extern/extern-return-TwoU64s.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] - -// ignore-wasm32-bare no libc to test ffi with - -pub struct TwoU64s { - one: u64, two: u64 -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_return_TwoU64s() -> TwoU64s; -} - -pub fn main() { - unsafe { - let y = rust_dbg_extern_return_TwoU64s(); - assert_eq!(y.one, 10); - assert_eq!(y.two, 20); - } -} diff --git a/src/test/run-pass/abi/extern/extern-return-TwoU8s.rs b/src/test/run-pass/abi/extern/extern-return-TwoU8s.rs deleted file mode 100644 index a7cd21b2073..00000000000 --- a/src/test/run-pass/abi/extern/extern-return-TwoU8s.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] - -// ignore-wasm32-bare no libc to test ffi with - -pub struct TwoU8s { - one: u8, two: u8 -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_return_TwoU8s() -> TwoU8s; -} - -pub fn main() { - unsafe { - let y = rust_dbg_extern_return_TwoU8s(); - assert_eq!(y.one, 10); - assert_eq!(y.two, 20); - } -} diff --git a/src/test/run-pass/abi/foreign/auxiliary/foreign_lib.rs b/src/test/run-pass/abi/foreign/auxiliary/foreign_lib.rs deleted file mode 100644 index de6b0e2118a..00000000000 --- a/src/test/run-pass/abi/foreign/auxiliary/foreign_lib.rs +++ /dev/null @@ -1,38 +0,0 @@ -#![crate_name="foreign_lib"] - -#![feature(rustc_private)] - -pub mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn rust_get_test_int() -> libc::intptr_t; - } -} - -pub mod rustrt2 { - extern crate libc; - - extern { - pub fn rust_get_test_int() -> libc::intptr_t; - } -} - -pub mod rustrt3 { - // Different type, but same ABI (on all supported platforms). - // Ensures that we don't ICE or trigger LLVM asserts when - // importing the same symbol under different types. - // See https://github.com/rust-lang/rust/issues/32740. - extern { - pub fn rust_get_test_int() -> *const u8; - } -} - -pub fn local_uses() { - unsafe { - let x = rustrt::rust_get_test_int(); - assert_eq!(x, rustrt2::rust_get_test_int()); - assert_eq!(x as *const _, rustrt3::rust_get_test_int()); - } -} diff --git a/src/test/run-pass/abi/foreign/foreign-call-no-runtime.rs b/src/test/run-pass/abi/foreign/foreign-call-no-runtime.rs deleted file mode 100644 index c6afa07ad05..00000000000 --- a/src/test/run-pass/abi/foreign/foreign-call-no-runtime.rs +++ /dev/null @@ -1,55 +0,0 @@ -// run-pass -// ignore-emscripten no threads support - -#![feature(rustc_private)] - -extern crate libc; - -use std::mem; -use std::thread; - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t), - data: libc::uintptr_t) -> libc::uintptr_t; -} - -pub fn main() { - unsafe { - thread::spawn(move|| { - let i: isize = 100; - rust_dbg_call(callback_isize, mem::transmute(&i)); - }).join().unwrap(); - - thread::spawn(move|| { - let i: i32 = 100; - rust_dbg_call(callback_i32, mem::transmute(&i)); - }).join().unwrap(); - - thread::spawn(move|| { - let i: i64 = 100; - rust_dbg_call(callback_i64, mem::transmute(&i)); - }).join().unwrap(); - } -} - -extern fn callback_isize(data: libc::uintptr_t) { - unsafe { - let data: *const isize = mem::transmute(data); - assert_eq!(*data, 100); - } -} - -extern fn callback_i64(data: libc::uintptr_t) { - unsafe { - let data: *const i64 = mem::transmute(data); - assert_eq!(*data, 100); - } -} - -extern fn callback_i32(data: libc::uintptr_t) { - unsafe { - let data: *const i32 = mem::transmute(data); - assert_eq!(*data, 100); - } -} diff --git a/src/test/run-pass/abi/foreign/foreign-dupe.rs b/src/test/run-pass/abi/foreign/foreign-dupe.rs deleted file mode 100644 index 3c9f0f583d4..00000000000 --- a/src/test/run-pass/abi/foreign/foreign-dupe.rs +++ /dev/null @@ -1,17 +0,0 @@ -// run-pass -// aux-build:foreign_lib.rs -// ignore-wasm32-bare no libc to test ffi with - -// Check that we can still call duplicated extern (imported) functions -// which were declared in another crate. See issues #32740 and #32783. - - -extern crate foreign_lib; - -pub fn main() { - unsafe { - let x = foreign_lib::rustrt::rust_get_test_int(); - assert_eq!(x, foreign_lib::rustrt2::rust_get_test_int()); - assert_eq!(x as *const _, foreign_lib::rustrt3::rust_get_test_int()); - } -} diff --git a/src/test/run-pass/abi/foreign/foreign-fn-with-byval.rs b/src/test/run-pass/abi/foreign/foreign-fn-with-byval.rs deleted file mode 100644 index 3a35599aa57..00000000000 --- a/src/test/run-pass/abi/foreign/foreign-fn-with-byval.rs +++ /dev/null @@ -1,32 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] - -// ignore-wasm32-bare no libc to test ffi with - -#[derive(Copy, Clone)] -pub struct S { - x: u64, - y: u64, - z: u64, -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn get_x(x: S) -> u64; - pub fn get_y(x: S) -> u64; - pub fn get_z(x: S) -> u64; -} - -#[inline(never)] -fn indirect_call(func: unsafe extern fn(s: S) -> u64, s: S) -> u64 { - unsafe { - func(s) - } -} - -fn main() { - let s = S { x: 1, y: 2, z: 3 }; - assert_eq!(s.x, indirect_call(get_x, s)); - assert_eq!(s.y, indirect_call(get_y, s)); - assert_eq!(s.z, indirect_call(get_z, s)); -} diff --git a/src/test/run-pass/abi/foreign/foreign-no-abi.rs b/src/test/run-pass/abi/foreign/foreign-no-abi.rs deleted file mode 100644 index 2f33fb47656..00000000000 --- a/src/test/run-pass/abi/foreign/foreign-no-abi.rs +++ /dev/null @@ -1,22 +0,0 @@ -// run-pass -// ABI is cdecl by default - -// ignore-wasm32-bare no libc to test ffi with -// pretty-expanded FIXME #23616 - -#![feature(rustc_private)] - -mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn rust_get_test_int() -> libc::intptr_t; - } -} - -pub fn main() { - unsafe { - rustrt::rust_get_test_int(); - } -} diff --git a/src/test/run-pass/abi/invoke-external-foreign.rs b/src/test/run-pass/abi/invoke-external-foreign.rs deleted file mode 100644 index d34933cde42..00000000000 --- a/src/test/run-pass/abi/invoke-external-foreign.rs +++ /dev/null @@ -1,16 +0,0 @@ -// aux-build:foreign_lib.rs -// ignore-wasm32-bare no libc to test ffi with - -// The purpose of this test is to check that we can -// successfully (and safely) invoke external, cdecl -// functions from outside the crate. - -// pretty-expanded FIXME #23616 - -extern crate foreign_lib; - -pub fn main() { - unsafe { - let _foo = foreign_lib::rustrt::rust_get_test_int(); - } -} diff --git a/src/test/run-pass/abi/issues/auxiliary/issue-25185-1.rs b/src/test/run-pass/abi/issues/auxiliary/issue-25185-1.rs deleted file mode 100644 index 77a4787ba94..00000000000 --- a/src/test/run-pass/abi/issues/auxiliary/issue-25185-1.rs +++ /dev/null @@ -1,8 +0,0 @@ -// no-prefer-dynamic - -#![crate_type = "rlib"] - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - pub fn rust_dbg_extern_identity_u32(u: u32) -> u32; -} diff --git a/src/test/run-pass/abi/issues/auxiliary/issue-25185-2.rs b/src/test/run-pass/abi/issues/auxiliary/issue-25185-2.rs deleted file mode 100644 index 7ce3df255a3..00000000000 --- a/src/test/run-pass/abi/issues/auxiliary/issue-25185-2.rs +++ /dev/null @@ -1,3 +0,0 @@ -extern crate issue_25185_1; - -pub use issue_25185_1::rust_dbg_extern_identity_u32; diff --git a/src/test/run-pass/abi/issues/issue-25185.rs b/src/test/run-pass/abi/issues/issue-25185.rs deleted file mode 100644 index 383c9a1e9c4..00000000000 --- a/src/test/run-pass/abi/issues/issue-25185.rs +++ /dev/null @@ -1,13 +0,0 @@ -// run-pass -// aux-build:issue-25185-1.rs -// aux-build:issue-25185-2.rs -// ignore-wasm32-bare no libc for ffi testing - -extern crate issue_25185_2; - -fn main() { - let x = unsafe { - issue_25185_2::rust_dbg_extern_identity_u32(1) - }; - assert_eq!(x, 1); -} diff --git a/src/test/run-pass/abi/issues/issue-28676.rs b/src/test/run-pass/abi/issues/issue-28676.rs deleted file mode 100644 index 2b83478ca61..00000000000 --- a/src/test/run-pass/abi/issues/issue-28676.rs +++ /dev/null @@ -1,35 +0,0 @@ -// run-pass -#![allow(dead_code)] -#![allow(improper_ctypes)] - -// ignore-wasm32-bare no libc to test ffi with - -#[derive(Copy, Clone)] -pub struct Quad { a: u64, b: u64, c: u64, d: u64 } - -mod rustrt { - use super::Quad; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn get_c_many_params(_: *const (), _: *const (), - _: *const (), _: *const (), f: Quad) -> u64; - } -} - -fn test() { - unsafe { - let null = std::ptr::null(); - let q = Quad { - a: 1, - b: 2, - c: 3, - d: 4 - }; - assert_eq!(rustrt::get_c_many_params(null, null, null, null, q), q.c); - } -} - -pub fn main() { - test(); -} diff --git a/src/test/run-pass/abi/lib-defaults.rs b/src/test/run-pass/abi/lib-defaults.rs deleted file mode 100644 index dcf537866c5..00000000000 --- a/src/test/run-pass/abi/lib-defaults.rs +++ /dev/null @@ -1,16 +0,0 @@ -// dont-check-compiler-stderr (rust-lang/rust#54222) - -// ignore-wasm32-bare no libc to test ffi with - -// compile-flags: -lrust_test_helpers - -#[link(name = "rust_test_helpers", kind = "static")] -extern "C" { - pub fn rust_dbg_extern_identity_u32(x: u32) -> u32; -} - -fn main() { - unsafe { - rust_dbg_extern_identity_u32(42); - } -} diff --git a/src/test/run-pass/abi/macros/macros-in-extern.rs b/src/test/run-pass/abi/macros/macros-in-extern.rs deleted file mode 100644 index 28abef5cf4e..00000000000 --- a/src/test/run-pass/abi/macros/macros-in-extern.rs +++ /dev/null @@ -1,30 +0,0 @@ -// run-pass -// ignore-wasm32 - -#![feature(decl_macro, macros_in_extern)] - -macro_rules! returns_isize( - ($ident:ident) => ( - fn $ident() -> isize; - ) -); - -macro takes_u32_returns_u32($ident:ident) { - fn $ident (arg: u32) -> u32; -} - -macro_rules! emits_nothing( - () => () -); - -fn main() { - assert_eq!(unsafe { rust_get_test_int() }, 1isize); - assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEFu32); -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - returns_isize!(rust_get_test_int); - takes_u32_returns_u32!(rust_dbg_extern_identity_u32); - emits_nothing!(); -} diff --git a/src/test/run-pass/abi/mir/mir_codegen_calls_variadic.rs b/src/test/run-pass/abi/mir/mir_codegen_calls_variadic.rs deleted file mode 100644 index dc9fee03b77..00000000000 --- a/src/test/run-pass/abi/mir/mir_codegen_calls_variadic.rs +++ /dev/null @@ -1,22 +0,0 @@ -// run-pass -// ignore-wasm32-bare no libc to test ffi with - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - fn rust_interesting_average(_: i64, ...) -> f64; -} - -fn test(a: i64, b: i64, c: i64, d: i64, e: i64, f: T, g: U) -> i64 { - unsafe { - rust_interesting_average(6, a, a as f64, - b, b as f64, - c, c as f64, - d, d as f64, - e, e as f64, - f, g) as i64 - } -} - -fn main(){ - assert_eq!(test(10, 20, 30, 40, 50, 60_i64, 60.0_f64), 70); -} diff --git a/src/test/run-pass/abi/numbers-arithmetic/i128-ffi.rs b/src/test/run-pass/abi/numbers-arithmetic/i128-ffi.rs deleted file mode 100644 index 19edf9779f3..00000000000 --- a/src/test/run-pass/abi/numbers-arithmetic/i128-ffi.rs +++ /dev/null @@ -1,31 +0,0 @@ -// run-pass -#![allow(improper_ctypes)] - -// MSVC doesn't support 128 bit integers, and other Windows -// C compilers have very inconsistent views on how the ABI -// should look like. - -// ignore-windows -// ignore-32bit - -#[link(name = "rust_test_helpers", kind = "static")] -extern "C" { - fn identity(f: u128) -> u128; - fn square(f: i128) -> i128; - fn sub(f: i128, f: i128) -> i128; -} - -fn main() { - unsafe { - let a = 0x734C_C2F2_A521; - let b = 0x33EE_0E2A_54E2_59DA_A0E7_8E41; - let b_out = identity(b); - assert_eq!(b, b_out); - let a_square = square(a); - assert_eq!(b, a_square as u128); - let k = 0x1234_5678_9ABC_DEFF_EDCB_A987_6543_210; - let k_d = 0x2468_ACF1_3579_BDFF_DB97_530E_CA86_420; - let k_out = sub(k_d, k); - assert_eq!(k, k_out); - } -} diff --git a/src/test/run-pass/abi/proc_macro/auxiliary/test-macros.rs b/src/test/run-pass/abi/proc_macro/auxiliary/test-macros.rs deleted file mode 100644 index 15fe3804f9b..00000000000 --- a/src/test/run-pass/abi/proc_macro/auxiliary/test-macros.rs +++ /dev/null @@ -1,26 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[proc_macro_attribute] -pub fn nop_attr(_attr: TokenStream, input: TokenStream) -> TokenStream { - assert!(_attr.to_string().is_empty()); - input -} - -#[proc_macro_attribute] -pub fn no_output(_attr: TokenStream, _input: TokenStream) -> TokenStream { - assert!(_attr.to_string().is_empty()); - assert!(!_input.to_string().is_empty()); - "".parse().unwrap() -} - -#[proc_macro] -pub fn emit_input(input: TokenStream) -> TokenStream { - input -} diff --git a/src/test/run-pass/abi/proc_macro/macros-in-extern.rs b/src/test/run-pass/abi/proc_macro/macros-in-extern.rs deleted file mode 100644 index 99e3f7d14fd..00000000000 --- a/src/test/run-pass/abi/proc_macro/macros-in-extern.rs +++ /dev/null @@ -1,24 +0,0 @@ -// aux-build:test-macros.rs -// ignore-wasm32 - -#![feature(macros_in_extern)] - -extern crate test_macros; - -use test_macros::{nop_attr, no_output, emit_input}; - -fn main() { - assert_eq!(unsafe { rust_get_test_int() }, 1isize); - assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEF); -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - #[no_output] - fn some_definitely_unknown_symbol_which_should_be_removed(); - - #[nop_attr] - fn rust_get_test_int() -> isize; - - emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;); -} diff --git a/src/test/run-pass/abi/rfcs/rfc1717/library-override.rs b/src/test/run-pass/abi/rfcs/rfc1717/library-override.rs deleted file mode 100644 index 014ccac31b7..00000000000 --- a/src/test/run-pass/abi/rfcs/rfc1717/library-override.rs +++ /dev/null @@ -1,14 +0,0 @@ -// run-pass -// ignore-wasm32-bare no libc to test ffi with -// compile-flags: -lstatic=wronglibrary:rust_test_helpers - -#[link(name = "wronglibrary", kind = "dylib")] -extern "C" { - pub fn rust_dbg_extern_identity_u32(x: u32) -> u32; -} - -fn main() { - unsafe { - rust_dbg_extern_identity_u32(42); - } -} diff --git a/src/test/run-pass/abi/segfault-no-out-of-stack.rs b/src/test/run-pass/abi/segfault-no-out-of-stack.rs deleted file mode 100644 index e90efface68..00000000000 --- a/src/test/run-pass/abi/segfault-no-out-of-stack.rs +++ /dev/null @@ -1,48 +0,0 @@ -#![allow(unused_imports)] -// ignore-cloudabi can't run commands -// ignore-emscripten can't run commands -// ignore-sgx no processes - -#![feature(rustc_private)] - -extern crate libc; - -use std::process::{Command, ExitStatus}; -use std::env; - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - fn rust_get_null_ptr() -> *mut ::libc::c_char; -} - -#[cfg(unix)] -fn check_status(status: std::process::ExitStatus) -{ - use libc; - use std::os::unix::process::ExitStatusExt; - - assert!(status.signal() == Some(libc::SIGSEGV) - || status.signal() == Some(libc::SIGBUS)); -} - -#[cfg(not(unix))] -fn check_status(status: std::process::ExitStatus) -{ - assert!(!status.success()); -} - -fn main() { - let args: Vec = env::args().collect(); - if args.len() > 1 && args[1] == "segfault" { - unsafe { *rust_get_null_ptr() = 1; }; // trigger a segfault - } else { - let segfault = Command::new(&args[0]).arg("segfault").output().unwrap(); - let stderr = String::from_utf8_lossy(&segfault.stderr); - let stdout = String::from_utf8_lossy(&segfault.stdout); - println!("stdout: {}", stdout); - println!("stderr: {}", stderr); - println!("status: {}", segfault.status); - check_status(segfault.status); - assert!(!stderr.contains("has overflowed its stack")); - } -} diff --git a/src/test/run-pass/abi/stack-probes-lto.rs b/src/test/run-pass/abi/stack-probes-lto.rs deleted file mode 100644 index 1274f032a3e..00000000000 --- a/src/test/run-pass/abi/stack-probes-lto.rs +++ /dev/null @@ -1,18 +0,0 @@ -// ignore-arm -// ignore-aarch64 -// ignore-mips -// ignore-mips64 -// ignore-powerpc -// ignore-s390x -// ignore-sparc -// ignore-sparc64 -// ignore-wasm -// ignore-cloudabi no processes -// ignore-emscripten no processes -// ignore-sgx no processes -// ignore-musl FIXME #31506 -// ignore-pretty -// compile-flags: -C lto -// no-prefer-dynamic - -include!("stack-probes.rs"); diff --git a/src/test/run-pass/abi/stack-probes.rs b/src/test/run-pass/abi/stack-probes.rs deleted file mode 100644 index 773d0ace90e..00000000000 --- a/src/test/run-pass/abi/stack-probes.rs +++ /dev/null @@ -1,67 +0,0 @@ -// ignore-arm -// ignore-aarch64 -// ignore-mips -// ignore-mips64 -// ignore-powerpc -// ignore-s390x -// ignore-sparc -// ignore-sparc64 -// ignore-wasm -// ignore-cloudabi no processes -// ignore-emscripten no processes -// ignore-sgx no processes -// ignore-musl FIXME #31506 - -use std::mem; -use std::process::Command; -use std::thread; -use std::env; - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - #[link_name = "rust_dbg_extern_identity_u64"] - fn black_box(u: u64); -} - -fn main() { - let args = env::args().skip(1).collect::>(); - if args.len() > 0 { - match &args[0][..] { - "main-thread" => recurse(&[]), - "child-thread" => thread::spawn(|| recurse(&[])).join().unwrap(), - _ => panic!(), - } - return - } - - let me = env::current_exe().unwrap(); - - // The linux kernel has some different behavior for the main thread because - // the main thread's stack can typically grow. We can't always guarantee - // that we report stack overflow on the main thread, see #43052 for some - // details - if cfg!(not(target_os = "linux")) { - assert_overflow(Command::new(&me).arg("main-thread")); - } - assert_overflow(Command::new(&me).arg("child-thread")); -} - -#[allow(unconditional_recursion)] -fn recurse(array: &[u64]) { - unsafe { black_box(array.as_ptr() as u64); } - #[allow(deprecated)] - let local: [_; 1024] = unsafe { mem::uninitialized() }; - recurse(&local); -} - -fn assert_overflow(cmd: &mut Command) { - let output = cmd.output().unwrap(); - assert!(!output.status.success()); - let stdout = String::from_utf8_lossy(&output.stdout); - let stderr = String::from_utf8_lossy(&output.stderr); - println!("status: {}", output.status); - println!("stdout: {}", stdout); - println!("stderr: {}", stderr); - assert!(stdout.is_empty()); - assert!(stderr.contains("has overflowed its stack\n")); -} diff --git a/src/test/run-pass/abi/statics/static-mut-foreign.rs b/src/test/run-pass/abi/statics/static-mut-foreign.rs deleted file mode 100644 index 5d6fa416b98..00000000000 --- a/src/test/run-pass/abi/statics/static-mut-foreign.rs +++ /dev/null @@ -1,41 +0,0 @@ -// run-pass -// Constants (static variables) can be used to match in patterns, but mutable -// statics cannot. This ensures that there's some form of error if this is -// attempted. - -// ignore-wasm32-bare no libc to test ffi with - -#![feature(rustc_private)] - -extern crate libc; - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - static mut rust_dbg_static_mut: libc::c_int; - pub fn rust_dbg_static_mut_check_four(); -} - -unsafe fn static_bound(_: &'static libc::c_int) {} - -fn static_bound_set(a: &'static mut libc::c_int) { - *a = 3; -} - -unsafe fn run() { - assert_eq!(rust_dbg_static_mut, 3); - rust_dbg_static_mut = 4; - assert_eq!(rust_dbg_static_mut, 4); - rust_dbg_static_mut_check_four(); - rust_dbg_static_mut += 1; - assert_eq!(rust_dbg_static_mut, 5); - rust_dbg_static_mut *= 3; - assert_eq!(rust_dbg_static_mut, 15); - rust_dbg_static_mut = -3; - assert_eq!(rust_dbg_static_mut, -3); - static_bound(&rust_dbg_static_mut); - static_bound_set(&mut rust_dbg_static_mut); -} - -pub fn main() { - unsafe { run() } -} diff --git a/src/test/run-pass/abi/structs-enums/struct-return.rs b/src/test/run-pass/abi/structs-enums/struct-return.rs deleted file mode 100644 index 5930fc4acbb..00000000000 --- a/src/test/run-pass/abi/structs-enums/struct-return.rs +++ /dev/null @@ -1,64 +0,0 @@ -// run-pass -#![allow(dead_code)] -// ignore-wasm32-bare no libc to test ffi with - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct Quad { a: u64, b: u64, c: u64, d: u64 } - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct Floats { a: f64, b: u8, c: f64 } - -mod rustrt { - use super::{Floats, Quad}; - - #[link(name = "rust_test_helpers", kind = "static")] - extern { - pub fn rust_dbg_abi_1(q: Quad) -> Quad; - pub fn rust_dbg_abi_2(f: Floats) -> Floats; - } -} - -fn test1() { - unsafe { - let q = Quad { a: 0xaaaa_aaaa_aaaa_aaaa, - b: 0xbbbb_bbbb_bbbb_bbbb, - c: 0xcccc_cccc_cccc_cccc, - d: 0xdddd_dddd_dddd_dddd }; - let qq = rustrt::rust_dbg_abi_1(q); - println!("a: {:x}", qq.a as usize); - println!("b: {:x}", qq.b as usize); - println!("c: {:x}", qq.c as usize); - println!("d: {:x}", qq.d as usize); - assert_eq!(qq.a, q.c + 1); - assert_eq!(qq.b, q.d - 1); - assert_eq!(qq.c, q.a + 1); - assert_eq!(qq.d, q.b - 1); - } -} - -#[cfg(target_pointer_width = "64")] -fn test2() { - unsafe { - let f = Floats { a: 1.234567890e-15_f64, - b: 0b_1010_1010, - c: 1.0987654321e-15_f64 }; - let ff = rustrt::rust_dbg_abi_2(f); - println!("a: {}", ff.a as f64); - println!("b: {}", ff.b as usize); - println!("c: {}", ff.c as f64); - assert_eq!(ff.a, f.c + 1.0f64); - assert_eq!(ff.b, 0xff); - assert_eq!(ff.c, f.a - 1.0f64); - } -} - -#[cfg(target_pointer_width = "32")] -fn test2() { -} - -pub fn main() { - test1(); - test2(); -} diff --git a/src/test/run-pass/abi/union/union-c-interop.rs b/src/test/run-pass/abi/union/union-c-interop.rs deleted file mode 100644 index 00f04d5b7ff..00000000000 --- a/src/test/run-pass/abi/union/union-c-interop.rs +++ /dev/null @@ -1,37 +0,0 @@ -// run-pass -#![allow(non_snake_case)] - -// ignore-wasm32-bare no libc to test ffi with - -#[derive(Clone, Copy)] -#[repr(C)] -struct LARGE_INTEGER_U { - LowPart: u32, - HighPart: u32, -} - -#[derive(Clone, Copy)] -#[repr(C)] -union LARGE_INTEGER { - __unnamed__: LARGE_INTEGER_U, - u: LARGE_INTEGER_U, - QuadPart: u64, -} - -#[link(name = "rust_test_helpers", kind = "static")] -extern "C" { - fn increment_all_parts(_: LARGE_INTEGER) -> LARGE_INTEGER; -} - -fn main() { - unsafe { - let mut li = LARGE_INTEGER { QuadPart: 0 }; - let li_c = increment_all_parts(li); - li.__unnamed__.LowPart += 1; - li.__unnamed__.HighPart += 1; - li.u.LowPart += 1; - li.u.HighPart += 1; - li.QuadPart += 1; - assert_eq!(li.QuadPart, li_c.QuadPart); - } -} diff --git a/src/test/run-pass/abi/variadic-ffi.rs b/src/test/run-pass/abi/variadic-ffi.rs deleted file mode 100644 index d6fbb1773b2..00000000000 --- a/src/test/run-pass/abi/variadic-ffi.rs +++ /dev/null @@ -1,83 +0,0 @@ -// ignore-wasm32-bare no libc to test ffi with -#![feature(c_variadic)] - -use std::ffi::VaList; - -#[link(name = "rust_test_helpers", kind = "static")] -extern { - fn rust_interesting_average(_: u64, ...) -> f64; - - // FIXME: we need to disable this lint for `VaList`, - // since it contains a `MaybeUninit` on the asmjs target, - // and this type isn't FFI-safe. This is OK for now, - // since the type is layout-compatible with `i32`. - #[cfg_attr(target_arch = "asmjs", allow(improper_ctypes))] - fn rust_valist_interesting_average(_: u64, _: VaList) -> f64; -} - -pub unsafe extern "C" fn test_valist_forward(n: u64, mut ap: ...) -> f64 { - rust_valist_interesting_average(n, ap.as_va_list()) -} - -pub unsafe extern "C" fn test_va_copy(_: u64, mut ap: ...) { - let mut ap2 = ap.clone(); - assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 30); - - // Advance one pair in the copy before checking - let mut ap2 = ap.clone(); - let _ = ap2.arg::(); - let _ = ap2.arg::(); - assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 50); - - // Advance one pair in the original - let _ = ap.arg::(); - let _ = ap.arg::(); - - let mut ap2 = ap.clone(); - assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 50); - - let mut ap2 = ap.clone(); - let _ = ap2.arg::(); - let _ = ap2.arg::(); - assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 70); -} - -pub fn main() { - // Call without variadic arguments - unsafe { - assert!(rust_interesting_average(0).is_nan()); - } - - // Call with direct arguments - unsafe { - assert_eq!(rust_interesting_average(1, 10i64, 10.0f64) as i64, 20); - } - - // Call with named arguments, variable number of them - let (x1, x2, x3, x4) = (10i64, 10.0f64, 20i64, 20.0f64); - unsafe { - assert_eq!(rust_interesting_average(2, x1, x2, x3, x4) as i64, 30); - } - - // A function that takes a function pointer - unsafe fn call(fp: unsafe extern fn(u64, ...) -> f64) { - let (x1, x2, x3, x4) = (10i64, 10.0f64, 20i64, 20.0f64); - assert_eq!(fp(2, x1, x2, x3, x4) as i64, 30); - } - - unsafe { - call(rust_interesting_average); - - // Make a function pointer, pass indirectly - let x: unsafe extern fn(u64, ...) -> f64 = rust_interesting_average; - call(x); - } - - unsafe { - assert_eq!(test_valist_forward(2, 10i64, 10f64, 20i64, 20f64) as i64, 30); - } - - unsafe { - test_va_copy(4, 10i64, 10f64, 20i64, 20f64, 30i64, 30f64, 40i64, 40f64); - } -} From 26ee99e5d473e8743e3faa08c6cb89d3acb29104 Mon Sep 17 00:00:00 2001 From: Kevin Per Date: Thu, 15 Aug 2019 19:26:51 +0200 Subject: [PATCH 7/7] Duplicate `test-macros.rs` to fix test #62593 --- .../abi/proc-macro/auxiliary/test-macros.rs | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/test/ui/abi/proc-macro/auxiliary/test-macros.rs diff --git a/src/test/ui/abi/proc-macro/auxiliary/test-macros.rs b/src/test/ui/abi/proc-macro/auxiliary/test-macros.rs new file mode 100644 index 00000000000..27efa44f980 --- /dev/null +++ b/src/test/ui/abi/proc-macro/auxiliary/test-macros.rs @@ -0,0 +1,112 @@ +// force-host +// no-prefer-dynamic + +// Proc macros commonly used by tests. +// `panic`/`print` -> `panic_bang`/`print_bang` to avoid conflicts with standard macros. + +#![crate_type = "proc-macro"] + +extern crate proc_macro; +use proc_macro::TokenStream; + +// Macro that return empty token stream. + +#[proc_macro] +pub fn empty(_: TokenStream) -> TokenStream { + TokenStream::new() +} + +#[proc_macro_attribute] +pub fn empty_attr(_: TokenStream, _: TokenStream) -> TokenStream { + TokenStream::new() +} + +#[proc_macro_derive(Empty, attributes(empty_helper))] +pub fn empty_derive(_: TokenStream) -> TokenStream { + TokenStream::new() +} + +// Macro that panics. + +#[proc_macro] +pub fn panic_bang(_: TokenStream) -> TokenStream { + panic!("panic-bang"); +} + +#[proc_macro_attribute] +pub fn panic_attr(_: TokenStream, _: TokenStream) -> TokenStream { + panic!("panic-attr"); +} + +#[proc_macro_derive(Panic, attributes(panic_helper))] +pub fn panic_derive(_: TokenStream) -> TokenStream { + panic!("panic-derive"); +} + +// Macros that return the input stream. + +#[proc_macro] +pub fn identity(input: TokenStream) -> TokenStream { + input +} + +#[proc_macro_attribute] +pub fn identity_attr(_: TokenStream, input: TokenStream) -> TokenStream { + input +} + +#[proc_macro_derive(Identity, attributes(identity_helper))] +pub fn identity_derive(input: TokenStream) -> TokenStream { + input +} + +// Macros that iterate and re-collect the input stream. + +#[proc_macro] +pub fn recollect(input: TokenStream) -> TokenStream { + input.into_iter().collect() +} + +#[proc_macro_attribute] +pub fn recollect_attr(_: TokenStream, input: TokenStream) -> TokenStream { + input.into_iter().collect() +} + +#[proc_macro_derive(Recollect, attributes(recollect_helper))] +pub fn recollect_derive(input: TokenStream) -> TokenStream { + input.into_iter().collect() +} + +// Macros that print their input in the original and re-collected forms (if they differ). + +fn print_helper(input: TokenStream, kind: &str) -> TokenStream { + let input_display = format!("{}", input); + let input_debug = format!("{:#?}", input); + let recollected = input.into_iter().collect(); + let recollected_display = format!("{}", recollected); + let recollected_debug = format!("{:#?}", recollected); + println!("PRINT-{} INPUT (DISPLAY): {}", kind, input_display); + if recollected_display != input_display { + println!("PRINT-{} RE-COLLECTED (DISPLAY): {}", kind, recollected_display); + } + println!("PRINT-{} INPUT (DEBUG): {}", kind, input_debug); + if recollected_debug != input_debug { + println!("PRINT-{} RE-COLLECTED (DEBUG): {}", kind, recollected_debug); + } + recollected +} + +#[proc_macro] +pub fn print_bang(input: TokenStream) -> TokenStream { + print_helper(input, "BANG") +} + +#[proc_macro_attribute] +pub fn print_attr(_: TokenStream, input: TokenStream) -> TokenStream { + print_helper(input, "ATTR") +} + +#[proc_macro_derive(Print, attributes(print_helper))] +pub fn print_derive(input: TokenStream) -> TokenStream { + print_helper(input, "DERIVE") +}