Skip to content

C2Rust skips vector typedef __m128i_u from <immintrin.h> and generates Rust code that fails to compile #1649

@chisa22

Description

@chisa22

When transpiling a C program that includes <immintrin.h>, C2Rust reports that the typedef __m128i_u is skipped because it uses an unsupported vector type (CType::Vector). However, C2Rust still emits a Rust file that references __m128i_u, which is not defined in Rust, causing the generated code to fail compilation.
This indicates that C2Rust does not support Clang vector typedefs used in SIMD headers and does not provide a fallback or stop generation when such types are skipped.
Reproducer

#include <immintrin.h>

int main(void) {
    __m128i_u x;   // force referencing the typedef
    (void)x;
    return 0;
}

Use c2rust transpile test.c
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::_mm_setzero_si128;
#[cfg(target_arch = "x86_64")]
pub use ::core::arch::x86_64::_mm_setzero_si128;
unsafe fn main_0() -> ::core::ffi::c_int {
    let mut x: __m128i_u = _mm_setzero_si128();
    return 0 as ::core::ffi::c_int;
}
pub fn main() {
    unsafe { ::std::process::exit(main_0() as i32) }
}

Observed Behavior
During transpilation:

Transpiling test.c
error: Skipping declaration Some(Typedef { name: "__m128i_u", typ: CQualTypeId { qualifiers: Qualifiers { is_const: false, is_restrict: false, is_volatile: false }, ctype: CTypeId(5206) }, is_implicit: false, target_dependent_macro: None }) due to error: Unsupported type Vector(CQualTypeId { qualifiers: Qualifiers { is_const: false, is_restrict: false, is_volatile: false }, ctype: CTypeId(292) }, 2)

Despite this error, C2Rust still produces a Rust file.
Compiling the generated Rust then fails:

error[E0412]: cannot find type `__m128i_u` in this scope

Environment

  • c2rust version: v0.21.0
  • platform:Ubuntu 24.04
  • Rust: nightly-2022-08-08
  • Clang version:17.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions