|
| 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 | +} |
0 commit comments