]> git.lizzy.rs Git - rust.git/blob - tests/ui/abi/nullable-pointer-ffi-compat.rs
Rollup merge of #103236 - tspiteri:redoc-int-adc-sbb, r=m-ou-se
[rust.git] / tests / ui / abi / nullable-pointer-ffi-compat.rs
1 // run-pass
2 // #11303, #11040:
3 // This would previously crash on i686 Linux due to abi differences
4 // between returning an Option<T> and T, where T is a non nullable
5 // pointer.
6 // If we have an enum with two variants such that one is zero sized
7 // and the other contains a nonnullable pointer, we don't use a
8 // separate discriminant. Instead we use that pointer field to differentiate
9 // between the 2 cases.
10 // Also, if the variant with the nonnullable pointer has no other fields
11 // then we simply express the enum as just a pointer and not wrap it
12 // in a struct.
13
14
15 use std::mem;
16
17 #[inline(never)]
18 extern "C" fn foo(x: &isize) -> Option<&isize> { Some(x) }
19
20 static FOO: isize = 0xDEADBEE;
21
22 pub fn main() {
23     unsafe {
24         let f: extern "C" fn(&isize) -> &isize =
25             mem::transmute(foo as extern "C" fn(&isize) -> Option<&isize>);
26         assert_eq!(*f(&FOO), FOO);
27     }
28 }