Skip to content

Commit 42a71d4

Browse files
committed
Add address identity tests
1 parent da79b0c commit 42a71d4

6 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
__cpp2rust_init_globals();
11+
std::process::exit(main_0());
12+
}
13+
fn main_0() -> i32 {
14+
let rows: Value<Box<[Box<[i32]>]>> = Rc::new(RefCell::new(Box::new([
15+
Box::new([1, 2, 3]),
16+
Box::new([4, 5, 6]),
17+
])));
18+
return ((((((rows.as_pointer() as Ptr<Box<[i32]>>)
19+
.offset(1)
20+
.as_pointer()) as Ptr<i32>)
21+
- (((((rows.as_pointer() as Ptr<Box<[i32]>>)
22+
.offset(0)
23+
.as_pointer()) as Ptr<i32>)
24+
.offset(0))
25+
.offset((2) as isize))) as i64) as i32);
26+
}
27+
pub fn __cpp2rust_init_globals() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
__cpp2rust_init_globals();
12+
std::process::exit(main_0() as i32);
13+
}
14+
}
15+
unsafe fn main_0() -> i32 {
16+
let mut rows: [[i32; 3]; 2] = [[1, 2, 3], [4, 5, 6]];
17+
return ((((rows[(1) as usize].as_mut_ptr() as usize
18+
- ((&mut rows[(0) as usize][(0) as usize] as *mut i32).offset((2) as isize)) as usize)
19+
/ ::std::mem::size_of::<i32>()) as i64) as i32);
20+
}
21+
pub unsafe fn __cpp2rust_init_globals() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// panic-ub: refcount
2+
// nondet-result: unsafe
3+
int main() {
4+
int rows[2][3] = {{1, 2, 3}, {4, 5, 6}};
5+
return rows[1] - (&rows[0][0] + 2);
6+
}

‎tests/unit/array_reference.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ int main() {
110110
q[1][0] = q[0][1];
111111
q[1][1] += q[0][2];
112112
assert(rows[0][1] == 3 && rows[1][0] == 3 && rows[1][1] == 8);
113+
assert(&rows[1][2] - &rows[1][0] == 2);
113114

114115
int key[4] = {0, 4, 5, 6};
115116
assert(memcmp(&key[1], kTable[1], sizeof(kTable[1])) == 0);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ fn main_0() -> i32 {
189189
&& ((*rows.borrow())[(1) as usize][(0) as usize] == 3))
190190
&& ((*rows.borrow())[(1) as usize][(1) as usize] == 8)
191191
);
192+
assert!(
193+
((((((rows.as_pointer() as Ptr<Box<[i32]>>)
194+
.offset(1)
195+
.as_pointer()) as Ptr<i32>)
196+
.offset(2))
197+
- ((((rows.as_pointer() as Ptr<Box<[i32]>>)
198+
.offset(1)
199+
.as_pointer()) as Ptr<i32>)
200+
.offset(0))) as i64
201+
== 2_i64)
202+
);
192203
let key: Value<Box<[i32]>> = Rc::new(RefCell::new(Box::new([0, 4, 5, 6])));
193204
assert!(
194205
((((key.as_pointer() as Ptr<i32>).offset(1)) as Ptr::<i32>)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ unsafe fn main_0() -> i32 {
145145
&& ((rows[(1) as usize][(0) as usize]) == (3)))
146146
&& ((rows[(1) as usize][(1) as usize]) == (8))
147147
);
148+
assert!(
149+
(((((&mut rows[(1) as usize][(2) as usize] as *mut i32) as usize
150+
- (&mut rows[(1) as usize][(0) as usize] as *mut i32) as usize)
151+
/ ::std::mem::size_of::<i32>()) as i64)
152+
== (2_i64))
153+
);
148154
let mut key: [i32; 4] = [0, 4, 5, 6];
149155
assert!(
150156
(({

0 commit comments

Comments
 (0)