Skip to content

Commit 9188d35

Browse files
committed
Add example rules
1 parent 9c4090a commit 9188d35

9 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <algorithm>
5+
6+
template <typename T1> void f18(T1 first, T1 last) {
7+
return std::random_shuffle(first, last);
8+
}

‎rules/algorithm/tgt_refcount.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,16 @@ fn f16<T1: PartialOrd + Clone + ByteRepr>(a0: Ptr<T1>, a1: Ptr<T1>) -> Ptr<T1> {
117117
fn f17<T1: PartialOrd + Clone + ByteRepr>(a0: Ptr<T1>, a1: Ptr<T1>) -> Ptr<T1> {
118118
if a0.read() >= a1.read() { a0 } else { a1 }
119119
}
120+
121+
fn f18<T1: Clone + ByteRepr>(a0: Ptr<T1>, a1: Ptr<T1>) {
122+
let count = a1.get_offset() - a0.get_offset();
123+
let random = std::hash::RandomState::new();
124+
for i in (1..count).rev() {
125+
let j = std::hash::BuildHasher::hash_one(&random, i) as usize % (i + 1);
126+
let x = a0.offset(i);
127+
let y = a0.offset(j);
128+
let tmp = x.read();
129+
x.write(y.read());
130+
y.write(tmp);
131+
}
132+
}

‎rules/algorithm/tgt_unsafe.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,11 @@ unsafe fn f17<T1: PartialOrd>(a0: *const T1, a1: *const T1) -> *const T1 {
133133
(a1) as *const _
134134
}
135135
}
136+
137+
unsafe fn f18<T1>(a0: *mut T1, a1: *mut T1) {
138+
let len = a1.offset_from(a0) as usize;
139+
let slice = ::std::slice::from_raw_parts_mut(a0, len);
140+
for i in (1..len).rev() {
141+
slice.swap(i, libc::rand() as usize % (i + 1));
142+
}
143+
}

‎rules/memory/src_until_cxx23.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <cstddef>
5+
#include <memory>
6+
7+
void f1(char *a0, std::size_t a1) { return std::declare_no_pointers(a0, a1); }
8+
9+
void f2(char *a0, std::size_t a1) {
10+
return std::undeclare_no_pointers(a0, a1);
11+
}

‎rules/memory/tgt_refcount.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
use libcc2rs::*;
5+
6+
fn f1(_a0: Ptr<i8>, _a1: usize) {}
7+
8+
fn f2(_a0: Ptr<i8>, _a1: usize) {}

‎rules/memory/tgt_unsafe.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
unsafe fn f1(_a0: *mut libc::c_char, _a1: usize) {}
5+
6+
unsafe fn f2(_a0: *mut libc::c_char, _a1: usize) {}

‎rules/string/src_until_cxx20.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <string>
5+
6+
bool f31(const std::string &a, const char *b) { return a != b; }

‎rules/string/tgt_refcount.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,7 @@ fn f29(a0: Ptr<Vec<i8>>, a1: Vec<i8>) {
190190
fn f30(a0: Ptr<Vec<i8>>, a1: &mut Vec<i8>) {
191191
a0.write(std::mem::take(&mut *a1))
192192
}
193+
194+
fn f31(a0: Vec<i8>, a1: Ptr<i8>) -> bool {
195+
a1.with_c_str(|__s| a0[..a0.len().saturating_sub(1)] != *__s)
196+
}

‎rules/string/tgt_unsafe.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,10 @@ unsafe fn f29(a0: &mut Vec<libc::c_char>, a1: Vec<libc::c_char>) {
184184
unsafe fn f30(a0: &mut Vec<libc::c_char>, a1: &mut Vec<libc::c_char>) {
185185
*a0 = std::mem::take(&mut *a1)
186186
}
187+
188+
unsafe fn f31(a0: Vec<libc::c_char>, a1: *const libc::c_char) -> bool {
189+
a0 != {
190+
let s = a1;
191+
std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec()
192+
}
193+
}

0 commit comments

Comments
 (0)