Skip to content

Commit 65fb8b5

Browse files
committed
Update union generated files
1 parent 5cabdfb commit 65fb8b5

28 files changed

Lines changed: 2050 additions & 3 deletions
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
#[repr(C)]
10+
#[derive()]
11+
pub struct record {
12+
pub code: Value<u16>,
13+
pub lo: Value<u16>,
14+
pub hi: Value<u32>,
15+
pub pad: Value<Box<[u8]>>,
16+
}
17+
impl ByteRepr for record {}
18+
#[repr(C)]
19+
#[derive(Copy, Clone)]
20+
pub union Container_anon_15_3 {
21+
pub h: Value<record>,
22+
pub raw_: Value<Box<[u8]>>,
23+
}
24+
impl Default for Container_anon_15_3 {
25+
fn default() -> Self {
26+
unsafe { std::mem::zeroed() }
27+
}
28+
}
29+
#[repr(C)]
30+
#[derive(Default)]
31+
pub struct Container {
32+
pub view: Value<Container_anon_15_3>,
33+
}
34+
impl ByteRepr for Container {}
35+
pub fn fill_0(out: AnyPtr, cap: u64) {
36+
let out: Value<AnyPtr> = Rc::new(RefCell::new(out));
37+
let cap: Value<u64> = Rc::new(RefCell::new(cap));
38+
let src: Value<Box<[u8]>> = Rc::new(RefCell::new(Box::new([
39+
0_u8,
40+
<u8>::default(),
41+
<u8>::default(),
42+
<u8>::default(),
43+
<u8>::default(),
44+
<u8>::default(),
45+
<u8>::default(),
46+
<u8>::default(),
47+
<u8>::default(),
48+
<u8>::default(),
49+
<u8>::default(),
50+
<u8>::default(),
51+
<u8>::default(),
52+
<u8>::default(),
53+
<u8>::default(),
54+
<u8>::default(),
55+
])));
56+
(*src.borrow_mut())[(0) as usize] = 2_u8;
57+
(*src.borrow_mut())[(1) as usize] = 0_u8;
58+
(*src.borrow_mut())[(2) as usize] = 0_u8;
59+
(*src.borrow_mut())[(3) as usize] = 80_u8;
60+
(*src.borrow_mut())[(4) as usize] = 127_u8;
61+
(*src.borrow_mut())[(5) as usize] = 0_u8;
62+
(*src.borrow_mut())[(6) as usize] = 0_u8;
63+
(*src.borrow_mut())[(7) as usize] = 1_u8;
64+
let n: Value<u64> = Rc::new(RefCell::new(
65+
if ((::std::mem::size_of::<[u8; 16]>() as u64) < (*cap.borrow())) {
66+
::std::mem::size_of::<[u8; 16]>() as u64
67+
} else {
68+
(*cap.borrow())
69+
},
70+
));
71+
{
72+
(*out.borrow()).memcpy(
73+
&((src.as_pointer() as Ptr<u8>) as Ptr<u8>).to_any(),
74+
(*n.borrow()) as usize,
75+
);
76+
(*out.borrow()).clone()
77+
};
78+
}
79+
pub fn main() {
80+
std::process::exit(main_0());
81+
}
82+
fn main_0() -> i32 {
83+
let c: Value<Container> = <Value<Container>>::default();
84+
{
85+
((c.as_pointer()) as Ptr<Container>).to_any().memset(
86+
(0) as u8,
87+
::std::mem::size_of::<Container>() as u64 as usize,
88+
);
89+
((c.as_pointer()) as Ptr<Container>).to_any().clone()
90+
};
91+
({
92+
let _out: AnyPtr = (((*c.borrow()).view.as_pointer()).to_strong().as_pointer() as AnyPtr);
93+
let _cap: u64 = ::std::mem::size_of::<Container_anon_15_3>() as u64;
94+
fill_0(_out, _cap)
95+
});
96+
assert!((((*(*(*(*c.borrow()).view.borrow()).h.borrow()).code.borrow()) as i32) == (2)));
97+
assert!(
98+
((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer())
99+
.to_strong()
100+
.as_pointer() as Ptr::<u8>)
101+
.offset((0) as isize)
102+
.read()) as i32)
103+
== (0))
104+
);
105+
assert!(
106+
((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer())
107+
.to_strong()
108+
.as_pointer() as Ptr::<u8>)
109+
.offset((1) as isize)
110+
.read()) as i32)
111+
== (80))
112+
);
113+
assert!((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(0) as usize] as i32) == (2)));
114+
assert!(
115+
((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(3) as usize] as u8) as i32) == (80))
116+
);
117+
return 0;
118+
}

tests/unit/out/refcount/union_basic.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
99
#[derive(Default)]
10-
pub struct basic {
10+
pub union basic {
1111
pub i: Value<i32>,
1212
pub f: Value<f32>,
1313
}
14+
impl Default for basic {
15+
fn default() -> Self {
16+
unsafe { std::mem::zeroed() }
17+
}
18+
}
1419
impl ByteRepr for basic {}
1520
pub fn main() {
1621
std::process::exit(main_0());
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
#[derive()]
10+
pub struct shape_a {
11+
pub code: Value<u16>,
12+
pub pad: Value<Box<[u8]>>,
13+
}
14+
impl Default for shape_a {
15+
fn default() -> Self {
16+
shape_a {
17+
code: <Value<u16>>::default(),
18+
pad: Rc::new(RefCell::new(
19+
(0..14).map(|_| <u8>::default()).collect::<Box<[u8]>>(),
20+
)),
21+
}
22+
}
23+
}
24+
impl ByteRepr for shape_a {}
25+
#[derive()]
26+
pub struct shape_b {
27+
pub code: Value<u16>,
28+
pub lo: Value<u16>,
29+
pub mid: Value<u32>,
30+
pub fill: Value<Box<[u8]>>,
31+
pub tail: Value<u32>,
32+
}
33+
impl Default for shape_b {
34+
fn default() -> Self {
35+
shape_b {
36+
code: <Value<u16>>::default(),
37+
lo: <Value<u16>>::default(),
38+
mid: <Value<u32>>::default(),
39+
fill: Rc::new(RefCell::new(
40+
(0..16).map(|_| <u8>::default()).collect::<Box<[u8]>>(),
41+
)),
42+
tail: <Value<u32>>::default(),
43+
}
44+
}
45+
}
46+
impl ByteRepr for shape_b {}
47+
#[derive()]
48+
pub union Container_anon_22_3 {
49+
pub a: Value<shape_a>,
50+
pub b: Value<shape_b>,
51+
pub raw_: Value<Box<[u8]>>,
52+
}
53+
impl Default for Container_anon_22_3 {
54+
fn default() -> Self {
55+
unsafe { std::mem::zeroed() }
56+
}
57+
}
58+
impl ByteRepr for Container_anon_22_3 {}
59+
#[derive(Default)]
60+
pub struct Container {
61+
pub len: Value<u32>,
62+
pub u: Value<Container_anon_22_3>,
63+
}
64+
impl ByteRepr for Container {}
65+
pub fn main() {
66+
std::process::exit(main_0());
67+
}
68+
fn main_0() -> i32 {
69+
let c: Value<Container> = <Value<Container>>::default();
70+
{
71+
((c.as_pointer()) as Ptr<Container>).to_any().memset(
72+
(0) as u8,
73+
::std::mem::size_of::<Container>() as u64 as usize,
74+
);
75+
((c.as_pointer()) as Ptr<Container>).to_any().clone()
76+
};
77+
(*(*(*(*c.borrow()).u.borrow()).a.borrow()).code.borrow_mut()) = 10_u16;
78+
(*(*c.borrow()).len.borrow_mut()) = (::std::mem::size_of::<shape_b>() as u64 as u32);
79+
(*(*((((*(*c.borrow()).u.borrow()).a.as_pointer())
80+
.to_strong()
81+
.as_pointer() as AnyPtr)
82+
.cast::<shape_b>()
83+
.expect("ub:wrong type"))
84+
.upgrade()
85+
.deref())
86+
.tail
87+
.borrow_mut()) = 3735928559_u32;
88+
assert!(((*(*(*(*c.borrow()).u.borrow()).b.borrow()).tail.borrow()) == 3735928559_u32));
89+
assert!((((*(*(*(*c.borrow()).u.borrow()).b.borrow()).code.borrow()) as i32) == 10));
90+
(*(*(*(*c.borrow()).u.borrow()).b.borrow()).lo.borrow_mut()) = 8080_u16;
91+
assert!(
92+
((((((*(*c.borrow()).u.borrow()).raw_.as_pointer())
93+
.to_strong()
94+
.as_pointer() as Ptr::<u8>)
95+
.offset((2) as isize)
96+
.read()) as i32)
97+
== 144)
98+
);
99+
assert!(
100+
((((((*(*c.borrow()).u.borrow()).raw_.as_pointer())
101+
.to_strong()
102+
.as_pointer() as Ptr::<u8>)
103+
.offset((3) as isize)
104+
.read()) as i32)
105+
== 31)
106+
);
107+
return 0;
108+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
#[derive()]
10+
pub union node_anon_10_3 {
11+
pub bytes: Value<Box<[u8]>>,
12+
pub aligner: Value<AnyPtr>,
13+
}
14+
impl Default for node_anon_10_3 {
15+
fn default() -> Self {
16+
unsafe { std::mem::zeroed() }
17+
}
18+
}
19+
impl ByteRepr for node_anon_10_3 {}
20+
#[derive(Default)]
21+
pub struct node {
22+
pub next: Value<Ptr<node>>,
23+
pub x: Value<node_anon_10_3>,
24+
}
25+
impl ByteRepr for node {}
26+
pub fn main() {
27+
std::process::exit(main_0());
28+
}
29+
fn main_0() -> i32 {
30+
let n: Value<node> = <Value<node>>::default();
31+
(*(*n.borrow()).next.borrow_mut()) = Default::default();
32+
(*(*(*n.borrow()).x.borrow()).bytes.borrow_mut())[(0) as usize] = 171_u8;
33+
assert!((((*(*(*n.borrow()).x.borrow()).bytes.borrow())[(0) as usize] as i32) == 171));
34+
return 0;
35+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
#[derive()]
10+
pub union node_anon_10_3 {
11+
pub bytes: Value<Box<[u8]>>,
12+
pub aligner: Value<AnyPtr>,
13+
}
14+
impl Default for node_anon_10_3 {
15+
fn default() -> Self {
16+
unsafe { std::mem::zeroed() }
17+
}
18+
}
19+
impl ByteRepr for node_anon_10_3 {}
20+
#[derive(Default)]
21+
pub struct node {
22+
pub len: Value<u64>,
23+
pub x: Value<node_anon_10_3>,
24+
}
25+
impl ByteRepr for node {}
26+
pub fn main() {
27+
std::process::exit(main_0());
28+
}
29+
fn main_0() -> i32 {
30+
let tail_size: Value<u64> = Rc::new(RefCell::new(32_u64));
31+
let n: Value<Ptr<node>> = Rc::new(RefCell::new(
32+
({
33+
let ___size: u64 =
34+
(::std::mem::size_of::<node>() as u64 as u64).wrapping_add((*tail_size.borrow()));
35+
malloc_0(___size)
36+
})
37+
.cast::<node>()
38+
.expect("ub:wrong type"),
39+
));
40+
(*(*(*n.borrow()).upgrade().deref()).len.borrow_mut()) = (*tail_size.borrow());
41+
let i: Value<u64> = Rc::new(RefCell::new(0_u64));
42+
'loop_: while ((*i.borrow()) < (*tail_size.borrow())) {
43+
let __rhs = ((((*i.borrow()) & 255_u64) as u64) as u8);
44+
(*(*(*(*n.borrow()).upgrade().deref()).x.borrow())
45+
.bytes
46+
.borrow_mut())[(*i.borrow()) as usize] = __rhs;
47+
(*i.borrow_mut()).postfix_inc();
48+
}
49+
let i: Value<u64> = Rc::new(RefCell::new(0_u64));
50+
'loop_: while ((*i.borrow()) < (*tail_size.borrow())) {
51+
assert!({
52+
let _lhs = ((*(*(*(*n.borrow()).upgrade().deref()).x.borrow())
53+
.bytes
54+
.borrow())[(*i.borrow()) as usize] as i32);
55+
_lhs == (((((*i.borrow()) & 255_u64) as u64) as u8) as i32)
56+
});
57+
(*i.borrow_mut()).postfix_inc();
58+
}
59+
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(
60+
(((*(*(*n.borrow()).upgrade().deref()).x.borrow())
61+
.bytes
62+
.as_pointer() as Ptr<u8>)
63+
.offset(10 as isize)),
64+
));
65+
assert!(((((*p.borrow()).read()) as i32) == 10));
66+
(*p.borrow()).write(170_u8);
67+
assert!(
68+
(((*(*(*(*n.borrow()).upgrade().deref()).x.borrow())
69+
.bytes
70+
.borrow())[(10) as usize] as i32)
71+
== 170)
72+
);
73+
({
74+
let ___ptr: AnyPtr = ((*n.borrow()).clone() as Ptr<node>).to_any();
75+
free_1(___ptr)
76+
});
77+
return 0;
78+
}

0 commit comments

Comments
 (0)