Skip to content

Commit b6065cf

Browse files
Add coverage for repeated-character string append
Signed-off-by: Perfloop Agent <agent@perfloop.ai> Signed-off-by: Tomás Senart <ts@perfloop.ai>
1 parent e2b679d commit b6065cf

3 files changed

Lines changed: 399 additions & 0 deletions

File tree

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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 append_to_reference_0(s: Ptr<Vec<i8>>) {
10+
{
11+
s.with_mut(|__v: &mut Vec<i8>| __v.pop());
12+
s.with_mut(|__v: &mut Vec<i8>| {
13+
__v.resize(
14+
(*s.upgrade().deref()).len() + (1_usize) as usize,
15+
('r' as i8),
16+
)
17+
});
18+
s.with_mut(|__v: &mut Vec<i8>| __v.push(0));
19+
(*s.upgrade().deref()).clone()
20+
};
21+
}
22+
pub fn main() {
23+
__cpp2rust_init_globals();
24+
std::process::exit(main_0());
25+
}
26+
fn main_0() -> i32 {
27+
let lengths: Value<Box<[usize]>> = Rc::new(RefCell::new(Box::new([
28+
0_usize, 1_usize, 2_usize, 3_usize, 7_usize, 8_usize, 15_usize, 16_usize, 31_usize,
29+
64_usize,
30+
])));
31+
let counts: Value<Box<[usize]>> = Rc::new(RefCell::new(Box::new([
32+
0_usize, 1_usize, 2_usize, 3_usize, 8_usize, 33_usize,
33+
])));
34+
let characters: Value<Box<[i8]>> = Rc::new(RefCell::new(Box::new([
35+
0_i8,
36+
1_i8,
37+
2_i8,
38+
7_i8,
39+
9_i8,
40+
10_i8,
41+
13_i8,
42+
31_i8,
43+
32_i8,
44+
42_i8,
45+
65_i8,
46+
90_i8,
47+
97_i8,
48+
100_i8,
49+
127_i8,
50+
(-128_i32 as i8),
51+
(-127_i32 as i8),
52+
(-64_i32 as i8),
53+
(-2_i32 as i8),
54+
(-1_i32 as i8),
55+
])));
56+
let mut initial: [i8; 5] = [
57+
('a' as i8),
58+
0_i8,
59+
('b' as i8),
60+
(-128_i32 as i8),
61+
(-1_i32 as i8),
62+
];
63+
let mut cases: usize = 0_usize;
64+
'loop_: for length in IterRange::new(
65+
(lengths.as_pointer() as Ptr<usize>),
66+
(lengths.as_pointer() as Ptr<usize>).offset((10_i64) as isize),
67+
) {
68+
let mut length: usize = (length.read());
69+
'loop_: for count in IterRange::new(
70+
(counts.as_pointer() as Ptr<usize>),
71+
(counts.as_pointer() as Ptr<usize>).offset((6_i64) as isize),
72+
) {
73+
let mut count: usize = (count.read());
74+
'loop_: for character in IterRange::new(
75+
(characters.as_pointer() as Ptr<i8>),
76+
(characters.as_pointer() as Ptr<i8>).offset((20_i64) as isize),
77+
) {
78+
let character: Value<i8> = Rc::new(RefCell::new((character.read())));
79+
let mut shrink: i32 = 0;
80+
'loop_: while (shrink < 2) {
81+
let s: Value<Vec<i8>> = Rc::new(RefCell::new(
82+
vec![('x' as i8); (length) as usize]
83+
.iter()
84+
.cloned()
85+
.chain(std::iter::once(0))
86+
.collect(),
87+
));
88+
let mut i: usize = 0_usize;
89+
'loop_: while (i < length) {
90+
let __rhs = initial[((i as u64)
91+
.wrapping_rem((::std::mem::size_of::<[i8; 5]>() as u64)))
92+
as usize];
93+
(*s.borrow_mut())[i] = __rhs;
94+
i.prefix_inc();
95+
}
96+
if (shrink != 0) {
97+
(*s.borrow_mut()).shrink_to_fit();
98+
}
99+
{
100+
(*s.borrow_mut()).pop();
101+
(*s.borrow_mut()).resize(
102+
(*s.borrow()).len() + (count) as usize,
103+
({ (*character.borrow()) }),
104+
);
105+
(*s.borrow_mut()).push(0);
106+
(*s.borrow()).clone()
107+
};
108+
assert!(({ (((*s.borrow()).len() - 1) == (length).wrapping_add(count)) }));
109+
let mut data: Ptr<i8> = s.decay();
110+
let mut i: usize = 0_usize;
111+
'loop_: while (i < (length).wrapping_add(count)) {
112+
assert!(
113+
({
114+
({ ((elem!(data, i).read()) as i32) } == {
115+
((if (i < length) {
116+
initial[((i as u64).wrapping_rem(
117+
(::std::mem::size_of::<[i8; 5]>() as u64),
118+
)) as usize]
119+
} else {
120+
(*character.borrow())
121+
}) as i32)
122+
})
123+
})
124+
);
125+
i.prefix_inc();
126+
}
127+
assert!(({ (((elem!(data, ((*s.borrow()).len() - 1)).read()) as i32) == 0) }));
128+
cases.prefix_inc();
129+
shrink.prefix_inc();
130+
}
131+
}
132+
}
133+
}
134+
let mut unboxed: Vec<i8> = {
135+
let mut __bytes = Ptr::<i8>::from_string_literal(b"a").to_c_bytes();
136+
__bytes.push(0);
137+
__bytes
138+
};
139+
{
140+
unboxed.pop();
141+
unboxed.resize(unboxed.len() + (2_usize) as usize, ('b' as i8));
142+
unboxed.push(0);
143+
unboxed.clone()
144+
};
145+
assert!(
146+
Ptr::<i8>::from_string_literal(b"abb")
147+
.with_c_str(|__s| unboxed[..unboxed.len().saturating_sub(1)] == *__s)
148+
);
149+
let indirect: Value<Vec<i8>> = Rc::new(RefCell::new({
150+
let mut __bytes = Ptr::<i8>::from_string_literal(b"c").to_c_bytes();
151+
__bytes.push(0);
152+
__bytes
153+
}));
154+
({ append_to_reference_0(indirect.as_pointer()) });
155+
assert!(
156+
({
157+
Ptr::<i8>::from_string_literal(b"cr").with_c_str(|__s| {
158+
(*indirect.borrow())[..(*indirect.borrow()).len().saturating_sub(1)] == *__s
159+
})
160+
})
161+
);
162+
let mut pointer: Ptr<Vec<i8>> = (indirect.as_pointer());
163+
{
164+
pointer.with_mut(|__v: &mut Vec<i8>| __v.pop());
165+
pointer.with_mut(|__v: &mut Vec<i8>| {
166+
__v.resize(
167+
(*pointer.upgrade().deref()).len() + (0_usize) as usize,
168+
('\0' as i8),
169+
)
170+
});
171+
pointer.with_mut(|__v: &mut Vec<i8>| __v.push(0));
172+
(*pointer.upgrade().deref()).clone()
173+
};
174+
assert!(
175+
({
176+
Ptr::<i8>::from_string_literal(b"cr").with_c_str(|__s| {
177+
(*indirect.borrow())[..(*indirect.borrow()).len().saturating_sub(1)] == *__s
178+
})
179+
})
180+
);
181+
println!("checked {} appends", cases);
182+
return 0;
183+
}
184+
pub fn __cpp2rust_init_globals() {}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
8+
use std::rc::Rc;
9+
pub unsafe fn append_to_reference_0(s: *mut Vec<libc::c_char>) {
10+
(*s).splice(
11+
(*s).len() - 1..(*s).len() - 1,
12+
::std::vec::from_elem(('r' as libc::c_char), 1_usize as usize),
13+
);
14+
}
15+
pub fn main() {
16+
unsafe {
17+
__cpp2rust_init_globals();
18+
std::process::exit(main_0() as i32);
19+
}
20+
}
21+
unsafe fn main_0() -> i32 {
22+
let lengths: [usize; 10] = [
23+
0_usize, 1_usize, 2_usize, 3_usize, 7_usize, 8_usize, 15_usize, 16_usize, 31_usize,
24+
64_usize,
25+
];
26+
let counts: [usize; 6] = [0_usize, 1_usize, 2_usize, 3_usize, 8_usize, 33_usize];
27+
let characters: [libc::c_char; 20] = [
28+
(0 as libc::c_char),
29+
(1 as libc::c_char),
30+
(2 as libc::c_char),
31+
(7 as libc::c_char),
32+
(9 as libc::c_char),
33+
(10 as libc::c_char),
34+
(13 as libc::c_char),
35+
(31 as libc::c_char),
36+
(32 as libc::c_char),
37+
(42 as libc::c_char),
38+
(65 as libc::c_char),
39+
(90 as libc::c_char),
40+
(97 as libc::c_char),
41+
(100 as libc::c_char),
42+
(127 as libc::c_char),
43+
(-128_i32 as libc::c_char),
44+
(-127_i32 as libc::c_char),
45+
(-64_i32 as libc::c_char),
46+
(-2_i32 as libc::c_char),
47+
(-1_i32 as libc::c_char),
48+
];
49+
let initial: [libc::c_char; 5] = [
50+
('a' as libc::c_char),
51+
(0 as libc::c_char),
52+
('b' as libc::c_char),
53+
(-128_i32 as libc::c_char),
54+
(-1_i32 as libc::c_char),
55+
];
56+
let mut cases: usize = 0_usize;
57+
'loop_: for length in
58+
IterRange::new(lengths.as_ptr(), lengths.as_ptr().offset((10_i64) as isize))
59+
{
60+
let mut length: usize = (*length);
61+
'loop_: for count in
62+
IterRange::new(counts.as_ptr(), counts.as_ptr().offset((6_i64) as isize))
63+
{
64+
let mut count: usize = (*count);
65+
'loop_: for character in IterRange::new(
66+
characters.as_ptr(),
67+
characters.as_ptr().offset((20_i64) as isize),
68+
) {
69+
let mut character: libc::c_char = (*character);
70+
let mut shrink: i32 = 0;
71+
'loop_: while ((shrink) < (2)) {
72+
let mut s: Vec<libc::c_char> = vec![('x' as libc::c_char); (length) as usize]
73+
.iter()
74+
.cloned()
75+
.chain(std::iter::once(0))
76+
.collect();
77+
let mut i: usize = 0_usize;
78+
'loop_: while ((i) < (length)) {
79+
s[(i)] = initial[((i as u64)
80+
.wrapping_rem((::std::mem::size_of::<[libc::c_char; 5]>() as u64)))
81+
as usize];
82+
i.prefix_inc();
83+
}
84+
if (shrink != 0) {
85+
s.shrink_to_fit();
86+
}
87+
s.splice(
88+
s.len() - 1..s.len() - 1,
89+
::std::vec::from_elem(character, count as usize),
90+
);
91+
assert!(((s.len() - 1) == ((length).wrapping_add(count))));
92+
let mut data: *const libc::c_char = (s.as_mut_ptr()).cast_const();
93+
let mut i: usize = 0_usize;
94+
'loop_: while ((i) < ((length).wrapping_add(count))) {
95+
assert!(
96+
(((*data.offset((i) as isize)) as i32)
97+
== ((if ((i) < (length)) {
98+
initial[((i as u64).wrapping_rem(
99+
(::std::mem::size_of::<[libc::c_char; 5]>() as u64),
100+
)) as usize]
101+
} else {
102+
character
103+
}) as i32))
104+
);
105+
i.prefix_inc();
106+
}
107+
assert!((((*data.offset((s.len() - 1) as isize)) as i32) == (0)));
108+
cases.prefix_inc();
109+
shrink.prefix_inc();
110+
}
111+
}
112+
}
113+
}
114+
let mut unboxed: Vec<libc::c_char> = std::slice::from_raw_parts(
115+
c"a".as_ptr(),
116+
(0..).take_while(|&i| *c"a".as_ptr().add(i) != 0).count() + 1,
117+
)
118+
.to_vec();
119+
unboxed.splice(
120+
unboxed.len() - 1..unboxed.len() - 1,
121+
::std::vec::from_elem(('b' as libc::c_char), 2_usize as usize),
122+
);
123+
assert!(
124+
unboxed == {
125+
std::slice::from_raw_parts(
126+
c"abb".as_ptr(),
127+
(0..).take_while(|&i| *c"abb".as_ptr().add(i) != 0).count() + 1,
128+
)
129+
.to_vec()
130+
}
131+
);
132+
let mut indirect: Vec<libc::c_char> = std::slice::from_raw_parts(
133+
c"c".as_ptr(),
134+
(0..).take_while(|&i| *c"c".as_ptr().add(i) != 0).count() + 1,
135+
)
136+
.to_vec();
137+
(unsafe { append_to_reference_0(&mut indirect) });
138+
assert!(
139+
indirect == {
140+
std::slice::from_raw_parts(
141+
c"cr".as_ptr(),
142+
(0..).take_while(|&i| *c"cr".as_ptr().add(i) != 0).count() + 1,
143+
)
144+
.to_vec()
145+
}
146+
);
147+
let mut pointer: *mut Vec<libc::c_char> = (&mut indirect as *mut Vec<libc::c_char>);
148+
(*pointer).splice(
149+
(*pointer).len() - 1..(*pointer).len() - 1,
150+
::std::vec::from_elem(('\0' as libc::c_char), 0_usize as usize),
151+
);
152+
assert!(
153+
indirect == {
154+
std::slice::from_raw_parts(
155+
c"cr".as_ptr(),
156+
(0..).take_while(|&i| *c"cr".as_ptr().add(i) != 0).count() + 1,
157+
)
158+
.to_vec()
159+
}
160+
);
161+
(unsafe {
162+
libc::printf(
163+
c"checked %zu appends\n".as_ptr() as *const libc::c_char,
164+
(cases),
165+
)
166+
});
167+
return 0;
168+
}
169+
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)