]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-mock-codegen.rs
Rollup merge of #69665 - tmiasko:new-pass-manager-thin-lto-opt, r=nikic
[rust.git] / src / test / ui / regions / regions-mock-codegen.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(non_camel_case_types)]
4
5 // pretty-expanded FIXME #23616
6
7 #![feature(allocator_api)]
8
9 use std::alloc::{AllocRef, Global, Layout, handle_alloc_error};
10 use std::ptr::NonNull;
11
12 struct arena(());
13
14 struct Bcx<'a> {
15     fcx: &'a Fcx<'a>
16 }
17
18 struct Fcx<'a> {
19     arena: &'a arena,
20     ccx: &'a Ccx
21 }
22
23 struct Ccx {
24     x: isize
25 }
26
27 fn alloc(_bcx: &arena) -> &Bcx<'_> {
28     unsafe {
29         let layout = Layout::new::<Bcx>();
30         let (ptr, _) = Global.alloc(layout).unwrap_or_else(|_| handle_alloc_error(layout));
31         &*(ptr.as_ptr() as *const _)
32     }
33 }
34
35 fn h<'a>(bcx: &'a Bcx<'a>) -> &'a Bcx<'a> {
36     return alloc(bcx.fcx.arena);
37 }
38
39 fn g(fcx: &Fcx) {
40     let bcx = Bcx { fcx };
41     let bcx2 = h(&bcx);
42     unsafe {
43         Global.dealloc(NonNull::new_unchecked(bcx2 as *const _ as *mut _), Layout::new::<Bcx>());
44     }
45 }
46
47 fn f(ccx: &Ccx) {
48     let a = arena(());
49     let fcx = Fcx { arena: &a, ccx };
50     return g(&fcx);
51 }
52
53 pub fn main() {
54     let ccx = Ccx { x: 0 };
55     f(&ccx);
56 }