Skip to content

Commit 6fa0a5d

Browse files
committed
Update tests
1 parent d121c25 commit 6fa0a5d

6 files changed

Lines changed: 297 additions & 0 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
10+
#[byte_size(8)]
11+
pub struct pair {
12+
#[offset(0)]
13+
pub a: i32,
14+
#[offset(4)]
15+
pub b: i32,
16+
}
17+
pub fn main() {
18+
__cpp2rust_init_globals();
19+
std::process::exit(main_0());
20+
}
21+
fn main_0() -> i32 {
22+
let mut x: i32 = 0_i32;
23+
x = (x + 1);
24+
let mut p: pair = <pair>::default();
25+
p = pair { a: 1, b: (p.a + 1) };
26+
let r: Ptr<i32> = (r).clone();
27+
let __tmp_0: Value<i32> = Rc::new(RefCell::new(((cr.read()) + 1)));
28+
let cr: Ptr<i32> = __tmp_0.as_pointer();
29+
return ({ ({ (x + p.b) } + { (r.read()) }) } + { (cr.read()) });
30+
}
31+
pub fn __cpp2rust_init_globals() {}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
#[repr(C)]
10+
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
11+
pub struct pair {
12+
pub a: i32,
13+
pub b: i32,
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 mut x: i32 = 0_i32;
23+
x = ((x) + (1));
24+
let mut p: pair = <pair>::default();
25+
p = pair {
26+
a: 1,
27+
b: ((p.a) + (1)),
28+
};
29+
let r: *mut i32 = r;
30+
let mut __tmp_0: i32 = ((*cr) + (1));
31+
let cr: *const i32 = &mut __tmp_0;
32+
return ((((x) + (p.b)) + (*r)) + (*cr));
33+
}
34+
pub unsafe fn __cpp2rust_init_globals() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// nondet-result
2+
3+
struct pair {
4+
int a;
5+
int b;
6+
};
7+
8+
int main() {
9+
int x = x + 1;
10+
pair p = {1, p.a + 1};
11+
return x + p.b;
12+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
10+
#[byte_size(8)]
11+
pub struct list_head {
12+
#[offset(0)]
13+
#[byte_size(8)]
14+
pub next: Ptr<list_head>,
15+
}
16+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
17+
#[byte_size(16)]
18+
pub struct node {
19+
#[offset(0)]
20+
pub value: i32,
21+
#[offset(8)]
22+
#[byte_size(8)]
23+
pub value_ptr: Ptr<i32>,
24+
}
25+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)]
26+
#[byte_size(16)]
27+
pub struct node_with_defaults {
28+
#[offset(0)]
29+
#[byte_size(8)]
30+
pub next: Ptr<node_with_defaults>,
31+
#[offset(8)]
32+
pub value: i32,
33+
}
34+
impl Default for node_with_defaults {
35+
fn default() -> Self {
36+
node_with_defaults {
37+
next: Ptr::<node_with_defaults>::null(),
38+
value: 3,
39+
}
40+
}
41+
}
42+
pub fn main() {
43+
__cpp2rust_init_globals();
44+
std::process::exit(main_0());
45+
}
46+
fn main_0() -> i32 {
47+
let list: Value<list_head> = <Value<list_head>>::default();
48+
*list.borrow_mut() = list_head {
49+
next: (list.as_pointer()),
50+
};
51+
assert!(({ { (*list.borrow()).next.clone() } } == { (list.as_pointer()) }));
52+
let n: Value<node> = <Value<node>>::default();
53+
*n.borrow_mut() = node {
54+
value: 42,
55+
value_ptr: (field_ptr!(n.as_pointer(), value)),
56+
};
57+
assert!(({ { (*n.borrow()).value_ptr.clone() } } == { (field_ptr!(n.as_pointer(), value)) }));
58+
{ (*n.borrow()).value_ptr.clone() }.write(7);
59+
assert!(({ (*n.borrow()).value } == 7));
60+
let arr: Value<Box<[AnyPtr]>> = Rc::new(RefCell::new(
61+
(0..2).map(|_| AnyPtr::default()).collect::<Box<[AnyPtr]>>(),
62+
));
63+
*arr.borrow_mut() = Box::new([
64+
(((arr.as_pointer() as Ptr<AnyPtr>).offset(1)) as Ptr<AnyPtr>).to_any(),
65+
(((arr.as_pointer() as Ptr<AnyPtr>).offset(0)) as Ptr<AnyPtr>).to_any(),
66+
]);
67+
assert!(
68+
((*arr.borrow())[(0) as usize]
69+
== (((arr.as_pointer() as Ptr<AnyPtr>).offset(1)) as Ptr<AnyPtr>).to_any())
70+
);
71+
assert!(
72+
((*arr.borrow())[(1) as usize]
73+
== (((arr.as_pointer() as Ptr<AnyPtr>).offset(0)) as Ptr<AnyPtr>).to_any())
74+
);
75+
let p: Value<AnyPtr> = Rc::new(RefCell::new(AnyPtr::default()));
76+
*p.borrow_mut() = ((p.as_pointer()) as Ptr<AnyPtr>).to_any();
77+
assert!(((*p.borrow()) == ((p.as_pointer()) as Ptr<AnyPtr>).to_any()));
78+
let d: Value<node_with_defaults> = <Value<node_with_defaults>>::default();
79+
*d.borrow_mut() = node_with_defaults {
80+
next: (d.as_pointer()),
81+
value: 3,
82+
};
83+
assert!(({ { (*d.borrow()).next.clone() } } == { (d.as_pointer()) }));
84+
assert!(({ (*d.borrow()).value } == 3));
85+
let mut heap: Ptr<list_head> =
86+
libcc2rs::malloc_refcount(8usize).reinterpret_cast::<list_head>();
87+
assert!(!((heap).is_null()));
88+
field!(heap, next).write({ (heap).clone() });
89+
assert!(({ heap.with(|__s| __s.next.clone()) } == { (heap).clone() }));
90+
libcc2rs::free_refcount((heap).to_any());
91+
return 0;
92+
}
93+
pub fn __cpp2rust_init_globals() {}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
#[repr(C)]
10+
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
11+
pub struct list_head {
12+
pub next: *mut list_head,
13+
}
14+
#[repr(C)]
15+
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
16+
pub struct node {
17+
pub value: i32,
18+
pub value_ptr: *mut i32,
19+
}
20+
#[repr(C)]
21+
#[derive(Copy, Clone, VaArg, FnPtrArg)]
22+
pub struct node_with_defaults {
23+
pub next: *mut node_with_defaults,
24+
pub value: i32,
25+
}
26+
impl Default for node_with_defaults {
27+
fn default() -> Self {
28+
node_with_defaults {
29+
next: std::ptr::null_mut(),
30+
value: 3,
31+
}
32+
}
33+
}
34+
pub fn main() {
35+
unsafe {
36+
__cpp2rust_init_globals();
37+
std::process::exit(main_0() as i32);
38+
}
39+
}
40+
unsafe fn main_0() -> i32 {
41+
let mut list: list_head = <list_head>::default();
42+
list = list_head {
43+
next: (&mut list as *mut list_head),
44+
};
45+
assert!(((list.next) == (&mut list as *mut list_head)));
46+
let mut n: node = <node>::default();
47+
n = node {
48+
value: 42,
49+
value_ptr: (&mut n.value as *mut i32),
50+
};
51+
assert!(((n.value_ptr) == (&mut n.value as *mut i32)));
52+
(*n.value_ptr) = 7;
53+
assert!(((n.value) == (7)));
54+
let mut arr: [*mut ::libc::c_void; 2] = [std::ptr::null_mut(); 2];
55+
arr = [
56+
((&mut arr[(1) as usize] as *mut *mut ::libc::c_void) as *mut ::libc::c_void),
57+
((&mut arr[(0) as usize] as *mut *mut ::libc::c_void) as *mut ::libc::c_void),
58+
];
59+
assert!(
60+
((arr[(0) as usize])
61+
== ((&mut arr[(1) as usize] as *mut *mut ::libc::c_void) as *mut ::libc::c_void))
62+
);
63+
assert!(
64+
((arr[(1) as usize])
65+
== ((&mut arr[(0) as usize] as *mut *mut ::libc::c_void) as *mut ::libc::c_void))
66+
);
67+
let mut p: *mut ::libc::c_void = std::ptr::null_mut();
68+
p = ((&mut p as *mut *mut ::libc::c_void) as *mut ::libc::c_void);
69+
assert!(((p) == ((&mut p as *mut *mut ::libc::c_void) as *mut ::libc::c_void)));
70+
let mut d: node_with_defaults = <node_with_defaults>::default();
71+
d = node_with_defaults {
72+
next: (&mut d as *mut node_with_defaults),
73+
value: 3,
74+
};
75+
assert!(((d.next) == (&mut d as *mut node_with_defaults)));
76+
assert!(((d.value) == (3)));
77+
let mut heap: *mut list_head =
78+
(libcc2rs::malloc_unsafe(::std::mem::size_of::<list_head>()) as *mut list_head);
79+
assert!(!((heap).is_null()));
80+
(*heap).next = heap;
81+
assert!((((*heap).next) == (heap)));
82+
libcc2rs::free_unsafe((heap as *mut ::libc::c_void));
83+
return 0;
84+
}
85+
pub unsafe fn __cpp2rust_init_globals() {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <cassert>
2+
#include <cstdlib>
3+
4+
struct list_head {
5+
list_head *next;
6+
};
7+
8+
struct node {
9+
int value;
10+
int *value_ptr;
11+
};
12+
13+
struct node_with_defaults {
14+
node_with_defaults *next = nullptr;
15+
int value = 3;
16+
};
17+
18+
int main() {
19+
list_head list = {&list};
20+
assert(list.next == &list);
21+
22+
node n = {42, &n.value};
23+
assert(n.value_ptr == &n.value);
24+
*n.value_ptr = 7;
25+
assert(n.value == 7);
26+
27+
list_head arr[2] = {{&arr[1]}, {&arr[0]}};
28+
assert(arr[0].next == &arr[1]);
29+
assert(arr[1].next == &arr[0]);
30+
31+
node_with_defaults d{&d};
32+
assert(d.next == &d);
33+
assert(d.value == 3);
34+
35+
list_head *heap = static_cast<list_head *>(malloc(sizeof(*heap)));
36+
assert(heap != nullptr);
37+
heap->next = heap;
38+
assert(heap->next == heap);
39+
free(heap);
40+
41+
return 0;
42+
}

0 commit comments

Comments
 (0)