Skip to content

Commit d725a50

Browse files
committed
Update tests
1 parent 697f71a commit d725a50

14 files changed

Lines changed: 213 additions & 12 deletions

tests/unit/out/refcount/bool_printing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ fn main_0() -> i32 {
2323
write!(
2424
libcc2rs::cout(),
2525
"{:}\n",
26-
((((*i1.borrow()) != (*i2.borrow())) as bool) as u8),
26+
(((*i1.borrow()) != (*i2.borrow())) as u8),
2727
);
2828
write!(
2929
libcc2rs::cout(),
3030
"{:}\n",
31-
((((*i1.borrow()) == (*i2.borrow())) as bool) as u8),
31+
(((*i1.borrow()) == (*i2.borrow())) as u8),
3232
);
3333
write!(libcc2rs::cout(), "{:}\n", (({ foo_0() }) as u8),);
3434
write!(libcc2rs::cout(), "{:}\n", (({ bar_1() }) as u8),);

tests/unit/out/refcount/continue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ fn main_0() -> i32 {
3535
'loop_: while ((*k2.borrow()) < 5) {
3636
let k3: Value<i32> = Rc::new(RefCell::new(0));
3737
'loop_: while ((*k3.borrow()) < 5) {
38-
if ((((((*k1.borrow()) + (*k2.borrow())) + (*k3.borrow())) as i32) % 2) == 0) {
38+
if (((((*k1.borrow()) + (*k2.borrow())) + (*k3.borrow())) % 2) == 0) {
3939
(*k3.borrow_mut()).postfix_inc();
4040
continue 'loop_;
4141
}
4242
(*out.borrow_mut()).prefix_inc();
4343
(*k3.borrow_mut()).postfix_inc();
4444
}
45-
if (((((*k1.borrow()) + (*k2.borrow())) as i32) % 2) == 0) {
45+
if ((((*k1.borrow()) + (*k2.borrow())) % 2) == 0) {
4646
(*k2.borrow_mut()).postfix_inc();
4747
continue 'loop_;
4848
}

tests/unit/out/refcount/reinterpret_cast_oob_read.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ fn main_0() -> i32 {
1515
let x: Value<u8> = Rc::new(RefCell::new(
1616
((*bytes.borrow()).offset((4) as isize).read()),
1717
));
18+
let _ = (*x.borrow_mut()).clone();
1819
return 0;
1920
}

tests/unit/out/refcount/reinterpret_cast_undersize.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ fn main_0() -> i32 {
1313
let b: Value<u8> = Rc::new(RefCell::new(66_u8));
1414
let p: Value<Ptr<u32>> = Rc::new(RefCell::new((b.as_pointer()).reinterpret_cast::<u32>()));
1515
let val: Value<u32> = Rc::new(RefCell::new(((*p.borrow()).read())));
16+
let _ = (*val.borrow_mut()).clone();
1617
return 0;
1718
}

tests/unit/out/refcount/string_escape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ fn main_0() -> i32 {
2323
);
2424
let i: Value<i32> = Rc::new(RefCell::new(0));
2525
'loop_: while ((*i.borrow())
26-
< ((((::std::mem::size_of::<[u8; 40]>() as u64 as u64)
27-
.wrapping_div(::std::mem::size_of::<u8>() as u64 as u64)) as u64) as i32))
26+
< (((::std::mem::size_of::<[u8; 40]>() as u64 as u64)
27+
.wrapping_div(::std::mem::size_of::<u8>() as u64 as u64)) as i32))
2828
{
2929
assert!({
3030
let _lhs = (((*special.borrow()).offset((*i.borrow()) as isize).read()) as i32);

tests/unit/out/refcount/va_arg_printf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::rc::{Rc, Weak};
99
pub fn logf_impl_0(fmt: Ptr<u8>, ap: VaList) -> i32 {
1010
let fmt: Value<Ptr<u8>> = Rc::new(RefCell::new(fmt));
1111
let ap: Value<VaList> = Rc::new(RefCell::new(ap));
12+
let _ = (*fmt.borrow());
1213
return {
1314
let _lhs = ((*ap.borrow_mut()).arg::<i32>()).clone();
1415
_lhs + ((*ap.borrow_mut()).arg::<i32>()).clone()
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
pub fn unused_param_0(x: i32) {
10+
let x: Value<i32> = Rc::new(RefCell::new(x));
11+
let _ = (*x.borrow_mut()).clone();
12+
}
13+
thread_local!(
14+
pub static side_effect_counter: Value<i32> = Rc::new(RefCell::new(0));
15+
);
16+
pub fn bump_and_return_1() -> i32 {
17+
(*side_effect_counter.with(Value::clone).borrow_mut()).prefix_inc();
18+
return (*side_effect_counter.with(Value::clone).borrow());
19+
}
20+
#[derive(Default)]
21+
pub struct Holder {
22+
pub field: Value<i32>,
23+
}
24+
impl Clone for Holder {
25+
fn clone(&self) -> Self {
26+
let mut this = Self {
27+
field: Rc::new(RefCell::new((*self.field.borrow()))),
28+
};
29+
this
30+
}
31+
}
32+
impl ByteRepr for Holder {}
33+
pub fn main() {
34+
std::process::exit(main_0());
35+
}
36+
fn main_0() -> i32 {
37+
({
38+
let _x: i32 = 42;
39+
unused_param_0(_x)
40+
});
41+
let y: Value<i32> = Rc::new(RefCell::new(5));
42+
let _ = (*y.borrow_mut()).clone();
43+
let z: Value<i32> = Rc::new(RefCell::new({
44+
let _ = (*y.borrow_mut()).clone();
45+
7
46+
}));
47+
assert!(((*z.borrow()) == 7));
48+
let counter: Value<i32> = Rc::new(RefCell::new(0));
49+
let w: Value<i32> = Rc::new(RefCell::new({
50+
let _ = (*counter.borrow_mut()).clone();
51+
(*counter.borrow_mut()) = 3;
52+
(*counter.borrow())
53+
}));
54+
assert!(((*w.borrow()) == 3));
55+
assert!(((*counter.borrow()) == 3));
56+
let _ = ({ bump_and_return_1() });
57+
assert!(((*side_effect_counter.with(Value::clone).borrow()) == 1));
58+
let v: Value<i32> = Rc::new(RefCell::new({
59+
let _ = ({ bump_and_return_1() });
60+
99
61+
}));
62+
assert!(((*side_effect_counter.with(Value::clone).borrow()) == 2));
63+
assert!(((*v.borrow()) == 99));
64+
let _ = 0;
65+
let _ = (0);
66+
let _ = (*y.borrow_mut()).clone();
67+
{
68+
let _ = 0;
69+
};
70+
{
71+
let _ = (*y.borrow_mut()).clone();
72+
};
73+
let err: Value<i32> = Rc::new(RefCell::new(0));
74+
{
75+
let _ = ((*err.borrow_mut()) = 42).clone();
76+
};
77+
assert!(((*err.borrow()) == 42));
78+
let chosen: Value<i32> = Rc::new(RefCell::new({
79+
let _ = ((*err.borrow_mut()) = 7).clone();
80+
123
81+
}));
82+
assert!(((*err.borrow()) == 7));
83+
assert!(((*chosen.borrow()) == 123));
84+
let _ = bump_and_return_1.clone();
85+
assert!(((*side_effect_counter.with(Value::clone).borrow()) == 2));
86+
let _ = (FnPtr::<fn() -> i32>::new(bump_and_return_1));
87+
assert!(((*side_effect_counter.with(Value::clone).borrow()) == 2));
88+
let _ = ((FnPtr::<fn() -> i32>::new(bump_and_return_1)).cast::<fn() -> i32>(None));
89+
assert!(((*side_effect_counter.with(Value::clone).borrow()) == 2));
90+
let storage: Value<i32> = Rc::new(RefCell::new(11));
91+
let p: Value<Ptr<i32>> = Rc::new(RefCell::new((storage.as_pointer())));
92+
let _ = ((*p.borrow()).read()).clone();
93+
let arr: Value<Box<[i32]>> = Rc::new(RefCell::new(Box::new([1, 2, 3])));
94+
let _ = ((*arr.borrow_mut())[(1) as usize]).clone();
95+
let h: Value<Holder> = Rc::new(RefCell::new(Holder {
96+
field: Rc::new(RefCell::new(17)),
97+
}));
98+
let _ = (*(*h.borrow()).field.borrow_mut()).clone();
99+
let hp: Value<Ptr<Holder>> = Rc::new(RefCell::new((h.as_pointer())));
100+
let _ = (*(*(*hp.borrow()).upgrade().deref()).field.borrow_mut()).clone();
101+
return 0;
102+
}

tests/unit/out/unsafe/bool_printing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ unsafe fn main_0() -> i32 {
5151
.into_raw_fd(),
5252
),
5353
"{:}\n",
54-
((((i1) != (i2)) as bool) as u8),
54+
(((i1) != (i2)) as u8),
5555
);
5656
write!(
5757
std::fs::File::from_raw_fd(
@@ -62,7 +62,7 @@ unsafe fn main_0() -> i32 {
6262
.into_raw_fd(),
6363
),
6464
"{:}\n",
65-
((((i1) == (i2)) as bool) as u8),
65+
(((i1) == (i2)) as u8),
6666
);
6767
write!(
6868
std::fs::File::from_raw_fd(

tests/unit/out/unsafe/continue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ unsafe fn main_0() -> i32 {
3737
'loop_: while ((k2) < (5)) {
3838
let mut k3: i32 = 0;
3939
'loop_: while ((k3) < (5)) {
40-
if ((((((k1) + (k2)) + (k3)) as i32) % (2)) == (0)) {
40+
if (((((k1) + (k2)) + (k3)) % (2)) == (0)) {
4141
k3.postfix_inc();
4242
continue 'loop_;
4343
}
4444
out.prefix_inc();
4545
k3.postfix_inc();
4646
}
47-
if (((((k1) + (k2)) as i32) % (2)) == (0)) {
47+
if ((((k1) + (k2)) % (2)) == (0)) {
4848
k2.postfix_inc();
4949
continue 'loop_;
5050
}

tests/unit/out/unsafe/reinterpret_cast_oob_read.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ unsafe fn main_0() -> i32 {
1515
let mut val: u32 = 67305985_u32;
1616
let mut bytes: *mut u8 = ((&mut val as *mut u32) as *mut u8);
1717
let mut x: u8 = (*bytes.offset((4) as isize));
18+
let _ = x.clone();
1819
return 0;
1920
}

0 commit comments

Comments
 (0)