Skip to content

Commit 93ab31b

Browse files
committed
transpile: add auto_type test
1 parent 7caecf8 commit 93ab31b

4 files changed

Lines changed: 76 additions & 0 deletions

File tree

c2rust-transpile/tests/snapshots.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ fn test_atomics() {
314314
transpile("atomics.c").run();
315315
}
316316

317+
#[test]
318+
fn test_auto_type() {
319+
transpile("auto_type.c").run();
320+
}
321+
317322
#[test]
318323
fn test_bitfields() {
319324
transpile("bitfields.c").expect_compile_error(true).run();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct bar {
2+
int x;
3+
};
4+
5+
int foo() {
6+
__auto_type x = 42;
7+
__auto_type px = &x;
8+
__auto_type sx = sizeof(x);
9+
__auto_type y = (struct bar) { .x = x };
10+
return y.x;
11+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
source: c2rust-transpile/tests/snapshots.rs
3+
expression: cat tests/snapshots/auto_type.2021.rs
4+
---
5+
#![allow(
6+
clippy::missing_safety_doc,
7+
dead_code,
8+
non_camel_case_types,
9+
non_snake_case,
10+
non_upper_case_globals,
11+
unused_assignments,
12+
unused_mut
13+
)]
14+
#![feature(raw_ref_op)]
15+
#[derive(Copy, Clone)]
16+
#[repr(C)]
17+
pub struct bar {
18+
pub x: ::core::ffi::c_int,
19+
}
20+
#[no_mangle]
21+
pub unsafe extern "C" fn foo() -> ::core::ffi::c_int {
22+
let mut x: ::core::ffi::c_int = 42 as ::core::ffi::c_int;
23+
let mut px: *mut ::core::ffi::c_int = &raw mut x;
24+
let mut sx: ::core::ffi::c_ulong =
25+
::core::mem::size_of::<::core::ffi::c_int>() as ::core::ffi::c_ulong;
26+
let mut y: bar = bar {
27+
x: x as ::core::ffi::c_int,
28+
} as bar;
29+
return y.x;
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
source: c2rust-transpile/tests/snapshots.rs
3+
expression: cat tests/snapshots/auto_type.2024.rs
4+
---
5+
#![allow(
6+
clippy::missing_safety_doc,
7+
dead_code,
8+
non_camel_case_types,
9+
non_snake_case,
10+
non_upper_case_globals,
11+
unsafe_op_in_unsafe_fn,
12+
unused_assignments,
13+
unused_mut
14+
)]
15+
#[derive(Copy, Clone)]
16+
#[repr(C)]
17+
pub struct bar {
18+
pub x: ::core::ffi::c_int,
19+
}
20+
#[unsafe(no_mangle)]
21+
pub unsafe extern "C" fn foo() -> ::core::ffi::c_int {
22+
let mut x: ::core::ffi::c_int = 42 as ::core::ffi::c_int;
23+
let mut px: *mut ::core::ffi::c_int = &raw mut x;
24+
let mut sx: ::core::ffi::c_ulong =
25+
::core::mem::size_of::<::core::ffi::c_int>() as ::core::ffi::c_ulong;
26+
let mut y: bar = bar {
27+
x: x as ::core::ffi::c_int,
28+
} as bar;
29+
return y.x;
30+
}

0 commit comments

Comments
 (0)