Skip to content

Commit 52749e3

Browse files
committed
Update tests
1 parent 099bcfd commit 52749e3

25 files changed

Lines changed: 196 additions & 61 deletions

tests/unit/out/refcount/string_literals.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
pub fn foo_0(str: Ptr<u8>) {
9+
pub fn foo_mut_0(str: Ptr<u8>) {
10+
let str: Value<Ptr<u8>> = Rc::new(RefCell::new(str));
11+
}
12+
pub fn foo_const_1(str: Ptr<u8>) {
1013
let str: Value<Ptr<u8>> = Rc::new(RefCell::new(str));
1114
}
1215
pub fn main() {
@@ -25,13 +28,41 @@ fn main_0() -> i32 {
2528
])));
2629
let mutable_string: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal("hello")));
2730
let immutable_string: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal("hello")));
31+
let mutable_string_arr: Value<Box<[u8]>> =
32+
Rc::new(RefCell::new(Box::<[u8]>::from(b"papanasi\0".as_slice())));
33+
let immutable_string_arr: Value<Box<[u8]>> =
34+
Rc::new(RefCell::new(Box::<[u8]>::from(b"papanasi\0".as_slice())));
35+
({
36+
let _str: Ptr<u8> = Ptr::from_string_literal("world");
37+
foo_mut_0(_str)
38+
});
39+
({
40+
let _str: Ptr<u8> = (*mutable_string.borrow()).clone();
41+
foo_mut_0(_str)
42+
});
43+
({
44+
let _str: Ptr<u8> = (mutable_string_arr.as_pointer() as Ptr<u8>);
45+
foo_mut_0(_str)
46+
});
2847
({
2948
let _str: Ptr<u8> = Ptr::from_string_literal("world");
30-
foo_0(_str)
49+
foo_const_1(_str)
3150
});
3251
({
3352
let _str: Ptr<u8> = (*mutable_string.borrow()).clone();
34-
foo_0(_str)
53+
foo_const_1(_str)
54+
});
55+
({
56+
let _str: Ptr<u8> = (*immutable_string.borrow()).clone();
57+
foo_const_1(_str)
58+
});
59+
({
60+
let _str: Ptr<u8> = (mutable_string_arr.as_pointer() as Ptr<u8>);
61+
foo_const_1(_str)
62+
});
63+
({
64+
let _str: Ptr<u8> = (immutable_string_arr.as_pointer() as Ptr<u8>);
65+
foo_const_1(_str)
3566
});
3667
return 0;
3768
}

tests/unit/out/refcount/string_literals_c.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
pub fn foo_0(str: Ptr<u8>) {
9+
pub fn foo_mut_0(str: Ptr<u8>) {
10+
let str: Value<Ptr<u8>> = Rc::new(RefCell::new(str));
11+
}
12+
pub fn foo_const_1(str: Ptr<u8>) {
1013
let str: Value<Ptr<u8>> = Rc::new(RefCell::new(str));
1114
}
1215
pub fn main() {
@@ -25,13 +28,41 @@ fn main_0() -> i32 {
2528
])));
2629
let mutable_string: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal("hello")));
2730
let immutable_string: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal("hello")));
31+
let mutable_string_arr: Value<Box<[u8]>> =
32+
Rc::new(RefCell::new(Box::<[u8]>::from(b"papanasi\0".as_slice())));
33+
let immutable_string_arr: Value<Box<[u8]>> =
34+
Rc::new(RefCell::new(Box::<[u8]>::from(b"papanasi\0".as_slice())));
35+
({
36+
let _str: Ptr<u8> = Ptr::from_string_literal("world");
37+
foo_mut_0(_str)
38+
});
39+
({
40+
let _str: Ptr<u8> = (*mutable_string.borrow()).clone();
41+
foo_mut_0(_str)
42+
});
43+
({
44+
let _str: Ptr<u8> = (mutable_string_arr.as_pointer() as Ptr<u8>);
45+
foo_mut_0(_str)
46+
});
2847
({
2948
let _str: Ptr<u8> = Ptr::from_string_literal("world");
30-
foo_0(_str)
49+
foo_const_1(_str)
3150
});
3251
({
3352
let _str: Ptr<u8> = (*mutable_string.borrow()).clone();
34-
foo_0(_str)
53+
foo_const_1(_str)
54+
});
55+
({
56+
let _str: Ptr<u8> = (*immutable_string.borrow()).clone();
57+
foo_const_1(_str)
58+
});
59+
({
60+
let _str: Ptr<u8> = (mutable_string_arr.as_pointer() as Ptr<u8>);
61+
foo_const_1(_str)
62+
});
63+
({
64+
let _str: Ptr<u8> = (immutable_string_arr.as_pointer() as Ptr<u8>);
65+
foo_const_1(_str)
3566
});
3667
return 0;
3768
}

tests/unit/out/unsafe/borrow_mut_opt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub unsafe fn convert_without_rhs_0() {
2323
let mut w: i32 = ((arr[(y) as usize]) + (arr[(x) as usize]));
2424
w += (((z) + (y)) + (x));
2525
let mut arr2: [u8; 3] = [('a' as u8), ('b' as u8), ('c' as u8)];
26-
let mut p1: *const i32 = (&mut x as *mut i32);
26+
let mut p1: *const i32 = (&mut x as *mut i32).cast_const();
2727
let mut c: u8 = arr2[(*p1) as usize];
2828
c = arr2[(*p1) as usize];
2929
let mut p2: *mut i32 = (&mut x as *mut i32);

tests/unit/out/unsafe/huffman.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub unsafe fn CollectCodes_4(
239239
CollectCodes_4(_root, _arr, _top, _out, _next)
240240
});
241241
}
242-
if (unsafe { (*root).IsLeaf() }) {
242+
if (unsafe { (*root.cast_const()).IsLeaf() }) {
243243
(unsafe {
244244
let _arr: *mut Option<Box<[i32]>> = arr;
245245
let _top: i32 = top;

tests/unit/out/unsafe/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn main() {
1818
}
1919
unsafe fn main_0(mut argc: i32, mut argv: *mut *mut u8) -> i32 {
2020
let mut s: Vec<u8> = {
21-
let s = (*argv.offset((0) as isize));
21+
let s = (*argv.offset((0) as isize)).cast_const();
2222
std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec()
2323
};
2424
assert!(((argc) == (1)));

tests/unit/out/unsafe/pointer_diff.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn main() {
1313
}
1414
unsafe fn main_0() -> i32 {
1515
let mut a: [i32; 5] = [1, 2, 3, 4, 5];
16-
let mut p0: *const i32 = (&mut a[(0) as usize] as *mut i32);
17-
let mut p1: *const i32 = (&mut a[(4) as usize] as *mut i32);
16+
let mut p0: *const i32 = (&mut a[(0) as usize] as *mut i32).cast_const();
17+
let mut p1: *const i32 = (&mut a[(4) as usize] as *mut i32).cast_const();
1818
return ((((p1 as usize - p0 as usize) / ::std::mem::size_of::<i32>()) as u64) as i32);
1919
}

tests/unit/out/unsafe/pointer_eq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ pub fn main() {
1313
}
1414
unsafe fn main_0() -> i32 {
1515
let mut x: i32 = 5;
16-
let mut p1: *const i32 = (&mut x as *mut i32);
17-
let mut p2: *const i32 = (&mut x as *mut i32);
16+
let mut p1: *const i32 = (&mut x as *mut i32).cast_const();
17+
let mut p2: *const i32 = (&mut x as *mut i32).cast_const();
1818
assert!(((p1) == (p2)));
1919
let mut y: i32 = 5;
20-
let mut p3: *const i32 = (&mut y as *mut i32);
20+
let mut p3: *const i32 = (&mut y as *mut i32).cast_const();
2121
assert!(((p1) != (p3)));
2222
let mut arr: [i32; 3] = [1, 2, 3];
2323
let mut p: *mut i32 = arr.as_mut_ptr();

tests/unit/out/unsafe/pointer_neq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub fn main() {
1313
}
1414
unsafe fn main_0() -> i32 {
1515
let mut x: i32 = 5;
16-
let mut p1: *const i32 = (&mut x as *mut i32);
17-
let mut p2: *const i32 = (&mut x as *mut i32);
16+
let mut p1: *const i32 = (&mut x as *mut i32).cast_const();
17+
let mut p2: *const i32 = (&mut x as *mut i32).cast_const();
1818
if ((p1) != (p2)) {
1919
return 1;
2020
} else {

tests/unit/out/unsafe/pointer_offset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn main() {
1414
unsafe fn main_0() -> i32 {
1515
let mut out: i32 = 0;
1616
let mut arr: [i32; 5] = [1, 2, 3, 4, 0];
17-
let mut ptr: *const i32 = (&mut arr[(0) as usize] as *mut i32);
17+
let mut ptr: *const i32 = (&mut arr[(0) as usize] as *mut i32).cast_const();
1818
'loop_: while ((*ptr) != (0)) {
1919
out += (*ptr);
2020
ptr.prefix_inc();
@@ -29,7 +29,7 @@ unsafe fn main_0() -> i32 {
2929
out += (*ptr);
3030
ptr.postfix_dec();
3131
}
32-
let mut ptr: *const i32 = (&mut arr[(3) as usize] as *mut i32);
32+
let mut ptr: *const i32 = (&mut arr[(3) as usize] as *mut i32).cast_const();
3333
'loop_: while ((*ptr) != (2)) {
3434
out += (*ptr);
3535
ptr.prefix_dec();

tests/unit/out/unsafe/polymorphism.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ pub fn main() {
3636
unsafe fn main_0() -> i32 {
3737
let mut dog: Dog = <Dog>::default();
3838
let mut animal: *mut dyn Animal = (&mut dog as *mut Dog);
39-
let mut eat1: bool = (unsafe { (*animal).bark() });
39+
let mut eat1: bool = (unsafe { (*animal.cast_const()).bark() });
4040
let mut cat: Cat = <Cat>::default();
4141
animal = (&mut cat as *mut Cat);
42-
let mut eat2: bool = (unsafe { (*animal).bark() });
42+
let mut eat2: bool = (unsafe { (*animal.cast_const()).bark() });
4343
return (((eat1) && (!eat2)) as i32);
4444
}

0 commit comments

Comments
 (0)