C2Rust generates `_mm_storeu_si32` calls that fail to compile across Rust toolchains (missing intrinsic or incorrect pointer type)
When transpiling C code that uses the SSE intrinsic _mm_storeu_si32, C2Rust generates Rust code importing and calling _mm_storeu_si32 from core::arch::{x86,x86_64}.
However, the generated code fails to compile across different Rust toolchains:
- On older toolchains (e.g.,
rustc 1.65.0-nightly), the intrinsic_mm_storeu_si32is not available, causing an unresolved import error (E0432). - On newer toolchains (e.g.,
rustc 1.92.0-nightly), the intrinsic exists but its Rust signature expects*mut u8, while C2Rust generates a*mut c_void, causing a type mismatch (E0308). As a result, the generated Rust code does not compile on either toolchain.
Reproducer
#include <immintrin.h>
int main() {
int val = 777;
__m128i simd_vec = _mm_set1_epi32(val);
__m128i add_vec = _mm_set1_epi32(111);
__m128i result = _mm_add_epi32(simd_vec, add_vec);
int simd_result;
_mm_storeu_si32(&simd_result, result);
}
Run c2rust transpile test.c
C2Rust generated Rust
#![allow(
dead_code,
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unused_assignments,
unused_mut
)]
#![feature(stdsimd)]
#[cfg(target_arch = "x86")]
pub use ::core::arch::x86::{
__m128i, _mm_add_epi32, _mm_set_epi32, _mm_set1_epi32, _mm_storeu_si32,
_mm_setzero_si128,
};
#[cfg(target_arch = "x86_64")]
pub use ::core::arch::x86_64::{
__m128i, _mm_add_epi32, _mm_set_epi32, _mm_set1_epi32, _mm_storeu_si32,
_mm_setzero_si128,
};
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct __storeu_si32 {
pub __v: ::core::ffi::c_int,
}
unsafe fn main_0() -> ::core::ffi::c_int {
let mut val: ::core::ffi::c_int = 777 as ::core::ffi::c_int;
let mut simd_vec: __m128i = _mm_set1_epi32(val);
let mut add_vec: __m128i = _mm_set1_epi32(111 as ::core::ffi::c_int);
let mut result: __m128i = _mm_add_epi32(simd_vec, add_vec);
let mut simd_result: ::core::ffi::c_int = 0;
_mm_storeu_si32(
&mut simd_result as *mut ::core::ffi::c_int as *mut ::core::ffi::c_void,
result,
);
return 0;
}
pub fn main() {
unsafe { ::std::process::exit(main_0() as i32) }
}
Observed Behavior
- Compilation fails with:
error[E0432]: unresolved import `core::arch::x86_64::_mm_storeu_si32`
in nightly-2022-08-08(rustc 1.65.0-nightly (d394408fb 2022-08-07))
- Compilation fails with:
error[E0308]: mismatched types
expected *mut u8
found *mut c_void
in nightly-2025-10-02(rustc 1.92.0-nightly (4da69dfff 2025-10-01))
Environment
- c2rust version: v0.21.0
- platform:Ubuntu 24.04
- rustc 1.65.0-nightly (d394408fb 2022-08-07)
- rustc 1.92.0-nightly (4da69dfff 2025-10-01)
I'd like to work on this issue. I've analyzed the codebase and have a fix ready.
I'd like to work on this issue. I've analyzed the codebase and have a fix ready.
Thanks! One thing to be aware of is we're in the middle of upgrading the transpiler to emit edition 2024 code (while still supporting edition 2021 with the pinned nightly). We're doing that in #1643.