blob: 081060980779fe40470ab93c03a48a086bfab6f5 [file] [log] [blame]
Brian Silverman8751d482022-05-18 23:28:44 -07001extern "C" {
2 fn c_return5() -> u8;
3 fn c_take5(x: *mut u8);
4}
5
6#[no_mangle]
7pub unsafe extern "C" fn rust_return5() -> i32 {
8 let layout = std::alloc::Layout::from_size_align(1, 1).unwrap();
9 let a = std::alloc::alloc(layout);
10 *a = c_return5();
11 // Do something so the compiler can't optimize out the alloc+free pair, which would invalidate
12 // this test.
13 if *a != 5 {
14 c_take5(a);
15 } else {
16 std::alloc::dealloc(a, layout);
17 }
18 5
19}