diff --git a/c2rust-transpile/src/translator/builtins.rs b/c2rust-transpile/src/translator/builtins.rs index 60275f9867..6ce9f13572 100644 --- a/c2rust-transpile/src/translator/builtins.rs +++ b/c2rust-transpile/src/translator/builtins.rs @@ -613,6 +613,9 @@ impl<'c> Translation<'c> { ) }) } + + // TODO: provide proper implementation, this is just to get stuff building + "__builtin_assume" => Ok(self.convert_expr(ctx.used(), args[0])?), // There's currently no way to replicate this functionality in Rust, so we just // pass the ptr input param in its place. "__builtin_assume_aligned" => Ok(self.convert_expr(ctx.used(), args[0])?), diff --git a/c2rust-transpile/src/translator/simd.rs b/c2rust-transpile/src/translator/simd.rs index 0363b0ff66..ff7c9c374f 100644 --- a/c2rust-transpile/src/translator/simd.rs +++ b/c2rust-transpile/src/translator/simd.rs @@ -91,7 +91,9 @@ impl<'c> Translation<'c> { pub fn import_simd_typedef(&self, name: &str) -> TranslationResult { Ok(match name { // Public API SIMD typedefs: - "__m128i" | "__m128" | "__m128d" | "__m64" | "__m256" | "__m256d" | "__m256i" => { + "__m64" | "__m128i" | "__m128i_u" | "__m128" | "__m128d" | "__m128_u" | "__m256" + | "__m256d" | "__m256_u" | "__m256i" | "__m256i_u" | "__m512 " | "__m512d" + | "__m512i" | "__m512i_u" | "__m512_u" => { // __m64 and MMX support were removed from upstream Rust. // See https://github.com/immunant/c2rust/issues/369 if name == "__m64" { @@ -100,6 +102,21 @@ impl<'c> Translation<'c> { ).into()); } + // Drop the `_u` suffix for unaligned SIMD types as they have + // no equivalents in Rust. Warn the user about possible probems. + let name = if name.ends_with("_u") { + warn!( + "Unaligned SIMD type {} has no equivalent in Rust. \ + Emitting {} instead. This likely means the potential \ + for miscompilation has been introduced.", + name, + &name[..name.len() - 2] + ); + &name[..name.len() - 2] + } else { + name + }; + self.with_cur_file_item_store(|item_store| { add_arch_use(item_store, "x86", name); add_arch_use(item_store, "x86_64", name); diff --git a/c2rust-transpile/src/translator/structs.rs b/c2rust-transpile/src/translator/structs.rs index fae47c4d15..6c83d8c997 100644 --- a/c2rust-transpile/src/translator/structs.rs +++ b/c2rust-transpile/src/translator/structs.rs @@ -377,7 +377,33 @@ impl<'a> Translation<'a> { field_entries.push(field); } - FieldType::Regular { field, .. } => field_entries.push(*field), + FieldType::Regular { + mut field, name, .. + } => { + if let crate::translator::Type::Path(segments, ..) = &field.ty { + for seg in &segments.path.segments { + let tynam = seg.ident.to_string(); + match tynam.as_str() { + "__m128i_u" | "__m128_u" | "__m256i_u" | "__m256_u" + | "__m512_u" | "__m512i_u" => { + // TODO: We might already have emitted a warning in `import_simd_typedef`, + // is it always safe to skip the warning here? + log::warn!("Unaligned SIMD type {} in field {} has no equivalent in Rust. \ + Emitting {} instead. This likely means the potential \ + for miscompilation has been introduced.", + tynam, + name, + &tynam[..tynam.len() - 2], + ); + field.ty = *mk().ident_ty(&tynam[..tynam.len() - 2]); + break; + } + _ => {} + } + } + } + field_entries.push(*field) + } } } Ok((field_entries, contains_va_list))