Skip to content

Commit 500600a

Browse files
committed
Update tests
1 parent 414fc4e commit 500600a

12 files changed

Lines changed: 166 additions & 5 deletions

tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ pub fn touch_0(c: Ptr<container>) {
4444
(*(*(*c.borrow()).upgrade().deref()).p.borrow()).clone();
4545
}
4646
pub struct opaque;
47+
impl ByteRepr for opaque {}

tests/multi-file/opaque_forward_decl/out/unsafe/opaque_forward_decl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ pub unsafe fn touch_0(mut c: *mut container) {
3131
&((*c).p);
3232
}
3333
pub struct opaque;
34+
impl ByteRepr for opaque {}

tests/unit/out/refcount/opaque_forward_decl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ fn main_0() -> i32 {
3838
return ((*(*c.borrow()).x.borrow()) - 42);
3939
}
4040
pub struct opaque;
41+
impl ByteRepr for opaque {}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
pub fn main() {
10+
std::process::exit(main_0());
11+
}
12+
fn main_0() -> i32 {
13+
let arr: Value<Box<[i32]>> = Rc::new(RefCell::new(Box::new([10, 20, 30, 40])));
14+
pub struct anon_0 {
15+
__bytes: Value<Box<[u8]>>,
16+
}
17+
impl anon_0 {
18+
pub fn p(&self) -> Ptr<Ptr<i32>> {
19+
(self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast()
20+
}
21+
pub fn bits(&self) -> Ptr<u64> {
22+
(self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast()
23+
}
24+
}
25+
impl Clone for anon_0 {
26+
fn clone(&self) -> Self {
27+
anon_0 {
28+
__bytes: Rc::new(RefCell::new(self.__bytes.borrow().clone())),
29+
}
30+
}
31+
}
32+
impl Default for anon_0 {
33+
fn default() -> Self {
34+
anon_0 {
35+
__bytes: Rc::new(RefCell::new(Box::from([0u8; 8]))),
36+
}
37+
}
38+
}
39+
impl ByteRepr for anon_0 {
40+
fn byte_size() -> usize {
41+
8
42+
}
43+
fn to_bytes(&self, buf: &mut [u8]) {
44+
buf.copy_from_slice(&self.__bytes.borrow());
45+
}
46+
fn from_bytes(buf: &[u8]) -> Self {
47+
anon_0 {
48+
__bytes: Rc::new(RefCell::new(Box::from(buf))),
49+
}
50+
}
51+
};
52+
let u: Value<anon_0> = <Value<anon_0>>::default();
53+
(*u.borrow_mut())
54+
.p()
55+
.write(((arr.as_pointer() as Ptr<i32>).offset(1)));
56+
let rhs_0 = ((((*u.borrow()).bits().read()) as u64)
57+
.wrapping_add(((2_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)) as u64)))
58+
as u64;
59+
(*u.borrow_mut()).bits().write(rhs_0);
60+
let q: Value<Ptr<i32>> = Rc::new(RefCell::new(((*u.borrow()).p().read()).clone()));
61+
assert!((((((*q.borrow()).read()) == 40) as i32) != 0));
62+
assert!(
63+
((({
64+
let _lhs = (*q.borrow()).clone();
65+
_lhs == ((arr.as_pointer() as Ptr<i32>).offset(3))
66+
}) as i32)
67+
!= 0)
68+
);
69+
let rhs_0 = ((((*u.borrow()).bits().read()) as u64)
70+
.wrapping_sub(((3_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)) as u64)))
71+
as u64;
72+
(*u.borrow_mut()).bits().write(rhs_0);
73+
assert!(
74+
((({
75+
let _lhs = ((*u.borrow()).p().read()).clone();
76+
_lhs == ((arr.as_pointer() as Ptr<i32>).offset(0))
77+
}) as i32)
78+
!= 0)
79+
);
80+
assert!(((((((*u.borrow()).p().read()).read()) == 10) as i32) != 0));
81+
(*u.borrow_mut())
82+
.p()
83+
.write((arr.as_pointer() as Ptr<i32>).offset((4) as isize));
84+
assert!(
85+
((({
86+
let _lhs = ((*u.borrow()).p().read()).clone();
87+
_lhs == (arr.as_pointer() as Ptr<i32>).offset((4) as isize)
88+
}) as i32)
89+
!= 0)
90+
);
91+
return 0;
92+
}

tests/unit/out/unsafe/opaque_forward_decl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ unsafe fn main_0() -> i32 {
2626
return ((c.x) - (42));
2727
}
2828
pub struct opaque;
29+
impl ByteRepr for opaque {}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
pub fn main() {
10+
unsafe {
11+
std::process::exit(main_0() as i32);
12+
}
13+
}
14+
unsafe fn main_0() -> i32 {
15+
let mut arr: [i32; 4] = [10, 20, 30, 40];
16+
#[repr(C)]
17+
#[derive(Copy, Clone)]
18+
pub union anon_0 {
19+
pub p: *mut i32,
20+
pub bits: u64,
21+
}
22+
impl Default for anon_0 {
23+
fn default() -> Self {
24+
unsafe { std::mem::zeroed() }
25+
}
26+
};
27+
let mut u: anon_0 = <anon_0>::default();
28+
u.p = (&mut arr[(1) as usize] as *mut i32);
29+
u.bits = ((u.bits as u64)
30+
.wrapping_add(((2_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)) as u64)))
31+
as u64;
32+
let mut q: *mut i32 = u.p;
33+
assert!(((((*q) == (40)) as i32) != 0));
34+
assert!(((((q) == (&mut arr[(3) as usize] as *mut i32)) as i32) != 0));
35+
u.bits = ((u.bits as u64)
36+
.wrapping_sub(((3_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)) as u64)))
37+
as u64;
38+
assert!(((((u.p) == (&mut arr[(0) as usize] as *mut i32)) as i32) != 0));
39+
assert!(((((*u.p) == (10)) as i32) != 0));
40+
u.p = arr.as_mut_ptr().offset((4) as isize);
41+
assert!(((((u.p) == (arr.as_mut_ptr().offset((4) as isize))) as i32) != 0));
42+
return 0;
43+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <assert.h>
2+
#include <stdint.h>
3+
4+
int main(void) {
5+
int arr[4] = {10, 20, 30, 40};
6+
7+
union {
8+
int *p;
9+
uintptr_t bits;
10+
} u;
11+
12+
u.p = &arr[1];
13+
u.bits += 2 * sizeof(int);
14+
int *q = u.p;
15+
16+
assert(*q == 40);
17+
assert(q == &arr[3]);
18+
19+
u.bits -= 3 * sizeof(int);
20+
assert(u.p == &arr[0]);
21+
assert(*u.p == 10);
22+
23+
u.p = arr + 4;
24+
assert(u.p == arr + 4);
25+
26+
return 0;
27+
}

tests/unit/union_pointer_pun_address.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// panic: refcount
21
#include <assert.h>
32

43
struct node_a {

tests/unit/union_pointer_pun_writethrough.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// panic: refcount
21
#include <assert.h>
32

43
int main(void) {

tests/unit/union_tagged_many_arms.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// panic: refcount
21
#include <assert.h>
32
#include <stdint.h>
43

0 commit comments

Comments
 (0)