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
17 changes: 10 additions & 7 deletions rules/string/tgt_refcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,16 @@ fn f18(a0: Vec<i8>, a1: Ptr<i8>) -> bool {
a1.with_c_str(|__s| a0[..a0.len().saturating_sub(1)] == *__s)
}

// TODO: This should return a0
fn f21(a0: &mut Vec<i8>, a1: usize, a2: i8) -> Vec<i8> {
a0.pop();
let __len = a0.len() + (a1) as usize;
a0.resize(__len, a2);
a0.push(0);
a0.clone()
fn f21(a0: Ptr<Vec<i8>>, a1: usize, a2: i8) -> Ptr<Vec<i8>> {
let __count = a1 as usize;
let __ch = a2;
a0.with_mut(|__v: &mut Vec<i8>| {
__v.pop();
let __len = __v.len() + __count;
__v.resize(__len, __ch);
__v.push(0);
});
a0
}

fn f26(a0: Ptr<Vec<i8>>, a1: usize) -> Ptr<i8> {
Expand Down
9 changes: 5 additions & 4 deletions rules/string/tgt_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ unsafe fn f18(a0: Vec<libc::c_char>, a1: *const libc::c_char) -> bool {
unsafe fn f19(a0: Vec<libc::c_char>) -> usize {
(a0.len() - 1)
}
unsafe fn f21(a0: &mut Vec<libc::c_char>, a1: usize, a2: libc::c_char) {
a0.splice(
a0.len() - 1..a0.len() - 1,
::std::vec::from_elem(a2, a1),
unsafe fn f21(a0: *mut Vec<libc::c_char>, a1: usize, a2: libc::c_char) -> *mut Vec<libc::c_char> {
(*a0).splice(
(*a0).len() - 1..(*a0).len() - 1,
::std::vec::from_elem(a2, a1 as usize),
);
a0
}

unsafe fn f22(a0: Vec<libc::c_char>) -> bool {
Expand Down
103 changes: 79 additions & 24 deletions tests/unit/out/refcount/string_repeat_append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ use std::os::fd::AsFd;
use std::rc::{Rc, Weak};
pub fn append_to_reference_0(s: Ptr<Vec<i8>>) {
{
s.with_mut(|__v: &mut Vec<i8>| __v.pop());
let __len = (*s.upgrade().deref()).len() + (1_usize) as usize;
s.with_mut(|__v: &mut Vec<i8>| __v.resize(__len, ('r' as i8)));
s.with_mut(|__v: &mut Vec<i8>| __v.push(0));
(*s.upgrade().deref()).clone()
let __count = 1_usize as usize;
let __ch = ('r' as i8);
s.with_mut(|__v: &mut Vec<i8>| {
__v.pop();
let __len = __v.len() + __count;
__v.resize(__len, __ch);
__v.push(0);
});
(s).clone()
};
}
pub fn main() {
Expand Down Expand Up @@ -92,11 +96,15 @@ fn main_0() -> i32 {
(*s.borrow_mut()).shrink_to_fit();
}
{
(*s.borrow_mut()).pop();
let __len = (*s.borrow()).len() + (count) as usize;
(*s.borrow_mut()).resize(__len, character);
(*s.borrow_mut()).push(0);
(*s.borrow()).clone()
let __count = count as usize;
let __ch = character;
s.as_pointer().with_mut(|__v: &mut Vec<i8>| {
__v.pop();
let __len = __v.len() + __count;
__v.resize(__len, __ch);
__v.push(0);
});
s.as_pointer()
};
assert!(({ (((*s.borrow()).len() - 1) == (length).wrapping_add(count)) }));
let mut data: Ptr<i8> = s.decay();
Expand Down Expand Up @@ -128,21 +136,28 @@ fn main_0() -> i32 {
}
}
}
let mut unboxed: Vec<i8> = {
let unboxed: Value<Vec<i8>> = Rc::new(RefCell::new({
let mut __bytes = Ptr::<i8>::from_string_literal(b"a").to_c_bytes();
__bytes.push(0);
__bytes
};
}));
{
unboxed.pop();
let __len = unboxed.len() + (2_usize) as usize;
unboxed.resize(__len, ('b' as i8));
unboxed.push(0);
unboxed.clone()
let __count = 2_usize as usize;
let __ch = ('b' as i8);
unboxed.as_pointer().with_mut(|__v: &mut Vec<i8>| {
__v.pop();
let __len = __v.len() + __count;
__v.resize(__len, __ch);
__v.push(0);
});
unboxed.as_pointer()
};
assert!(
Ptr::<i8>::from_string_literal(b"abb")
.with_c_str(|__s| unboxed[..unboxed.len().saturating_sub(1)] == *__s)
({
Ptr::<i8>::from_string_literal(b"abb").with_c_str(|__s| {
(*unboxed.borrow())[..(*unboxed.borrow()).len().saturating_sub(1)] == *__s
})
})
);
let indirect: Value<Vec<i8>> = Rc::new(RefCell::new({
let mut __bytes = Ptr::<i8>::from_string_literal(b"c").to_c_bytes();
Expand All @@ -159,11 +174,15 @@ fn main_0() -> i32 {
);
let mut pointer: Ptr<Vec<i8>> = (indirect.as_pointer());
{
pointer.with_mut(|__v: &mut Vec<i8>| __v.pop());
let __len = (*pointer.upgrade().deref()).len() + (0_usize) as usize;
pointer.with_mut(|__v: &mut Vec<i8>| __v.resize(__len, ('\0' as i8)));
pointer.with_mut(|__v: &mut Vec<i8>| __v.push(0));
(*pointer.upgrade().deref()).clone()
let __count = 0_usize as usize;
let __ch = ('\0' as i8);
pointer.with_mut(|__v: &mut Vec<i8>| {
__v.pop();
let __len = __v.len() + __count;
__v.resize(__len, __ch);
__v.push(0);
});
(pointer).clone()
};
assert!(
({
Expand All @@ -172,6 +191,42 @@ fn main_0() -> i32 {
})
})
);
let chained: Value<Vec<i8>> = Rc::new(RefCell::new({
let mut __bytes = Ptr::<i8>::from_string_literal(b"a").to_c_bytes();
__bytes.push(0);
__bytes
}));
match ({
let __count = 3_usize as usize;
let __ch = ('x' as i8);
chained.as_pointer().with_mut(|__v: &mut Vec<i8>| {
__v.pop();
let __len = __v.len() + __count;
__v.resize(__len, __ch);
__v.push(0);
});
chained.as_pointer()
},)
{
(__tmp_0,) => {
let __count = 2_usize as usize;
let __ch = ('y' as i8);
__tmp_0.with_mut(|__v: &mut Vec<i8>| {
__v.pop();
let __len = __v.len() + __count;
__v.resize(__len, __ch);
__v.push(0);
});
(__tmp_0).clone()
}
};
assert!(
({
Ptr::<i8>::from_string_literal(b"axxxyy").with_c_str(|__s| {
(*chained.borrow())[..(*chained.borrow()).len().saturating_sub(1)] == *__s
})
})
);
println!("checked {} appends", cases);
return 0;
}
Expand Down
82 changes: 66 additions & 16 deletions tests/unit/out/unsafe/string_repeat_append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ use std::io::{Read, Seek, Write};
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
use std::rc::Rc;
pub unsafe fn append_to_reference_0(s: *mut Vec<libc::c_char>) {
(*s).splice(
(*s).len() - 1..(*s).len() - 1,
::std::vec::from_elem(('r' as libc::c_char), 1_usize),
);
{
(*(s as *mut Vec<libc::c_char>)).splice(
(*(s as *mut Vec<libc::c_char>)).len() - 1..(*(s as *mut Vec<libc::c_char>)).len() - 1,
::std::vec::from_elem(('r' as libc::c_char), 1_usize as usize),
);
(s as *mut Vec<libc::c_char>)
};
}
pub fn main() {
unsafe {
Expand Down Expand Up @@ -88,10 +91,14 @@ unsafe fn main_0() -> i32 {
if (shrink != 0) {
s.shrink_to_fit();
}
s.splice(
s.len() - 1..s.len() - 1,
::std::vec::from_elem(character, count),
);
{
(*(&mut s as *mut Vec<libc::c_char>)).splice(
(*(&mut s as *mut Vec<libc::c_char>)).len() - 1
..(*(&mut s as *mut Vec<libc::c_char>)).len() - 1,
::std::vec::from_elem(character, count as usize),
);
(&mut s as *mut Vec<libc::c_char>)
};
assert!(((s.len() - 1) == ((length).wrapping_add(count))));
let mut data: *const libc::c_char = (s.as_mut_ptr()).cast_const();
{
Expand Down Expand Up @@ -124,10 +131,14 @@ unsafe fn main_0() -> i32 {
(0..).take_while(|&i| *c"a".as_ptr().add(i) != 0).count() + 1,
)
.to_vec();
unboxed.splice(
unboxed.len() - 1..unboxed.len() - 1,
::std::vec::from_elem(('b' as libc::c_char), 2_usize),
);
{
(*(&mut unboxed as *mut Vec<libc::c_char>)).splice(
(*(&mut unboxed as *mut Vec<libc::c_char>)).len() - 1
..(*(&mut unboxed as *mut Vec<libc::c_char>)).len() - 1,
::std::vec::from_elem(('b' as libc::c_char), 2_usize as usize),
);
(&mut unboxed as *mut Vec<libc::c_char>)
};
assert!(
unboxed == {
std::slice::from_raw_parts(
Expand All @@ -153,10 +164,14 @@ unsafe fn main_0() -> i32 {
}
);
let mut pointer: *mut Vec<libc::c_char> = (&mut indirect as *mut Vec<libc::c_char>);
(*pointer).splice(
(*pointer).len() - 1..(*pointer).len() - 1,
::std::vec::from_elem(('\0' as libc::c_char), 0_usize),
);
{
(*(pointer as *mut Vec<libc::c_char>)).splice(
(*(pointer as *mut Vec<libc::c_char>)).len() - 1
..(*(pointer as *mut Vec<libc::c_char>)).len() - 1,
::std::vec::from_elem(('\0' as libc::c_char), 0_usize as usize),
);
(pointer as *mut Vec<libc::c_char>)
};
assert!(
indirect == {
std::slice::from_raw_parts(
Expand All @@ -166,6 +181,41 @@ unsafe fn main_0() -> i32 {
.to_vec()
}
);
let mut chained: Vec<libc::c_char> = std::slice::from_raw_parts(
c"a".as_ptr(),
(0..).take_while(|&i| *c"a".as_ptr().add(i) != 0).count() + 1,
)
.to_vec();
match (({
(*(&mut chained as *mut Vec<libc::c_char>)).splice(
(*(&mut chained as *mut Vec<libc::c_char>)).len() - 1
..(*(&mut chained as *mut Vec<libc::c_char>)).len() - 1,
::std::vec::from_elem(('x' as libc::c_char), 3_usize as usize),
);
(&mut chained as *mut Vec<libc::c_char>)
} as *mut Vec<libc::c_char>),)
{
(__tmp_0,) => {
(*(__tmp_0 as *mut Vec<libc::c_char>)).splice(
(*(__tmp_0 as *mut Vec<libc::c_char>)).len() - 1
..(*(__tmp_0 as *mut Vec<libc::c_char>)).len() - 1,
::std::vec::from_elem(('y' as libc::c_char), 2_usize as usize),
);
(__tmp_0 as *mut Vec<libc::c_char>)
}
};
assert!(
chained == {
std::slice::from_raw_parts(
c"axxxyy".as_ptr(),
(0..)
.take_while(|&i| *c"axxxyy".as_ptr().add(i) != 0)
.count()
+ 1,
)
.to_vec()
}
);
(unsafe {
libc::printf(
c"checked %zu appends\n".as_ptr() as *const libc::c_char,
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/string_repeat_append.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ int main() {
std::string *pointer = &indirect;
pointer->append(std::size_t(0), '\0');
assert(indirect == "cr");
std::string chained = "a";
chained.append(3, 'x').append(2, 'y');
assert(chained == "axxxyy");
printf("checked %zu appends\n", cases);
return 0;
}
Loading