Skip to content

Commit 4965fe1

Browse files
committed
Add more va_arg tests
1 parent e2e7caf commit 4965fe1

36 files changed

Lines changed: 1320 additions & 38 deletions
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::AsFd;
9+
use std::rc::{Rc, Weak};
10+
pub fn extract_nth_0(n: i32, ap: VaList) -> i32 {
11+
let n: Value<i32> = Rc::new(RefCell::new(n));
12+
let ap: Value<VaList> = Rc::new(RefCell::new(ap));
13+
let i: Value<i32> = Rc::new(RefCell::new(0));
14+
'loop_: while ((*i.borrow()) < (*n.borrow())) {
15+
(*ap.borrow_mut()).arg::<i32>();
16+
(*i.borrow_mut()).postfix_inc();
17+
}
18+
return ((*ap.borrow_mut()).arg::<i32>()).clone();
19+
}
20+
pub fn middle_layer_1(n: i32, ap: VaList) -> i32 {
21+
let n: Value<i32> = Rc::new(RefCell::new(n));
22+
let ap: Value<VaList> = Rc::new(RefCell::new(ap));
23+
return ({
24+
let _n: i32 = (*n.borrow());
25+
let _ap: VaList = (*ap.borrow()).clone();
26+
extract_nth_0(_n, _ap)
27+
});
28+
}
29+
pub fn top_level_2(n: i32, args: &[VaArg]) -> i32 {
30+
let n: Value<i32> = Rc::new(RefCell::new(n));
31+
let ap: Value<VaList> = Rc::new(RefCell::new(<VaList>::default()));
32+
(*ap.borrow_mut()) = VaList::new(args);
33+
let result: Value<i32> = Rc::new(RefCell::new(
34+
({
35+
let _n: i32 = (*n.borrow());
36+
let _ap: VaList = (*ap.borrow()).clone();
37+
middle_layer_1(_n, _ap)
38+
}),
39+
));
40+
return (*result.borrow());
41+
}
42+
pub fn main() {
43+
std::process::exit(main_0());
44+
}
45+
fn main_0() -> i32 {
46+
assert!(
47+
(({
48+
let _n: i32 = 2;
49+
top_level_2(_n, &[100.into(), 200.into(), 300.into(), 400.into()])
50+
}) == 300)
51+
);
52+
assert!(
53+
(({
54+
let _n: i32 = 0;
55+
top_level_2(_n, &[42.into(), 99.into()])
56+
}) == 42)
57+
);
58+
assert!(
59+
(({
60+
let _n: i32 = 3;
61+
top_level_2(_n, &[1.into(), 2.into(), 3.into(), 4.into()])
62+
}) == 4)
63+
);
64+
return 0;
65+
}

tests/unit/out/refcount/va_arg_concat.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,23 @@ pub fn main() {
2727
std::process::exit(main_0());
2828
}
2929
fn main_0() -> i32 {
30-
return (({
31-
let _first: i32 = 1;
32-
sum_ints_0(_first, &[2.into(), 3.into(), 4.into(), 0.into()])
33-
}) - 10);
30+
assert!(
31+
(({
32+
let _first: i32 = 1;
33+
sum_ints_0(_first, &[2.into(), 3.into(), 4.into(), 0.into()])
34+
}) == 10)
35+
);
36+
assert!(
37+
(({
38+
let _first: i32 = 100;
39+
sum_ints_0(_first, &[0.into()])
40+
}) == 100)
41+
);
42+
assert!(
43+
(({
44+
let _first: i32 = 5;
45+
sum_ints_0(_first, &[5.into(), 5.into(), 5.into(), 5.into(), 0.into()])
46+
}) == 25)
47+
);
48+
return 0;
3449
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::AsFd;
9+
use std::rc::{Rc, Weak};
10+
pub fn conditional_log_0(verbose: i32, fmt: Ptr<u8>, args: &[VaArg]) -> i32 {
11+
let verbose: Value<i32> = Rc::new(RefCell::new(verbose));
12+
let fmt: Value<Ptr<u8>> = Rc::new(RefCell::new(fmt));
13+
if ((*verbose.borrow()) != 0) {
14+
let ap: Value<VaList> = Rc::new(RefCell::new(<VaList>::default()));
15+
(*ap.borrow_mut()) = VaList::new(args);
16+
let result: Value<i32> = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::<i32>()).clone()));
17+
return (*result.borrow());
18+
}
19+
return -1_i32;
20+
}
21+
pub fn main() {
22+
std::process::exit(main_0());
23+
}
24+
fn main_0() -> i32 {
25+
assert!(
26+
(({
27+
let _verbose: i32 = 1;
28+
let _fmt: Ptr<u8> = Ptr::from_string_literal("%d");
29+
conditional_log_0(_verbose, _fmt, &[42.into()])
30+
}) == 42)
31+
);
32+
assert!(
33+
(({
34+
let _verbose: i32 = 0;
35+
let _fmt: Ptr<u8> = Ptr::from_string_literal("%d");
36+
conditional_log_0(_verbose, _fmt, &[99.into()])
37+
}) == -1_i32)
38+
);
39+
return 0;
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::AsFd;
9+
use std::rc::{Rc, Weak};
10+
pub fn sum_with_copy_0(count: i32, args: &[VaArg]) -> i32 {
11+
let count: Value<i32> = Rc::new(RefCell::new(count));
12+
let ap: Value<VaList> = Rc::new(RefCell::new(<VaList>::default()));
13+
let aq: Value<VaList> = Rc::new(RefCell::new(<VaList>::default()));
14+
(*ap.borrow_mut()) = VaList::new(args);
15+
(*aq.borrow_mut()) = (*ap.borrow_mut()).clone();
16+
let sum1: Value<i32> = Rc::new(RefCell::new(0));
17+
let i: Value<i32> = Rc::new(RefCell::new(0));
18+
'loop_: while ((*i.borrow()) < (*count.borrow())) {
19+
(*sum1.borrow_mut()) += ((*ap.borrow_mut()).arg::<i32>()).clone();
20+
(*i.borrow_mut()).postfix_inc();
21+
}
22+
let sum2: Value<i32> = Rc::new(RefCell::new(0));
23+
let i: Value<i32> = Rc::new(RefCell::new(0));
24+
'loop_: while ((*i.borrow()) < (*count.borrow())) {
25+
(*sum2.borrow_mut()) += ((*aq.borrow_mut()).arg::<i32>()).clone();
26+
(*i.borrow_mut()).postfix_inc();
27+
}
28+
assert!(((*sum1.borrow()) == (*sum2.borrow())));
29+
return ((*sum1.borrow()) + (*sum2.borrow()));
30+
}
31+
pub fn main() {
32+
std::process::exit(main_0());
33+
}
34+
fn main_0() -> i32 {
35+
assert!(
36+
(({
37+
let _count: i32 = 3;
38+
sum_with_copy_0(_count, &[10.into(), 20.into(), 30.into()])
39+
}) == 120)
40+
);
41+
return 0;
42+
}

tests/unit/out/refcount/va_arg_forward.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,23 @@ pub fn main() {
3535
std::process::exit(main_0());
3636
}
3737
fn main_0() -> i32 {
38-
return (({
39-
let _count: i32 = 3;
40-
outer_1(_count, &[10.into(), 20.into(), 30.into()])
41-
}) - 60);
38+
assert!(
39+
(({
40+
let _count: i32 = 3;
41+
outer_1(_count, &[10.into(), 20.into(), 30.into()])
42+
}) == 60)
43+
);
44+
assert!(
45+
(({
46+
let _count: i32 = 1;
47+
outer_1(_count, &[42.into()])
48+
}) == 42)
49+
);
50+
assert!(
51+
(({
52+
let _count: i32 = 0;
53+
outer_1(_count, &[])
54+
}) == 0)
55+
);
56+
return 0;
4257
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::AsFd;
9+
use std::rc::{Rc, Weak};
10+
pub fn mixed_args_0(count: i32, args: &[VaArg]) -> i32 {
11+
let count: Value<i32> = Rc::new(RefCell::new(count));
12+
let ap: Value<VaList> = Rc::new(RefCell::new(<VaList>::default()));
13+
(*ap.borrow_mut()) = VaList::new(args);
14+
let total: Value<i32> = Rc::new(RefCell::new(0));
15+
let i: Value<i32> = Rc::new(RefCell::new(0));
16+
'loop_: while ((*i.borrow()) < (*count.borrow())) {
17+
let tag: Value<i32> = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::<i32>()).clone()));
18+
if ((*tag.borrow()) == 0) {
19+
(*total.borrow_mut()) += ((*ap.borrow_mut()).arg::<i32>()).clone();
20+
} else {
21+
let ptr: Value<Ptr<i32>> =
22+
Rc::new(RefCell::new(((*ap.borrow_mut()).arg::<Ptr<i32>>()).clone()));
23+
let __rhs = ((*ptr.borrow()).read());
24+
(*total.borrow_mut()) += __rhs;
25+
}
26+
(*i.borrow_mut()).postfix_inc();
27+
}
28+
return (*total.borrow());
29+
}
30+
pub fn main() {
31+
std::process::exit(main_0());
32+
}
33+
fn main_0() -> i32 {
34+
let x: Value<i32> = Rc::new(RefCell::new(100));
35+
assert!(
36+
(({
37+
let _count: i32 = 3;
38+
mixed_args_0(
39+
_count,
40+
&[
41+
0.into(),
42+
10.into(),
43+
1.into(),
44+
(x.as_pointer()).into(),
45+
0.into(),
46+
20.into(),
47+
],
48+
)
49+
}) == 130)
50+
);
51+
let y: Value<i32> = Rc::new(RefCell::new(50));
52+
assert!(
53+
(({
54+
let _count: i32 = 1;
55+
mixed_args_0(_count, &[1.into(), (y.as_pointer()).into()])
56+
}) == 50)
57+
);
58+
assert!(
59+
(({
60+
let _count: i32 = 2;
61+
mixed_args_0(_count, &[0.into(), 5.into(), 0.into(), 3.into()])
62+
}) == 8)
63+
);
64+
return 0;
65+
}

tests/unit/out/refcount/va_arg_mixed_types.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ use std::io::Seek;
77
use std::io::{Read, Write};
88
use std::os::fd::AsFd;
99
use std::rc::{Rc, Weak};
10-
pub fn sum_mixed_0(count: i32, args: &[VaArg]) -> f64 {
10+
pub fn sum_mixed_0(count: i32, args: &[VaArg]) -> i32 {
1111
let count: Value<i32> = Rc::new(RefCell::new(count));
1212
let ap: Value<VaList> = Rc::new(RefCell::new(<VaList>::default()));
1313
(*ap.borrow_mut()) = VaList::new(args);
14-
let total: Value<f64> = Rc::new(RefCell::new(0_f64));
14+
let total: Value<i32> = Rc::new(RefCell::new(0));
1515
let i: Value<i32> = Rc::new(RefCell::new(0));
1616
'loop_: while ((*i.borrow()) < (*count.borrow())) {
17-
(*total.borrow_mut()) += ((*ap.borrow_mut()).arg::<f64>()).clone();
17+
let tag: Value<i32> = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::<i32>()).clone()));
18+
if ((*tag.borrow()) == 0) {
19+
(*total.borrow_mut()) += ((*ap.borrow_mut()).arg::<i32>()).clone();
20+
} else if ((*tag.borrow()) == 1) {
21+
(*total.borrow_mut()) += ((*ap.borrow_mut()).arg::<f64>() as i32).clone();
22+
} else {
23+
let val: Value<i64> = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::<i64>()).clone()));
24+
(*total.borrow_mut()) += ((*val.borrow()) as i32);
25+
}
1826
(*i.borrow_mut()).postfix_inc();
1927
}
2028
return (*total.borrow());
@@ -23,9 +31,33 @@ pub fn main() {
2331
std::process::exit(main_0());
2432
}
2533
fn main_0() -> i32 {
26-
return ((({
27-
let _count: i32 = 3;
28-
sum_mixed_0(_count, &[1.5E+0.into(), 2.5E+0.into(), 3.0E+0.into()])
29-
}) as i32)
30-
- 7);
34+
assert!(
35+
(({
36+
let _count: i32 = 3;
37+
sum_mixed_0(
38+
_count,
39+
&[
40+
0.into(),
41+
10.into(),
42+
1.into(),
43+
2.05E+1.into(),
44+
2.into(),
45+
30_i64.into(),
46+
],
47+
)
48+
}) == 60)
49+
);
50+
assert!(
51+
(({
52+
let _count: i32 = 1;
53+
sum_mixed_0(_count, &[0.into(), 42.into()])
54+
}) == 42)
55+
);
56+
assert!(
57+
(({
58+
let _count: i32 = 2;
59+
sum_mixed_0(_count, &[1.into(), 3.7E+0.into(), 2.into(), 100_i64.into()])
60+
}) == 103)
61+
);
62+
return 0;
3163
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::AsFd;
9+
use std::rc::{Rc, Weak};
10+
pub fn logf_impl_0(fmt: Ptr<u8>, ap: VaList) -> i32 {
11+
let fmt: Value<Ptr<u8>> = Rc::new(RefCell::new(fmt));
12+
let ap: Value<VaList> = Rc::new(RefCell::new(ap));
13+
return {
14+
let _lhs = ((*ap.borrow_mut()).arg::<i32>()).clone();
15+
_lhs + ((*ap.borrow_mut()).arg::<i32>()).clone()
16+
};
17+
}
18+
pub fn logf_1(fmt: Ptr<u8>, args: &[VaArg]) -> i32 {
19+
let fmt: Value<Ptr<u8>> = Rc::new(RefCell::new(fmt));
20+
let ap: Value<VaList> = Rc::new(RefCell::new(<VaList>::default()));
21+
(*ap.borrow_mut()) = VaList::new(args);
22+
let result: Value<i32> = Rc::new(RefCell::new(
23+
({
24+
let _fmt: Ptr<u8> = (*fmt.borrow()).clone();
25+
let _ap: VaList = (*ap.borrow()).clone();
26+
logf_impl_0(_fmt, _ap)
27+
}),
28+
));
29+
return (*result.borrow());
30+
}
31+
pub fn main() {
32+
std::process::exit(main_0());
33+
}
34+
fn main_0() -> i32 {
35+
assert!(
36+
(({
37+
let _fmt: Ptr<u8> = Ptr::from_string_literal("hello %d %d");
38+
logf_1(_fmt, &[10.into(), 32.into()])
39+
}) == 42)
40+
);
41+
assert!(
42+
(({
43+
let _fmt: Ptr<u8> = Ptr::from_string_literal("x %d %d");
44+
logf_1(_fmt, &[1.into(), 2.into()])
45+
}) == 3)
46+
);
47+
return 0;
48+
}

0 commit comments

Comments
 (0)