diff --git a/c2rust-transpile/src/c_ast/mod.rs b/c2rust-transpile/src/c_ast/mod.rs index dc45dca353..2b8a76e608 100644 --- a/c2rust-transpile/src/c_ast/mod.rs +++ b/c2rust-transpile/src/c_ast/mod.rs @@ -166,6 +166,13 @@ impl Located { pub fn end_loc(&self) -> Option { self.loc.map(|loc| loc.end()) } + + pub fn with_kind(&self, kind: U) -> Located { + Located { + loc: self.loc, + kind, + } + } } /// This holds a [`SrcLoc`] and its [`include_path`](TypedAstContext::include_path) @@ -1075,51 +1082,84 @@ impl TypedAstContext { } } - /// Identifies typedefs that name unnamed types. - /// Later, the two declarations can be collapsed into a single name and declaration, - /// eliminating the typedef altogether. - pub fn set_prenamed_decls(&mut self) { + /// Eliminates typedefs in various ways. Currently does the following: + /// - Typedefs that resolve to one of `PULLBACK_KINDS` will point directly to the target type, + /// without intermediate (compiler-internal) typedefs if there are any. + /// - Typedefs that point to structs, unions or enums that have no name, or the same name as + /// the typedef, are stored in `prenamed_decls` so they can be skipped later. + pub fn bypass_typedefs(&mut self) { + let mut replacements: HashMap = HashMap::new(); let mut prenamed_decls: IndexMap = IndexMap::new(); for (&decl_id, decl) in self.iter_decls() { - if let CDeclKind::Typedef { ref name, typ, .. } = decl.kind { - if let Some(subdecl_id) = self.resolve_type(typ.ctype).kind.as_underlying_decl() { - use CDeclKind::*; - let is_unnamed = match self[subdecl_id].kind { - Struct { name: None, .. } - | Union { name: None, .. } - | Enum { name: None, .. } => true, - - // Detect case where typedef and struct share the same name. - // In this case the purpose of the typedef was simply to eliminate - // the need for the 'struct' tag when referring to the type name. - Struct { - name: Some(ref target_name), - .. - } - | Union { - name: Some(ref target_name), - .. - } - | Enum { - name: Some(ref target_name), - .. - } => name == target_name, - - _ => false, - }; - - if is_unnamed - && !prenamed_decls - .values() - .any(|decl_id| *decl_id == subdecl_id) - { - prenamed_decls.insert(decl_id, subdecl_id); + let CDeclKind::Typedef { + ref name, + typ, + is_implicit, + ref target_dependent_macro, + } = decl.kind else { + continue + }; + let resolved_type_id = self.resolve_type_id(typ.ctype); + let resolved_type_kind = &self[resolved_type_id].kind; + + if CTypeKind::PULLBACK_KINDS.contains(resolved_type_kind) + && name == resolved_type_kind.as_str() + { + // If the typedef resolves to a portable type, and its name matches the + // expected name, then replace its definition to directly target the type, + // bypassing any intermediate typedefs. + let kind = CDeclKind::Typedef { + name: name.clone(), + typ: typ.with_ctype(resolved_type_id), + is_implicit, + target_dependent_macro: target_dependent_macro.clone(), + }; + replacements.insert(decl_id, decl.with_kind(kind)); + } else if let Some(subdecl_id) = resolved_type_kind.as_underlying_decl() { + use CDeclKind::*; + + // Identifies typedefs that name unnamed types. + // Later, the two declarations can be collapsed into a single name and declaration, + // eliminating the typedef altogether. + let is_unnamed = match self[subdecl_id].kind { + Struct { name: None, .. } + | Union { name: None, .. } + | Enum { name: None, .. } => true, + + // Detect case where typedef and struct share the same name. + // In this case the purpose of the typedef was simply to eliminate + // the need for the 'struct' tag when referring to the type name. + Struct { + name: Some(ref target_name), + .. } + | Union { + name: Some(ref target_name), + .. + } + | Enum { + name: Some(ref target_name), + .. + } => name == target_name, + + _ => false, + }; + + if is_unnamed + && !prenamed_decls + .values() + .any(|decl_id| *decl_id == subdecl_id) + { + prenamed_decls.insert(decl_id, subdecl_id); } } } + for (decl_id, decl) in replacements { + self.c_decls[&decl_id] = decl; + } + self.prenamed_decls = prenamed_decls; } @@ -2492,6 +2532,10 @@ impl CQualTypeId { ctype, } } + + pub fn with_ctype(self, ctype: CTypeId) -> Self { + Self { ctype, ..self } + } } // TODO: these may be interesting, but I'm not sure if they fit here: diff --git a/c2rust-transpile/src/translator/mod.rs b/c2rust-transpile/src/translator/mod.rs index 3998138b8e..81a859995c 100644 --- a/c2rust-transpile/src/translator/mod.rs +++ b/c2rust-transpile/src/translator/mod.rs @@ -709,9 +709,7 @@ pub fn translate( None }; - // Identify typedefs that name unnamed types and collapse the two declarations - // into a single name and declaration, eliminating the typedef altogether. - t.ast_context.set_prenamed_decls(); + t.ast_context.bypass_typedefs(); // Headers often pull in declarations that are unused; // we simplify the translator output by omitting those. diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 4f10e330ea..ca9727c3eb 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -420,6 +420,11 @@ fn test_main_fn() { transpile("main_fn.c").run(); } +#[test] +fn test_out_of_range_lit() { + transpile("out_of_range_lit.c").run(); +} + #[test] fn test_predefined() { transpile("predefined.c").run(); @@ -472,6 +477,11 @@ fn test_str_init() { transpile("str_init.c").run(); } +#[test] +fn test_typedefidx() { + transpile("typedefidx.c").run(); +} + #[test] fn test_types_compatible() { transpile("types_compatible.c").run(); @@ -526,11 +536,6 @@ fn test_macros_os_specific() { transpile("macros.c").os_specific(true).run(); } -#[test] -fn test_out_of_range_lit() { - transpile("out_of_range_lit.c").os_specific(true).run(); -} - #[test] fn test_rnd() { transpile("rnd.c").os_specific(true).run(); @@ -549,11 +554,6 @@ fn test_sigign() { .run(); } -#[test] -fn test_typedefidx() { - transpile("typedefidx.c").os_specific(true).run(); -} - #[test] fn test_types() { transpile("types.c") diff --git a/c2rust-transpile/tests/snapshots/os-specific/out_of_range_lit.c b/c2rust-transpile/tests/snapshots/out_of_range_lit.c similarity index 100% rename from c2rust-transpile/tests/snapshots/os-specific/out_of_range_lit.c rename to c2rust-transpile/tests/snapshots/out_of_range_lit.c diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.2021.macos.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.2021.macos.clang15.snap index abe190708f..c62e4c3575 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.2021.macos.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.2021.macos.clang15.snap @@ -19,8 +19,7 @@ extern "C" { __n: size_t, ) -> *mut ::core::ffi::c_void; } -pub type __darwin_size_t = usize; -pub type size_t = __darwin_size_t; +pub type size_t = usize; #[no_mangle] pub unsafe extern "C" fn errno_is_error() -> bool { return *__error() != 0 as ::core::ffi::c_int; diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.2024.macos.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.2024.macos.clang15.snap index 4b2b117ab0..67bc9dff79 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.2024.macos.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.2024.macos.clang15.snap @@ -20,8 +20,7 @@ unsafe extern "C" { __n: size_t, ) -> *mut ::core::ffi::c_void; } -pub type __darwin_size_t = usize; -pub type size_t = __darwin_size_t; +pub type size_t = usize; #[unsafe(no_mangle)] pub unsafe extern "C" fn errno_is_error() -> bool { return *__error() != 0 as ::core::ffi::c_int; diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2021.macos.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2021.clang15.snap similarity index 88% rename from c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2021.macos.clang15.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2021.clang15.snap index 6578a2f718..2363ec0b77 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2021.macos.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2021.clang15.snap @@ -1,6 +1,6 @@ --- source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-specific/out_of_range_lit.2021.macos.rs +expression: cat tests/snapshots/out_of_range_lit.2021.clang15.rs --- #![allow( clippy::missing_safety_doc, diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2021.linux.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2021.linux.clang15.snap deleted file mode 100644 index 82a8a5b67f..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2021.linux.clang15.snap +++ /dev/null @@ -1,22 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-specific/out_of_range_lit.2021.linux.clang15.rs ---- -#![allow( - clippy::missing_safety_doc, - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] -pub type __int32_t = i32; -pub type int32_t = __int32_t; -#[no_mangle] -pub unsafe extern "C" fn f() { - let mut a: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; - let mut b: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; - let mut c: int32_t = 0x8000000000000000 as ::core::ffi::c_ulong as int32_t; - let mut d: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; -} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2024.macos.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2024.clang15.snap similarity index 89% rename from c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2024.macos.clang15.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2024.clang15.snap index 8358f4491f..08f0751836 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2024.macos.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2024.clang15.snap @@ -1,6 +1,6 @@ --- source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-specific/out_of_range_lit.2024.macos.rs +expression: cat tests/snapshots/out_of_range_lit.2024.clang15.rs --- #![allow( clippy::missing_safety_doc, diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2024.linux.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2024.linux.clang15.snap deleted file mode 100644 index 53424ee721..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@out_of_range_lit.c.2024.linux.clang15.snap +++ /dev/null @@ -1,23 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-specific/out_of_range_lit.2024.linux.clang15.rs ---- -#![allow( - clippy::missing_safety_doc, - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unsafe_op_in_unsafe_fn, - unused_assignments, - unused_mut -)] -pub type __int32_t = i32; -pub type int32_t = __int32_t; -#[unsafe(no_mangle)] -pub unsafe extern "C" fn f() { - let mut a: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; - let mut b: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; - let mut c: int32_t = 0x8000000000000000 as ::core::ffi::c_ulong as int32_t; - let mut d: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; -} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@rnd.c.2021.linux.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@rnd.c.2021.linux.clang15.snap index 55a82cf507..c940b1d2f5 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@rnd.c.2021.linux.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@rnd.c.2021.linux.clang15.snap @@ -14,10 +14,8 @@ expression: cat tests/snapshots/os-specific/rnd.2021.linux.clang15.rs extern "C" { fn abs(__x: ::core::ffi::c_int) -> ::core::ffi::c_int; } -pub type __int32_t = i32; -pub type __uint32_t = u32; -pub type int32_t = __int32_t; -pub type uint32_t = __uint32_t; +pub type int32_t = i32; +pub type uint32_t = u32; #[no_mangle] pub static mut cur_rand_seed: uint32_t = 0 as uint32_t; #[no_mangle] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@rnd.c.2024.linux.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@rnd.c.2024.linux.clang15.snap index a98741a019..13fe8c2ff1 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@rnd.c.2024.linux.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@rnd.c.2024.linux.clang15.snap @@ -15,10 +15,8 @@ expression: cat tests/snapshots/os-specific/rnd.2024.linux.clang15.rs unsafe extern "C" { unsafe fn abs(__x: ::core::ffi::c_int) -> ::core::ffi::c_int; } -pub type __int32_t = i32; -pub type __uint32_t = u32; -pub type int32_t = __int32_t; -pub type uint32_t = __uint32_t; +pub type int32_t = i32; +pub type uint32_t = u32; #[unsafe(no_mangle)] pub static mut cur_rand_seed: uint32_t = 0 as uint32_t; #[unsafe(no_mangle)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2021.linux.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2021.clang15.snap similarity index 75% rename from c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2021.linux.clang15.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2021.clang15.snap index b6bb3dd590..a4af6bcb01 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2021.linux.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2021.clang15.snap @@ -1,6 +1,6 @@ --- source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-specific/typedefidx.2021.linux.clang15.rs +expression: cat tests/snapshots/typedefidx.2021.clang15.rs --- #![allow( clippy::missing_safety_doc, @@ -12,8 +12,7 @@ expression: cat tests/snapshots/os-specific/typedefidx.2021.linux.clang15.rs unused_mut )] pub type size_t = usize; -pub type __uint64_t = u64; -pub type uint64_t = __uint64_t; +pub type uint64_t = u64; #[no_mangle] pub unsafe extern "C" fn index_typedef(mut arr: *mut uint64_t) { let mut foo3: size_t = *arr.offset(25 as ::core::ffi::c_int as isize) as size_t; diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2021.macos.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2021.macos.clang15.snap deleted file mode 100644 index d3b4fc05ca..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2021.macos.clang15.snap +++ /dev/null @@ -1,20 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-specific/typedefidx.2021.macos.rs ---- -#![allow( - clippy::missing_safety_doc, - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] -pub type __darwin_size_t = usize; -pub type size_t = __darwin_size_t; -pub type uint64_t = u64; -#[no_mangle] -pub unsafe extern "C" fn index_typedef(mut arr: *mut uint64_t) { - let mut foo3: size_t = *arr.offset(25 as ::core::ffi::c_int as isize) as size_t; -} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2024.linux.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2024.clang15.snap similarity index 76% rename from c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2024.linux.clang15.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2024.clang15.snap index a3dba3b958..03eb1549dc 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2024.linux.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2024.clang15.snap @@ -1,6 +1,6 @@ --- source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-specific/typedefidx.2024.linux.clang15.rs +expression: cat tests/snapshots/typedefidx.2024.clang15.rs --- #![allow( clippy::missing_safety_doc, @@ -13,8 +13,7 @@ expression: cat tests/snapshots/os-specific/typedefidx.2024.linux.clang15.rs unused_mut )] pub type size_t = usize; -pub type __uint64_t = u64; -pub type uint64_t = __uint64_t; +pub type uint64_t = u64; #[unsafe(no_mangle)] pub unsafe extern "C" fn index_typedef(mut arr: *mut uint64_t) { let mut foo3: size_t = *arr.offset(25 as ::core::ffi::c_int as isize) as size_t; diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2024.macos.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2024.macos.clang15.snap deleted file mode 100644 index 2e5255825b..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@typedefidx.c.2024.macos.clang15.snap +++ /dev/null @@ -1,21 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-specific/typedefidx.2024.macos.rs ---- -#![allow( - clippy::missing_safety_doc, - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unsafe_op_in_unsafe_fn, - unused_assignments, - unused_mut -)] -pub type __darwin_size_t = usize; -pub type size_t = __darwin_size_t; -pub type uint64_t = u64; -#[unsafe(no_mangle)] -pub unsafe extern "C" fn index_typedef(mut arr: *mut uint64_t) { - let mut foo3: size_t = *arr.offset(25 as ::core::ffi::c_int as isize) as size_t; -} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2021.linux.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2021.linux.clang15.snap index 3f4e6302d1..39df61d09d 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2021.linux.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2021.linux.clang15.snap @@ -12,23 +12,15 @@ expression: cat tests/snapshots/os-specific/types.2021.linux.clang15.rs unused_mut )] pub type size_t = usize; -pub type __int8_t = i8; -pub type __uint8_t = u8; -pub type __int16_t = i16; -pub type __uint16_t = u16; -pub type __int32_t = i32; -pub type __uint32_t = u32; -pub type __int64_t = i64; -pub type __uint64_t = u64; pub type ssize_t = isize; -pub type int8_t = __int8_t; -pub type int16_t = __int16_t; -pub type int32_t = __int32_t; -pub type int64_t = __int64_t; -pub type uint8_t = __uint8_t; -pub type uint16_t = __uint16_t; -pub type uint32_t = __uint32_t; -pub type uint64_t = __uint64_t; +pub type int8_t = i8; +pub type int16_t = i16; +pub type int32_t = i32; +pub type int64_t = i64; +pub type uint8_t = u8; +pub type uint16_t = u16; +pub type uint32_t = u32; +pub type uint64_t = u64; pub type intptr_t = isize; pub type uintptr_t = usize; pub type intmax_t = ::libc::intmax_t; diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2021.macos.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2021.macos.clang15.snap index 8f6843c64e..d9ba7c1958 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2021.macos.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2021.macos.clang15.snap @@ -11,24 +11,21 @@ expression: cat tests/snapshots/os-specific/types.2021.macos.rs unused_assignments, unused_mut )] -pub type __darwin_ptrdiff_t = isize; -pub type __darwin_size_t = usize; -pub type __darwin_ssize_t = isize; pub type int8_t = i8; pub type int16_t = i16; pub type int32_t = i32; pub type int64_t = i64; pub type intptr_t = isize; pub type uintptr_t = usize; -pub type size_t = __darwin_size_t; +pub type size_t = usize; pub type uint8_t = u8; pub type uint16_t = u16; pub type uint32_t = u32; pub type uint64_t = u64; pub type intmax_t = ::libc::intmax_t; pub type uintmax_t = ::libc::uintmax_t; -pub type ptrdiff_t = __darwin_ptrdiff_t; -pub type ssize_t = __darwin_ssize_t; +pub type ptrdiff_t = isize; +pub type ssize_t = isize; #[no_mangle] pub static mut intvar: ::core::ffi::c_int = 0 as ::core::ffi::c_int; #[no_mangle] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2024.linux.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2024.linux.clang15.snap index 75ab46d854..f359603b5f 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2024.linux.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2024.linux.clang15.snap @@ -13,23 +13,15 @@ expression: cat tests/snapshots/os-specific/types.2024.linux.clang15.rs unused_mut )] pub type size_t = usize; -pub type __int8_t = i8; -pub type __uint8_t = u8; -pub type __int16_t = i16; -pub type __uint16_t = u16; -pub type __int32_t = i32; -pub type __uint32_t = u32; -pub type __int64_t = i64; -pub type __uint64_t = u64; pub type ssize_t = isize; -pub type int8_t = __int8_t; -pub type int16_t = __int16_t; -pub type int32_t = __int32_t; -pub type int64_t = __int64_t; -pub type uint8_t = __uint8_t; -pub type uint16_t = __uint16_t; -pub type uint32_t = __uint32_t; -pub type uint64_t = __uint64_t; +pub type int8_t = i8; +pub type int16_t = i16; +pub type int32_t = i32; +pub type int64_t = i64; +pub type uint8_t = u8; +pub type uint16_t = u16; +pub type uint32_t = u32; +pub type uint64_t = u64; pub type intptr_t = isize; pub type uintptr_t = usize; pub type intmax_t = ::libc::intmax_t; diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2024.macos.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2024.macos.clang15.snap index de087b13d9..49593074f5 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2024.macos.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@types.c.2024.macos.clang15.snap @@ -12,24 +12,21 @@ expression: cat tests/snapshots/os-specific/types.2024.macos.rs unused_assignments, unused_mut )] -pub type __darwin_ptrdiff_t = isize; -pub type __darwin_size_t = usize; -pub type __darwin_ssize_t = isize; pub type int8_t = i8; pub type int16_t = i16; pub type int32_t = i32; pub type int64_t = i64; pub type intptr_t = isize; pub type uintptr_t = usize; -pub type size_t = __darwin_size_t; +pub type size_t = usize; pub type uint8_t = u8; pub type uint16_t = u16; pub type uint32_t = u32; pub type uint64_t = u64; pub type intmax_t = ::libc::intmax_t; pub type uintmax_t = ::libc::uintmax_t; -pub type ptrdiff_t = __darwin_ptrdiff_t; -pub type ssize_t = __darwin_ssize_t; +pub type ptrdiff_t = isize; +pub type ssize_t = isize; #[unsafe(no_mangle)] pub static mut intvar: ::core::ffi::c_int = 0 as ::core::ffi::c_int; #[unsafe(no_mangle)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2021.macos.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2021.macos.clang15.snap index af715c7395..1ceff22a2a 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2021.macos.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2021.macos.clang15.snap @@ -15,10 +15,8 @@ expression: cat tests/snapshots/os-specific/wide_strings.2021.macos.rs extern "C" { fn wcslen(_: *const wchar_t) -> ::core::ffi::c_ulong; } -pub type __darwin_size_t = usize; -pub type __darwin_wchar_t = ::libc::wchar_t; -pub type size_t = __darwin_size_t; -pub type wchar_t = __darwin_wchar_t; +pub type size_t = usize; +pub type wchar_t = ::libc::wchar_t; #[no_mangle] pub static mut static_array: [wchar_t; 2] = unsafe { ::core::mem::transmute::<[u8; 8], [wchar_t; 2]>(*b"x\0\0\0\0\0\0\0") }; diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2021.macos.clang22.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2021.macos.clang22.snap index c19b35442b..0948979cd3 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2021.macos.clang22.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2021.macos.clang22.snap @@ -15,10 +15,8 @@ expression: cat tests/snapshots/os-specific/wide_strings.2021.macos.clang22.rs extern "C" { fn wcslen(_: *const wchar_t) -> usize; } -pub type __darwin_size_t = usize; -pub type __darwin_wchar_t = ::libc::wchar_t; -pub type size_t = __darwin_size_t; -pub type wchar_t = __darwin_wchar_t; +pub type size_t = usize; +pub type wchar_t = ::libc::wchar_t; #[no_mangle] pub static mut static_array: [wchar_t; 2] = unsafe { ::core::mem::transmute::<[u8; 8], [wchar_t; 2]>(*b"x\0\0\0\0\0\0\0") }; diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2024.macos.clang15.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2024.macos.clang15.snap index 645cb2d7dd..81f4f0568b 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2024.macos.clang15.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2024.macos.clang15.snap @@ -15,10 +15,8 @@ expression: cat tests/snapshots/os-specific/wide_strings.2024.macos.rs unsafe extern "C" { unsafe fn wcslen(_: *const wchar_t) -> ::core::ffi::c_ulong; } -pub type __darwin_size_t = usize; -pub type __darwin_wchar_t = ::libc::wchar_t; -pub type size_t = __darwin_size_t; -pub type wchar_t = __darwin_wchar_t; +pub type size_t = usize; +pub type wchar_t = ::libc::wchar_t; #[unsafe(no_mangle)] pub static mut static_array: [wchar_t; 2] = unsafe { ::core::mem::transmute::<[u8; 8], [wchar_t; 2]>(*b"x\0\0\0\0\0\0\0") }; diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2024.macos.clang22.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2024.macos.clang22.snap index ef2d8b24e4..51a9510f93 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2024.macos.clang22.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2024.macos.clang22.snap @@ -15,10 +15,8 @@ expression: cat tests/snapshots/os-specific/wide_strings.2024.macos.clang22.rs unsafe extern "C" { unsafe fn wcslen(_: *const wchar_t) -> usize; } -pub type __darwin_size_t = usize; -pub type __darwin_wchar_t = ::libc::wchar_t; -pub type size_t = __darwin_size_t; -pub type wchar_t = __darwin_wchar_t; +pub type size_t = usize; +pub type wchar_t = ::libc::wchar_t; #[unsafe(no_mangle)] pub static mut static_array: [wchar_t; 2] = unsafe { ::core::mem::transmute::<[u8; 8], [wchar_t; 2]>(*b"x\0\0\0\0\0\0\0") }; diff --git a/c2rust-transpile/tests/snapshots/os-specific/typedefidx.c b/c2rust-transpile/tests/snapshots/typedefidx.c similarity index 100% rename from c2rust-transpile/tests/snapshots/os-specific/typedefidx.c rename to c2rust-transpile/tests/snapshots/typedefidx.c