Skip to content

Commit 2b50739

Browse files
committed
Auto merge of rust-lang#95088 - bjorn3:fix_test_variadic_fnptr, r=dtolnay
Don't declare test_variadic_fnptr with two conflicting signatures It is UB for LLVM and results in a compile error for Cranelift. cc https://github.com/bjorn3/rustc_codegen_cranelift/issues/806 Fixes rust-lang#66690
2 parents a4a5e79 + 4af755b commit 2b50739

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

Diff for: compiler/rustc_codegen_cranelift/patches/0022-sysroot-Disable-not-compiling-tests.patch

-20
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,5 @@ index 0000000..46fd999
3030
+
3131
+[dependencies]
3232
+rand = "0.7"
33-
diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs
34-
index 1a6be3a..42dbd59 100644
35-
--- a/library/core/tests/ptr.rs
36-
+++ b/library/core/tests/ptr.rs
37-
@@ -250,6 +250,7 @@ fn test_unsized_nonnull() {
38-
};
39-
}
40-
41-
+/*
42-
#[test]
43-
#[allow(warnings)]
44-
// Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the
45-
@@ -277,6 +277,7 @@ pub fn test_variadic_fnptr() {
46-
let mut s = SipHasher::new();
47-
assert_eq!(p.hash(&mut s), q.hash(&mut s));
48-
}
49-
+*/
50-
51-
#[test]
52-
fn write_unaligned_drop() {
5333
--
5434
2.21.0 (Apple Git-122)

Diff for: library/core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(const_ptr_offset)]
2424
#![feature(const_trait_impl)]
2525
#![feature(const_likely)]
26+
#![feature(core_ffi_c)]
2627
#![feature(core_intrinsics)]
2728
#![feature(core_private_bignum)]
2829
#![feature(core_private_diy_float)]

Diff for: library/core/tests/ptr.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,18 @@ fn test_const_nonnull_new() {
289289
}
290290

291291
#[test]
292-
#[allow(warnings)]
293-
// Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the
294-
// ABI, or even point to an actual executable code, because the function itself is never invoked.
295-
#[no_mangle]
292+
#[cfg(unix)] // printf may not be available on other platforms
293+
#[allow(deprecated)] // For SipHasher
296294
pub fn test_variadic_fnptr() {
295+
use core::ffi;
297296
use core::hash::{Hash, SipHasher};
298297
extern "C" {
299-
fn test_variadic_fnptr(_: u64, ...) -> f64;
298+
// This needs to use the correct function signature even though it isn't called as some
299+
// codegen backends make it UB to declare a function with multiple conflicting signatures
300+
// (like LLVM) while others straight up return an error (like Cranelift).
301+
fn printf(_: *const ffi::c_char, ...) -> ffi::c_int;
300302
}
301-
let p: unsafe extern "C" fn(u64, ...) -> f64 = test_variadic_fnptr;
303+
let p: unsafe extern "C" fn(*const ffi::c_char, ...) -> ffi::c_int = printf;
302304
let q = p.clone();
303305
assert_eq!(p, q);
304306
assert!(!(p < q));

0 commit comments

Comments
 (0)