-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathsnapshots__transpile@bitfields.c.2021.clang15.snap
More file actions
61 lines (61 loc) · 2.03 KB
/
Copy pathsnapshots__transpile@bitfields.c.2021.clang15.snap
File metadata and controls
61 lines (61 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
source: c2rust-transpile/tests/snapshots.rs
expression: cat tests/snapshots/bitfields.2021.clang15.rs
---
#![allow(
clippy::missing_safety_doc,
dead_code,
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unused_assignments,
unused_mut
)]
extern "C" {
fn printf(_: *const ::core::ffi::c_char, ...) -> ::core::ffi::c_int;
}
#[derive(Copy, Clone, ::c2rust_bitfields::BitfieldStruct)]
#[repr(C)]
pub struct PacketHeader {
#[bitfield(padding)]
pub c2rust_padding: [u8; 1],
#[bitfield(name = "version", ty = "::core::ffi::c_uchar", bits = "0..=2")]
#[bitfield(name = "r#type", ty = "::core::ffi::c_uchar", bits = "3..=4")]
#[bitfield(name = "flags", ty = "::core::ffi::c_uchar", bits = "5..=7")]
#[bitfield(name = "sequence", ty = "::core::ffi::c_ushort", bits = "16..=25")]
#[bitfield(name = "length", ty = "::core::ffi::c_ushort", bits = "26..=31")]
pub version_type_flags_sequence_length: [u8; 3],
}
#[derive(Copy, Clone, ::c2rust_bitfields::BitfieldStruct)]
#[repr(C)]
pub struct SingleRawIdent {
#[bitfield(name = "r#as", ty = "::core::ffi::c_uchar", bits = "0..=2")]
pub r#as: [u8; 1],
}
#[no_mangle]
pub unsafe extern "C" fn test_bitfields() {
let mut h: PacketHeader = {
let mut init = PacketHeader {
c2rust_padding: [0; 1],
version_type_flags_sequence_length: [0; 3],
};
init.set_version(0 as ::core::ffi::c_uchar);
init.set_type(0);
init.set_flags(0);
init.set_sequence(0);
init.set_length(0);
init
};
h.set_version(5 as ::core::ffi::c_uchar as ::core::ffi::c_uchar);
h.set_sequence(513 as ::core::ffi::c_ushort as ::core::ffi::c_ushort);
printf(
b"version=%u sequence=%u\n\0".as_ptr() as *const ::core::ffi::c_char,
h.version() as ::core::ffi::c_int,
h.sequence() as ::core::ffi::c_int,
);
let mut s: SingleRawIdent = {
let mut init = SingleRawIdent { r#as: [0; 1] };
init.set_as(0 as ::core::ffi::c_uchar);
init
};
}