Remove libc from rust_get_test_int uses

This commit is contained in:
Ben Kimock 2024-04-15 23:46:27 -04:00
parent 1dea922ea6
commit 6298d8f8fa
8 changed files with 18 additions and 54 deletions

View File

@ -1,13 +1,9 @@
//@ run-pass //@ run-pass
//@ pretty-expanded FIXME #23616 //@ pretty-expanded FIXME #23616
#![feature(rustc_private)]
extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern "C" { extern "C" {
fn rust_get_test_int() -> libc::intptr_t; fn rust_get_test_int() -> isize;
} }
pub fn main() { pub fn main() {

View File

@ -1,14 +1,10 @@
//@ run-pass //@ run-pass
//@ pretty-expanded FIXME #23616 //@ pretty-expanded FIXME #23616
#![feature(rustc_private)]
mod rustrt { mod rustrt {
extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern "C" { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> isize;
} }
} }

View File

@ -1,9 +1,6 @@
#![crate_name = "anonexternmod"] #![crate_name = "anonexternmod"]
#![feature(rustc_private)]
extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern "C" { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> isize;
} }

View File

@ -1,28 +1,28 @@
#![crate_name = "foreign_lib"] #![crate_name = "foreign_lib"]
#![feature(rustc_private)]
pub mod rustrt { pub mod rustrt {
extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern "C" { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> isize;
} }
} }
pub mod rustrt2 { pub mod rustrt2 {
extern crate libc;
extern "C" { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> isize;
} }
} }
pub mod rustrt3 { pub mod rustrt3 {
// Different type, but same ABI (on all supported platforms). // The point of this test is to ensure that we don't ICE or trigger LLVM asserts when importing
// Ensures that we don't ICE or trigger LLVM asserts when // the same symbol with different types. This is not really possible to test portably; there is
// importing the same symbol under different types. // no different signature we can come up with that is different to LLVM but which for sure has
// See https://github.com/rust-lang/rust/issues/32740. // the same behavior on all platforms. The signed-ness of integers is ignored by LLVM as well
// as pointee types. So the only ways to make our signatures differ are to use
// differently-sized integers which is definitely an ABI mismatch, or to rely on pointers and
// isize/usize having the same ABI, which is wrong on CHERI and probably other niche platforms.
// If this test causes you trouble, please file an issue.
// See https://github.com/rust-lang/rust/issues/32740 for the bug that prompted this test.
extern "C" { extern "C" {
pub fn rust_get_test_int() -> *const u8; pub fn rust_get_test_int() -> *const u8;
} }
@ -32,6 +32,6 @@ pub fn local_uses() {
unsafe { unsafe {
let x = rustrt::rust_get_test_int(); let x = rustrt::rust_get_test_int();
assert_eq!(x, rustrt2::rust_get_test_int()); assert_eq!(x, rustrt2::rust_get_test_int());
assert_eq!(x as *const _, rustrt3::rust_get_test_int()); assert_eq!(x as *const u8, rustrt3::rust_get_test_int());
} }
} }

View File

@ -4,13 +4,12 @@
// Check that we can still call duplicated extern (imported) functions // Check that we can still call duplicated extern (imported) functions
// which were declared in another crate. See issues #32740 and #32783. // which were declared in another crate. See issues #32740 and #32783.
extern crate foreign_lib; extern crate foreign_lib;
pub fn main() { pub fn main() {
unsafe { unsafe {
let x = foreign_lib::rustrt::rust_get_test_int(); let x = foreign_lib::rustrt::rust_get_test_int();
assert_eq!(x, foreign_lib::rustrt2::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()); assert_eq!(x as *const u8, foreign_lib::rustrt3::rust_get_test_int());
} }
} }

View File

@ -1,21 +0,0 @@
//@ run-pass
// ABI is cdecl by default
//@ pretty-expanded FIXME #23616
#![feature(rustc_private)]
mod rustrt {
extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t;
}
}
pub fn main() {
unsafe {
rustrt::rust_get_test_int();
}
}

View File

@ -148,7 +148,7 @@ pub mod rustrt {
#![rustc_dummy] #![rustc_dummy]
#[rustc_dummy] #[rustc_dummy]
fn rust_get_test_int() -> u32; fn rust_get_test_int() -> isize;
} }
} }
} }

View File

@ -2,13 +2,10 @@
#![allow(unused_attributes)] #![allow(unused_attributes)]
#![allow(dead_code)] #![allow(dead_code)]
//@ pretty-expanded FIXME #23616 //@ pretty-expanded FIXME #23616
#![feature(rustc_private)]
mod rustrt { mod rustrt {
extern crate libc;
extern "C" { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> isize;
} }
} }