Skip to content

Commit a6d4f3b

Browse files
committed
Update test
1 parent d053639 commit a6d4f3b

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎tests/unit/flex_array_member_incomplete.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@ int main(void) {
1717
assert(strcmp(f->tail, "xyz") == 0);
1818
assert(f->tail[1] == 'y');
1919
free(f);
20+
struct F *g = malloc(sizeof(struct F) + 8);
21+
assert(g != NULL);
22+
g->n = 8;
23+
memcpy(g->tail, "abcdefg", 8);
24+
assert(g->tail[6] == 'g');
25+
assert(g->tail[7] == '\0');
26+
free(g);
2027
return 0;
2128
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,30 @@ fn main_0() -> i32 {
6666
!= 0)
6767
);
6868
libcc2rs::free_refcount((f).to_any());
69+
let mut g: Ptr<F> =
70+
libcc2rs::malloc_refcount((4usize as usize).wrapping_add(8_usize)).reinterpret_cast::<F>();
71+
assert!((((!((g).is_null())) as i32) != 0));
72+
field!(g, n).write(8);
73+
{
74+
((array_field_ptr!(g, tail) as Ptr<i8>) as Ptr<i8>)
75+
.to_any()
76+
.memcpy(
77+
&Ptr::<i8>::from_string_literal(b"abcdefg").to_any(),
78+
8_usize as usize,
79+
);
80+
((array_field_ptr!(g, tail) as Ptr<i8>) as Ptr<i8>).to_any()
81+
};
82+
assert!(
83+
(((((elem!((array_field_ptr!(g, tail) as Ptr::<i8>), 6).read()) as i32) == ('g' as i32))
84+
as i32)
85+
!= 0)
86+
);
87+
assert!(
88+
(((((elem!((array_field_ptr!(g, tail) as Ptr::<i8>), 7).read()) as i32) == ('\0' as i32))
89+
as i32)
90+
!= 0)
91+
);
92+
libcc2rs::free_refcount((g).to_any());
6993
return 0;
7094
}
7195
pub fn __cpp2rust_init_globals() {}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ unsafe fn main_0() -> i32 {
5050
);
5151
assert!((((((*(*f).tail.as_mut_ptr().add((1) as usize)) as i32) == ('y' as i32)) as i32) != 0));
5252
libcc2rs::free_unsafe((f as *mut ::libc::c_void));
53+
let mut g: *mut F =
54+
(libcc2rs::malloc_unsafe((::std::mem::size_of::<F>() as usize).wrapping_add(8_usize))
55+
as *mut F);
56+
assert!((((!((g).is_null())) as i32) != 0));
57+
(*g).n = 8;
58+
{
59+
if 8_usize != 0 {
60+
::std::ptr::copy_nonoverlapping(
61+
(c"abcdefg".as_ptr().cast_mut() as *const ::libc::c_void),
62+
((*g).tail.as_mut_ptr() as *mut ::libc::c_void),
63+
8_usize as usize,
64+
)
65+
}
66+
((*g).tail.as_mut_ptr() as *mut ::libc::c_void)
67+
};
68+
assert!((((((*(*g).tail.as_mut_ptr().add((6) as usize)) as i32) == ('g' as i32)) as i32) != 0));
69+
assert!(
70+
(((((*(*g).tail.as_mut_ptr().add((7) as usize)) as i32) == ('\0' as i32)) as i32) != 0)
71+
);
72+
libcc2rs::free_unsafe((g as *mut ::libc::c_void));
5373
return 0;
5474
}
5575
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)