Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 93 additions & 26 deletions tests/unit/out/refcount/union_addrof_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,80 @@ impl Default for record {
}
}
}
impl ByteRepr for record {}
#[derive()]
pub union anon_0 {
pub h: Value<record>,
pub raw_: Value<Box<[u8]>>,
impl ByteRepr for record {
fn byte_size() -> usize {
16
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.code.borrow()).to_bytes(&mut buf[0..2]);
(*self.lo.borrow()).to_bytes(&mut buf[2..4]);
(*self.hi.borrow()).to_bytes(&mut buf[4..8]);
(*self.pad.borrow()).to_bytes(&mut buf[8..16]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
code: Rc::new(RefCell::new(<u16>::from_bytes(&buf[0..2]))),
lo: Rc::new(RefCell::new(<u16>::from_bytes(&buf[2..4]))),
hi: Rc::new(RefCell::new(<u32>::from_bytes(&buf[4..8]))),
pad: Rc::new(RefCell::new(<Box<[u8]>>::from_bytes(&buf[8..16]))),
}
}
}
pub struct anon_0 {
__bytes: Value<Box<[u8]>>,
}
impl anon_0 {
pub fn h(&self) -> Ptr<record> {
(self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast()
}
pub fn raw_(&self) -> Ptr<Box<[u8]>> {
(self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast()
}
}
impl Clone for anon_0 {
fn clone(&self) -> Self {
anon_0 {
__bytes: Rc::new(RefCell::new(self.__bytes.borrow().clone())),
}
}
}
impl Default for anon_0 {
fn default() -> Self {
anon_0 {
__bytes: Rc::new(RefCell::new(Box::from([0u8; 128]))),
}
}
}
impl ByteRepr for anon_0 {
fn byte_size() -> usize {
128
}
fn to_bytes(&self, buf: &mut [u8]) {
buf.copy_from_slice(&self.__bytes.borrow());
}
fn from_bytes(buf: &[u8]) -> Self {
anon_0 {
__bytes: Rc::new(RefCell::new(Box::from(buf))),
}
}
}
impl ByteRepr for anon_0 {}
#[derive(Default)]
pub struct Container {
pub view: Value<anon_0>,
}
impl ByteRepr for Container {}
impl ByteRepr for Container {
fn byte_size() -> usize {
128
}
fn to_bytes(&self, buf: &mut [u8]) {
(*self.view.borrow()).to_bytes(&mut buf[0..128]);
}
fn from_bytes(buf: &[u8]) -> Self {
Self {
view: Rc::new(RefCell::new(<anon_0>::from_bytes(&buf[0..128]))),
}
}
}
pub fn fill_1(out: AnyPtr, cap: usize) {
let out: Value<AnyPtr> = Rc::new(RefCell::new(out));
let cap: Value<usize> = Rc::new(RefCell::new(cap));
Expand Down Expand Up @@ -67,11 +129,11 @@ pub fn fill_1(out: AnyPtr, cap: usize) {
(*src.borrow_mut())[(6) as usize] = 0_u8;
(*src.borrow_mut())[(7) as usize] = 1_u8;
let n: Value<usize> = Rc::new(RefCell::new(
if (((::std::mem::size_of::<[u8; 16]>() < (*cap.borrow())) as i32) != 0) {
::std::mem::size_of::<[u8; 16]>()
(if (((::std::mem::size_of::<[u8; 16]>() < (*cap.borrow())) as i32) != 0) {
(::std::mem::size_of::<[u8; 16]>() as u64)
} else {
(*cap.borrow())
},
((*cap.borrow()) as u64)
} as usize),
));
{
(*out.borrow()).memcpy(
Expand All @@ -89,42 +151,47 @@ fn main_0() -> i32 {
{
((c.as_pointer()) as Ptr<Container>)
.to_any()
.memset((0) as u8, ::std::mem::size_of::<Container>() as usize);
.memset((0) as u8, 128usize as usize);
((c.as_pointer()) as Ptr<Container>).to_any().clone()
};
({
let _out: AnyPtr = ((*c.borrow()).view.as_pointer()).to_any();
let _cap: usize = ::std::mem::size_of::<anon_0>();
let _cap: usize = 128usize;
fill_1(_out, _cap)
});
assert!(
(((((*(*(*(*c.borrow()).view.borrow()).h.borrow()).code.borrow()) as i32) == 2) as i32)
(((((*(*(*(*c.borrow()).view.borrow()).h().upgrade().deref())
.code
.borrow()) as i32)
== 2) as i32)
!= 0)
);
assert!(
((((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer())
.to_strong()
.as_pointer() as Ptr::<u8>)
.offset((0) as isize)
.read()) as i32)
((((((((*(*(*c.borrow()).view.borrow()).h().upgrade().deref())
.lo
.as_pointer())
.reinterpret_cast::<u8>())
.offset((0) as isize)
.read()) as i32)
== 0) as i32)
!= 0)
);
assert!(
((((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer())
.to_strong()
.as_pointer() as Ptr::<u8>)
.offset((1) as isize)
.read()) as i32)
((((((((*(*(*c.borrow()).view.borrow()).h().upgrade().deref())
.lo
.as_pointer())
.reinterpret_cast::<u8>())
.offset((1) as isize)
.read()) as i32)
== 80) as i32)
!= 0)
);
assert!(
(((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(0) as usize] as i32) == 2) as i32)
((((((*(*c.borrow()).view.borrow()).raw_().read())[(0) as usize] as i32) == 2) as i32)
!= 0)
);
assert!(
((((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(3) as usize] as u8) as i32) == 80)
(((((((*(*c.borrow()).view.borrow()).raw_().read())[(3) as usize] as u8) as i32) == 80)
as i32)
!= 0)
);
Expand Down
14 changes: 6 additions & 8 deletions tests/unit/out/refcount/union_cross_arm_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,17 @@ fn main_0() -> i32 {
.borrow_mut()) = 8080_u16;
assert!(
((((((((*(*c.borrow()).u.borrow()).raw_().reinterpret_cast::<u8>())
.to_strong()
.as_pointer() as Ptr::<u8>)
.offset((2) as isize)
.read()) as i32)
.reinterpret_cast::<u8>())
.offset((2) as isize)
.read()) as i32)
== 144) as i32)
!= 0)
);
assert!(
((((((((*(*c.borrow()).u.borrow()).raw_().reinterpret_cast::<u8>())
.to_strong()
.as_pointer() as Ptr::<u8>)
.offset((3) as isize)
.read()) as i32)
.reinterpret_cast::<u8>())
.offset((3) as isize)
.read()) as i32)
== 31) as i32)
!= 0)
);
Expand Down
Loading
Loading