Skip to content

Test variadic fnptr uses incompatible definition and declaration #66690

Closed
@bjorn3

Description

@bjorn3

#[test]
#[allow(warnings)]
// Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the
// ABI, or even point to an actual executable code, because the function itself is never invoked.
#[no_mangle]
pub fn test_variadic_fnptr() {
use core::hash::{Hash, SipHasher};
extern {
fn test_variadic_fnptr(_: u64, ...) -> f64;
}
let p: unsafe extern fn(u64, ...) -> f64 = test_variadic_fnptr;
let q = p.clone();
assert_eq!(p, q);
assert!(!(p < q));
let mut s = SipHasher::new();
assert_eq!(p.hash(&mut s), q.hash(&mut s));
}

This causes a crash when trying to test libcore with cg_clif, as Cranelift doesn't allow incompatible definitions of the same function. While this currently works for cg_llvm, according to rust-lang/unsafe-code-guidelines#198 it is likely to become forbidden with cg_llvm too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-craneliftThings relevant to the [future] cranelift backendA-testsuiteArea: The testsuite used to check the correctness of rustcC-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions