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
20 changes: 10 additions & 10 deletions rules/algorithm/tgt_refcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ fn f17<T1: PartialOrd + Clone + ByteRepr>(a0: Ptr<T1>, a1: Ptr<T1>) -> Ptr<T1> {
if a0.read() >= a1.read() { a0 } else { a1 }
}

fn f18<T1: Clone + ByteRepr>(a0: Ptr<T1>, a1: Ptr<T1>) {
let count = a1.get_offset() - a0.get_offset();
let random = std::hash::RandomState::new();
for i in (1..count).rev() {
let j = std::hash::BuildHasher::hash_one(&random, i) as usize % (i + 1);
let x = a0.offset(i);
let y = a0.offset(j);
let tmp = x.read();
x.write(y.read());
y.write(tmp);
fn f18<T1: CppRandomAccessIterator<T2>, T2: Clone + ByteRepr>(a0: T1, a1: T1) {
let __n = a1.iter_distance(&a0);
let __random = std::hash::RandomState::new();
for __i in (1..__n).rev() {
let __j = (std::hash::BuildHasher::hash_one(&__random, __i) % (__i + 1) as u64) as isize;
let __x = a0.iter_at(__i);
let __y = a0.iter_at(__j);
let __tmp = __x.read();
__x.write(__y.read());
__y.write(__tmp);
}
}
10 changes: 5 additions & 5 deletions rules/algorithm/tgt_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ unsafe fn f17<T1: PartialOrd>(a0: *const T1, a1: *const T1) -> *const T1 {
}
}

unsafe fn f18<T1>(a0: *mut T1, a1: *mut T1) {
let len = a1.offset_from(a0) as usize;
let slice = ::std::slice::from_raw_parts_mut(a0, len);
for i in (1..len).rev() {
slice.swap(i, libc::rand() as usize % (i + 1));
unsafe fn f18<T1: UnsafeCppRandomAccessIterator<T2>, T2>(a0: T1, a1: T1) {
let __n = a1.iter_distance(&a0);
for __i in (1..__n).rev() {
let __j = libc::rand() as isize % (__i + 1);
std::ptr::swap(a0.iter_at(__i), a0.iter_at(__j));
}
}
37 changes: 11 additions & 26 deletions tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,17 @@ fn main_0() -> i32 {
assert!((*it.borrow()) != RandomAccessIterator::Vec((v.as_pointer() as Ptr<i32>).to_end()));
assert!((((*it.borrow()).iter_deref().read()) == 7));
{
let count = Rc::new(RefCell::new(RandomAccessIterator::Vec(
(v.as_pointer() as Ptr<i32>).to_end(),
)))
.as_pointer()
.get_offset()
- Rc::new(RefCell::new(RandomAccessIterator::Vec(
(v.as_pointer() as Ptr<i32>),
)))
.as_pointer()
.get_offset();
let random = std::hash::RandomState::new();
for i in (1..count).rev() {
let j = std::hash::BuildHasher::hash_one(&random, i) as usize % (i + 1);
let x = Rc::new(RefCell::new(RandomAccessIterator::Vec(
(v.as_pointer() as Ptr<i32>),
)))
.as_pointer()
.offset(i);
let y = Rc::new(RefCell::new(RandomAccessIterator::Vec(
(v.as_pointer() as Ptr<i32>),
)))
.as_pointer()
.offset(j);
let tmp = x.read();
x.write(y.read());
y.write(tmp);
let __n = RandomAccessIterator::Vec((v.as_pointer() as Ptr<i32>).to_end())
.iter_distance(&RandomAccessIterator::Vec((v.as_pointer() as Ptr<i32>)));
let __random = std::hash::RandomState::new();
for __i in (1..__n).rev() {
let __j =
(std::hash::BuildHasher::hash_one(&__random, __i) % (__i + 1) as u64) as isize;
let __x = RandomAccessIterator::Vec((v.as_pointer() as Ptr<i32>)).iter_at(__i);
let __y = RandomAccessIterator::Vec((v.as_pointer() as Ptr<i32>)).iter_at(__j);
let __tmp = __x.read();
__x.write(__y.read());
__y.write(__tmp);
}
};
{
Expand Down
15 changes: 8 additions & 7 deletions tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ unsafe fn main_0() -> i32 {
assert!(it != UnsafeRandomAccessIterator::Vec(v.as_mut_ptr().add(v.len())));
assert!(((*it.iter_deref()) == (7)));
{
let len = UnsafeRandomAccessIterator::Vec(v.as_mut_ptr().add(v.len()))
.offset_from(UnsafeRandomAccessIterator::Vec(v.as_mut_ptr()))
as usize;
let slice =
::std::slice::from_raw_parts_mut(UnsafeRandomAccessIterator::Vec(v.as_mut_ptr()), len);
for i in (1..len).rev() {
slice.swap(i, libc::rand() as usize % (i + 1));
let __n = UnsafeRandomAccessIterator::Vec(v.as_mut_ptr().add(v.len()))
.iter_distance(&UnsafeRandomAccessIterator::Vec(v.as_mut_ptr()));
for __i in (1..__n).rev() {
let __j = libc::rand() as isize % (__i + 1);
std::ptr::swap(
UnsafeRandomAccessIterator::Vec(v.as_mut_ptr()).iter_at(__i),
UnsafeRandomAccessIterator::Vec(v.as_mut_ptr()).iter_at(__j),
);
}
};
{
Expand Down
Loading