Skip to content

Commit 70bf770

Browse files
committed
Fix expected output
1 parent 892566f commit 70bf770

5 files changed

Lines changed: 344 additions & 36 deletions

File tree

tests/unit/out/refcount/union_addrof_external.rs

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,80 @@ impl Default for record {
2525
}
2626
}
2727
}
28-
impl ByteRepr for record {}
29-
#[derive()]
30-
pub union anon_0 {
31-
pub h: Value<record>,
32-
pub raw_: Value<Box<[u8]>>,
28+
impl ByteRepr for record {
29+
fn byte_size() -> usize {
30+
16
31+
}
32+
fn to_bytes(&self, buf: &mut [u8]) {
33+
(*self.code.borrow()).to_bytes(&mut buf[0..2]);
34+
(*self.lo.borrow()).to_bytes(&mut buf[2..4]);
35+
(*self.hi.borrow()).to_bytes(&mut buf[4..8]);
36+
(*self.pad.borrow()).to_bytes(&mut buf[8..16]);
37+
}
38+
fn from_bytes(buf: &[u8]) -> Self {
39+
Self {
40+
code: Rc::new(RefCell::new(<u16>::from_bytes(&buf[0..2]))),
41+
lo: Rc::new(RefCell::new(<u16>::from_bytes(&buf[2..4]))),
42+
hi: Rc::new(RefCell::new(<u32>::from_bytes(&buf[4..8]))),
43+
pad: Rc::new(RefCell::new(<Box<[u8]>>::from_bytes(&buf[8..16]))),
44+
}
45+
}
46+
}
47+
pub struct anon_0 {
48+
__bytes: Value<Box<[u8]>>,
49+
}
50+
impl anon_0 {
51+
pub fn h(&self) -> Ptr<record> {
52+
(self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast()
53+
}
54+
pub fn raw_(&self) -> Ptr<Box<[u8]>> {
55+
(self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast()
56+
}
57+
}
58+
impl Clone for anon_0 {
59+
fn clone(&self) -> Self {
60+
anon_0 {
61+
__bytes: Rc::new(RefCell::new(self.__bytes.borrow().clone())),
62+
}
63+
}
64+
}
65+
impl Default for anon_0 {
66+
fn default() -> Self {
67+
anon_0 {
68+
__bytes: Rc::new(RefCell::new(Box::from([0u8; 128]))),
69+
}
70+
}
71+
}
72+
impl ByteRepr for anon_0 {
73+
fn byte_size() -> usize {
74+
128
75+
}
76+
fn to_bytes(&self, buf: &mut [u8]) {
77+
buf.copy_from_slice(&self.__bytes.borrow());
78+
}
79+
fn from_bytes(buf: &[u8]) -> Self {
80+
anon_0 {
81+
__bytes: Rc::new(RefCell::new(Box::from(buf))),
82+
}
83+
}
3384
}
34-
impl ByteRepr for anon_0 {}
3585
#[derive(Default)]
3686
pub struct Container {
3787
pub view: Value<anon_0>,
3888
}
39-
impl ByteRepr for Container {}
89+
impl ByteRepr for Container {
90+
fn byte_size() -> usize {
91+
128
92+
}
93+
fn to_bytes(&self, buf: &mut [u8]) {
94+
(*self.view.borrow()).to_bytes(&mut buf[0..128]);
95+
}
96+
fn from_bytes(buf: &[u8]) -> Self {
97+
Self {
98+
view: Rc::new(RefCell::new(<anon_0>::from_bytes(&buf[0..128]))),
99+
}
100+
}
101+
}
40102
pub fn fill_1(out: AnyPtr, cap: usize) {
41103
let out: Value<AnyPtr> = Rc::new(RefCell::new(out));
42104
let cap: Value<usize> = Rc::new(RefCell::new(cap));
@@ -67,11 +129,11 @@ pub fn fill_1(out: AnyPtr, cap: usize) {
67129
(*src.borrow_mut())[(6) as usize] = 0_u8;
68130
(*src.borrow_mut())[(7) as usize] = 1_u8;
69131
let n: Value<usize> = Rc::new(RefCell::new(
70-
if (((::std::mem::size_of::<[u8; 16]>() < (*cap.borrow())) as i32) != 0) {
71-
::std::mem::size_of::<[u8; 16]>()
132+
(if (((::std::mem::size_of::<[u8; 16]>() < (*cap.borrow())) as i32) != 0) {
133+
(::std::mem::size_of::<[u8; 16]>() as u64)
72134
} else {
73-
(*cap.borrow())
74-
},
135+
((*cap.borrow()) as u64)
136+
} as usize),
75137
));
76138
{
77139
(*out.borrow()).memcpy(
@@ -89,42 +151,47 @@ fn main_0() -> i32 {
89151
{
90152
((c.as_pointer()) as Ptr<Container>)
91153
.to_any()
92-
.memset((0) as u8, ::std::mem::size_of::<Container>() as usize);
154+
.memset((0) as u8, 128usize as usize);
93155
((c.as_pointer()) as Ptr<Container>).to_any().clone()
94156
};
95157
({
96158
let _out: AnyPtr = ((*c.borrow()).view.as_pointer()).to_any();
97-
let _cap: usize = ::std::mem::size_of::<anon_0>();
159+
let _cap: usize = 128usize;
98160
fill_1(_out, _cap)
99161
});
100162
assert!(
101-
(((((*(*(*(*c.borrow()).view.borrow()).h.borrow()).code.borrow()) as i32) == 2) as i32)
163+
(((((*(*(*(*c.borrow()).view.borrow()).h().upgrade().deref())
164+
.code
165+
.borrow()) as i32)
166+
== 2) as i32)
102167
!= 0)
103168
);
104169
assert!(
105-
((((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer())
106-
.to_strong()
107-
.as_pointer() as Ptr::<u8>)
108-
.offset((0) as isize)
109-
.read()) as i32)
170+
((((((((*(*(*c.borrow()).view.borrow()).h().upgrade().deref())
171+
.lo
172+
.as_pointer())
173+
.reinterpret_cast::<u8>())
174+
.offset((0) as isize)
175+
.read()) as i32)
110176
== 0) as i32)
111177
!= 0)
112178
);
113179
assert!(
114-
((((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer())
115-
.to_strong()
116-
.as_pointer() as Ptr::<u8>)
117-
.offset((1) as isize)
118-
.read()) as i32)
180+
((((((((*(*(*c.borrow()).view.borrow()).h().upgrade().deref())
181+
.lo
182+
.as_pointer())
183+
.reinterpret_cast::<u8>())
184+
.offset((1) as isize)
185+
.read()) as i32)
119186
== 80) as i32)
120187
!= 0)
121188
);
122189
assert!(
123-
(((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(0) as usize] as i32) == 2) as i32)
190+
((((((*(*c.borrow()).view.borrow()).raw_().read())[(0) as usize] as i32) == 2) as i32)
124191
!= 0)
125192
);
126193
assert!(
127-
((((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(3) as usize] as u8) as i32) == 80)
194+
(((((((*(*c.borrow()).view.borrow()).raw_().read())[(3) as usize] as u8) as i32) == 80)
128195
as i32)
129196
!= 0)
130197
);

tests/unit/out/refcount/union_cross_arm_cast.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,17 @@ fn main_0() -> i32 {
182182
.borrow_mut()) = 8080_u16;
183183
assert!(
184184
((((((((*(*c.borrow()).u.borrow()).raw_().reinterpret_cast::<u8>())
185-
.to_strong()
186-
.as_pointer() as Ptr::<u8>)
187-
.offset((2) as isize)
188-
.read()) as i32)
185+
.reinterpret_cast::<u8>())
186+
.offset((2) as isize)
187+
.read()) as i32)
189188
== 144) as i32)
190189
!= 0)
191190
);
192191
assert!(
193192
((((((((*(*c.borrow()).u.borrow()).raw_().reinterpret_cast::<u8>())
194-
.to_strong()
195-
.as_pointer() as Ptr::<u8>)
196-
.offset((3) as isize)
197-
.read()) as i32)
193+
.reinterpret_cast::<u8>())
194+
.offset((3) as isize)
195+
.read()) as i32)
198196
== 31) as i32)
199197
!= 0)
200198
);

0 commit comments

Comments
 (0)