Skip to content

Commit 536d7fe

Browse files
Ruafw-immunant
authored andcommitted
transpile: Tidy up arrays.c snapshot test
1 parent a2c2149 commit 536d7fe

File tree

2 files changed

+47
-55
lines changed

2 files changed

+47
-55
lines changed

c2rust-transpile/tests/snapshots/arrays.c

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,28 @@ static char simple[] = "mystring";
44
static char *foo = "mystring";
55

66
void entry(void) {
7-
int arr[1][1] = { 1 };
8-
arr[0][0] += 9;
9-
10-
int arr2[16] = {};
11-
arr2[15] += 9;
12-
13-
struct {char* x; int y;} arr3[1] = {};
14-
arr3[0].y += 9;
15-
16-
int arr4[16] = {0};
17-
arr4[15] += 9;
18-
19-
struct {short; int y;} arr5[1] = { { 1, 2 } };
20-
arr5[0].y += 9;
21-
22-
// excess elements
23-
int arr6[2] = { 1, 2, 3 };
24-
int arr7[0] = { 1234 };
25-
26-
char abc[] = "abc";
27-
28-
char def[] = {'d','e','f'};
29-
30-
char part[2] = {1};
31-
32-
char *abcptr = "abc";
33-
34-
char init[] = {"abcd"};
35-
36-
char too_long[3] = "abcde";
37-
38-
char too_short[20] = "abc";
7+
int int_2d[1][1] = { 1 };
8+
int_2d[0][0] += 9;
9+
int int_empty_init[16] = {};
10+
int_empty_init[15] += 9;
11+
int int_too_long[2] = { 1, 2, 3 };
12+
int int_zero[0] = { 1234 };
13+
int int_too_short[16] = {0};
14+
int_too_short[15] += 9;
15+
16+
struct {char* x; int y;} struct_init_too_short[1] = {};
17+
struct_init_too_short[0].y += 9;
18+
struct {short; int y;} struct_init_too_long[1] = { { 1, 2 } };
19+
struct_init_too_long[0].y += 9;
20+
21+
char char_with_string[] = "abc";
22+
char char_with_chars[] = {'d','e','f'};
23+
char char_with_ints[2] = {1};
24+
char char_with_init[] = {"abcd"};
25+
char char_too_long[3] = "abcde";
26+
char char_too_short[20] = "abc";
27+
28+
char *char_ptr = "abc";
3929

4030
// TODO re-enable after #1266 adds portable support for translating `wchar_t`.
4131
#if 0

c2rust-transpile/tests/snapshots/[email protected]

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,45 +40,47 @@ static mut foo: *mut ::core::ffi::c_char =
4040
b"mystring\0" as *const u8 as *const ::core::ffi::c_char as *mut ::core::ffi::c_char;
4141
#[no_mangle]
4242
pub unsafe extern "C" fn entry() {
43-
let mut arr: [[::core::ffi::c_int; 1]; 1] = [[1 as ::core::ffi::c_int]];
44-
arr[0 as ::core::ffi::c_int as usize][0 as ::core::ffi::c_int as usize] +=
43+
let mut int_2d: [[::core::ffi::c_int; 1]; 1] = [[1 as ::core::ffi::c_int]];
44+
int_2d[0 as ::core::ffi::c_int as usize][0 as ::core::ffi::c_int as usize] +=
4545
9 as ::core::ffi::c_int;
46-
let mut arr2: [::core::ffi::c_int; 16] = [0; 16];
47-
arr2[15 as ::core::ffi::c_int as usize] += 9 as ::core::ffi::c_int;
48-
let mut arr3: [C2RustUnnamed_0; 1] = [C2RustUnnamed_0 {
46+
let mut int_empty_init: [::core::ffi::c_int; 16] = [0; 16];
47+
int_empty_init[15 as ::core::ffi::c_int as usize] += 9 as ::core::ffi::c_int;
48+
let mut int_too_long: [::core::ffi::c_int; 2] =
49+
[1 as ::core::ffi::c_int, 2 as ::core::ffi::c_int];
50+
let mut int_zero: [::core::ffi::c_int; 0] = [0; 0];
51+
let mut int_too_short: [::core::ffi::c_int; 16] = [0 as ::core::ffi::c_int; 16];
52+
int_too_short[15 as ::core::ffi::c_int as usize] += 9 as ::core::ffi::c_int;
53+
let mut struct_init_too_short: [C2RustUnnamed_0; 1] = [C2RustUnnamed_0 {
4954
x: 0 as *mut ::core::ffi::c_char,
5055
y: 0,
5156
}; 1];
52-
arr3[0 as ::core::ffi::c_int as usize].y += 9 as ::core::ffi::c_int;
53-
let mut arr4: [::core::ffi::c_int; 16] = [0 as ::core::ffi::c_int; 16];
54-
arr4[15 as ::core::ffi::c_int as usize] += 9 as ::core::ffi::c_int;
55-
let mut arr5: [C2RustUnnamed; 1] = [{
57+
struct_init_too_short[0 as ::core::ffi::c_int as usize].y += 9 as ::core::ffi::c_int;
58+
let mut struct_init_too_long: [C2RustUnnamed; 1] = [{
5659
let mut init = C2RustUnnamed {
5760
y: 1 as ::core::ffi::c_int,
5861
};
5962
init
6063
}];
61-
arr5[0 as ::core::ffi::c_int as usize].y += 9 as ::core::ffi::c_int;
62-
let mut arr6: [::core::ffi::c_int; 2] = [1 as ::core::ffi::c_int, 2 as ::core::ffi::c_int];
63-
let mut arr7: [::core::ffi::c_int; 0] = [0; 0];
64-
let mut abc: [::core::ffi::c_char; 4] =
64+
struct_init_too_long[0 as ::core::ffi::c_int as usize].y += 9 as ::core::ffi::c_int;
65+
let mut char_with_string: [::core::ffi::c_char; 4] =
6566
::core::mem::transmute::<[u8; 4], [::core::ffi::c_char; 4]>(*b"abc\0");
66-
let mut def: [::core::ffi::c_char; 3] = [
67+
let mut char_with_chars: [::core::ffi::c_char; 3] = [
6768
'd' as i32 as ::core::ffi::c_char,
6869
'e' as i32 as ::core::ffi::c_char,
6970
'f' as i32 as ::core::ffi::c_char,
7071
];
71-
let mut part: [::core::ffi::c_char; 2] = [1 as ::core::ffi::c_int as ::core::ffi::c_char, 0];
72-
let mut abcptr: *mut ::core::ffi::c_char =
73-
b"abc\0" as *const u8 as *const ::core::ffi::c_char as *mut ::core::ffi::c_char;
74-
let mut init: [::core::ffi::c_char; 5] =
72+
let mut char_with_ints: [::core::ffi::c_char; 2] =
73+
[1 as ::core::ffi::c_int as ::core::ffi::c_char, 0];
74+
let mut char_with_init: [::core::ffi::c_char; 5] =
7575
::core::mem::transmute::<[u8; 5], [::core::ffi::c_char; 5]>(*b"abcd\0");
76-
let mut too_long: [::core::ffi::c_char; 3] =
76+
let mut char_too_long: [::core::ffi::c_char; 3] =
7777
::core::mem::transmute::<[u8; 3], [::core::ffi::c_char; 3]>(*b"abc");
78-
let mut too_short: [::core::ffi::c_char; 20] = ::core::mem::transmute::<
79-
[u8; 20],
80-
[::core::ffi::c_char; 20],
81-
>(*b"abc\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
78+
let mut char_too_short: [::core::ffi::c_char; 20] =
79+
::core::mem::transmute::<[u8; 20], [::core::ffi::c_char; 20]>(
80+
*b"abc\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
81+
);
82+
let mut char_ptr: *mut ::core::ffi::c_char =
83+
b"abc\0" as *const u8 as *const ::core::ffi::c_char as *mut ::core::ffi::c_char;
8284
let mut past_end: *mut ::core::ffi::c_char = &mut *simple
8385
.as_mut_ptr()
8486
.offset(::core::mem::size_of::<[::core::ffi::c_char; 9]>() as isize)

0 commit comments

Comments
 (0)