]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass-dep/regions-mock-trans.rs
Rollup merge of #101889 - tspiteri:redoc-uint-adc-sbb, r=m-ou-se
[rust.git] / src / tools / miri / tests / pass-dep / regions-mock-trans.rs
1 use std::mem;
2
3 struct Arena(());
4
5 struct Bcx<'a> {
6     fcx: &'a Fcx<'a>,
7 }
8
9 #[allow(dead_code)]
10 struct Fcx<'a> {
11     arena: &'a Arena,
12     ccx: &'a Ccx,
13 }
14
15 #[allow(dead_code)]
16 struct Ccx {
17     x: isize,
18 }
19
20 fn alloc<'a>(_bcx: &'a Arena) -> &'a mut Bcx<'a> {
21     unsafe { mem::transmute(libc::malloc(mem::size_of::<Bcx<'a>>() as libc::size_t)) }
22 }
23
24 fn h<'a>(bcx: &'a Bcx<'a>) -> &'a mut Bcx<'a> {
25     return alloc(bcx.fcx.arena);
26 }
27
28 fn g(fcx: &Fcx) {
29     let bcx = Bcx { fcx: fcx };
30     let bcx2 = h(&bcx);
31     unsafe {
32         libc::free(mem::transmute(bcx2));
33     }
34 }
35
36 fn f(ccx: &Ccx) {
37     let a = Arena(());
38     let fcx = Fcx { arena: &a, ccx: ccx };
39     return g(&fcx);
40 }
41
42 pub fn main() {
43     let ccx = Ccx { x: 0 };
44     f(&ccx);
45 }