Skip to content

Commit 2e920ee

Browse files
committed
Update tests
1 parent b4c1d94 commit 2e920ee

5 files changed

Lines changed: 34 additions & 51 deletions

File tree

‎tests/ub/out/refcount/self_referencing_initializer.rs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ fn main_0() -> i32 {
2323
x = (x + 1);
2424
let mut p: pair = <pair>::default();
2525
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()) });
26+
return (x + p.b);
3027
}
3128
pub fn __cpp2rust_init_globals() {}

‎tests/ub/out/unsafe/self_referencing_initializer.rs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ unsafe fn main_0() -> i32 {
2626
a: 1,
2727
b: ((p.a) + (1)),
2828
};
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));
29+
return ((x) + (p.b));
3330
}
3431
pub unsafe fn __cpp2rust_init_globals() {}

‎tests/unit/out/refcount/self_referencing_initializer.rs‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,38 @@ fn main_0() -> i32 {
5757
assert!(({ { (*n.borrow()).value_ptr.clone() } } == { (field_ptr!(n.as_pointer(), value)) }));
5858
{ (*n.borrow()).value_ptr.clone() }.write(7);
5959
assert!(({ (*n.borrow()).value } == 7));
60-
let arr: Value<Box<[AnyPtr]>> = Rc::new(RefCell::new(
61-
(0..2).map(|_| AnyPtr::default()).collect::<Box<[AnyPtr]>>(),
60+
let arr: Value<Box<[list_head]>> = Rc::new(RefCell::new(
61+
(0..2)
62+
.map(|_| <list_head>::default())
63+
.collect::<Box<[list_head]>>(),
6264
));
6365
*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+
list_head {
67+
next: ((arr.as_pointer() as Ptr<list_head>).offset(1)),
68+
},
69+
list_head {
70+
next: ((arr.as_pointer() as Ptr<list_head>).offset(0)),
71+
},
6672
]);
6773
assert!(
68-
((*arr.borrow())[(0) as usize]
69-
== (((arr.as_pointer() as Ptr<AnyPtr>).offset(1)) as Ptr<AnyPtr>).to_any())
74+
({ { (*arr.borrow())[(0) as usize].next.clone() } } == {
75+
((arr.as_pointer() as Ptr<list_head>).offset(1))
76+
})
7077
);
7178
assert!(
72-
((*arr.borrow())[(1) as usize]
73-
== (((arr.as_pointer() as Ptr<AnyPtr>).offset(0)) as Ptr<AnyPtr>).to_any())
79+
({ { (*arr.borrow())[(1) as usize].next.clone() } } == {
80+
((arr.as_pointer() as Ptr<list_head>).offset(0))
81+
})
7482
);
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()));
7883
let d: Value<node_with_defaults> = <Value<node_with_defaults>>::default();
7984
*d.borrow_mut() = node_with_defaults {
8085
next: (d.as_pointer()),
8186
value: 3,
8287
};
8388
assert!(({ { (*d.borrow()).next.clone() } } == { (d.as_pointer()) }));
8489
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());
90+
let mut size: usize = ::std::mem::size_of::<usize>();
91+
assert!((size == ::std::mem::size_of::<usize>()));
9192
return 0;
9293
}
9394
pub fn __cpp2rust_init_globals() {}

‎tests/unit/out/unsafe/self_referencing_initializer.rs‎

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,26 @@ unsafe fn main_0() -> i32 {
5151
assert!(((n.value_ptr) == (&mut n.value as *mut i32)));
5252
(*n.value_ptr) = 7;
5353
assert!(((n.value) == (7)));
54-
let mut arr: [*mut ::libc::c_void; 2] = [std::ptr::null_mut(); 2];
54+
let mut arr: [list_head; 2] = [<list_head>::default(); 2];
5555
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),
56+
list_head {
57+
next: (&mut arr[(1) as usize] as *mut list_head),
58+
},
59+
list_head {
60+
next: (&mut arr[(0) as usize] as *mut list_head),
61+
},
5862
];
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)));
63+
assert!(((arr[(0) as usize].next) == (&mut arr[(1) as usize] as *mut list_head)));
64+
assert!(((arr[(1) as usize].next) == (&mut arr[(0) as usize] as *mut list_head)));
7065
let mut d: node_with_defaults = <node_with_defaults>::default();
7166
d = node_with_defaults {
7267
next: (&mut d as *mut node_with_defaults),
7368
value: 3,
7469
};
7570
assert!(((d.next) == (&mut d as *mut node_with_defaults)));
7671
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));
72+
let mut size: usize = ::std::mem::size_of::<usize>();
73+
assert!(((size) == (::std::mem::size_of::<usize>())));
8374
return 0;
8475
}
8576
pub unsafe fn __cpp2rust_init_globals() {}

‎tests/unit/self_referencing_initializer.cpp‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <cassert>
2-
#include <cstdlib>
2+
#include <cstddef>
33

44
struct list_head {
55
list_head *next;
@@ -32,11 +32,8 @@ int main() {
3232
assert(d.next == &d);
3333
assert(d.value == 3);
3434

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);
35+
size_t size = sizeof(size);
36+
assert(size == sizeof(size_t));
4037

4138
return 0;
4239
}

0 commit comments

Comments
 (0)