2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2018-09-25 23:51:35 +02:00
|
|
|
#![allow(dead_code)]
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2013-11-22 01:16:17 -08:00
|
|
|
/*!
|
|
|
|
* C-like enums have to be represented as LLVM ints, not wrapped in a
|
|
|
|
* struct, because it's important for the FFI that they interoperate
|
|
|
|
* with C integers/enums, and the ABI can treat structs differently.
|
|
|
|
* For example, on i686-linux-gnu, a struct return value is passed by
|
|
|
|
* storing to a hidden out parameter, whereas an integer would be
|
|
|
|
* returned in a register.
|
|
|
|
*
|
|
|
|
* This test just checks that the ABIs for the enum and the plain
|
|
|
|
* integer are compatible, rather than actually calling C code.
|
|
|
|
* The unused parameter to `foo` is to increase the likelihood of
|
|
|
|
* crashing if something goes wrong here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[repr(u32)]
|
|
|
|
enum Foo {
|
2016-02-18 15:19:38 +02:00
|
|
|
A = 0,
|
|
|
|
B = 23
|
2013-11-22 01:16:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(never)]
|
2015-03-25 17:06:52 -07:00
|
|
|
extern "C" fn foo(_x: usize) -> Foo { Foo::B }
|
2013-11-22 01:16:17 -08:00
|
|
|
|
|
|
|
pub fn main() {
|
2016-02-18 15:19:38 +02:00
|
|
|
unsafe {
|
|
|
|
let f: extern "C" fn(usize) -> u32 =
|
|
|
|
::std::mem::transmute(foo as extern "C" fn(usize) -> Foo);
|
|
|
|
assert_eq!(f(0xDEADBEEF), Foo::B as u32);
|
|
|
|
}
|
2013-11-22 01:16:17 -08:00
|
|
|
}
|