Skip to content

C2Rust panics in translator/simd.rs on __builtin_shufflevector with vector_size(16) vector typedef #1677

@rikki322

Description

@rikki322

C2Rust crashes when transpiling a valid C program that uses the GCC/Clang vector_size extension together with __builtin_shufflevector.
This appears related to incomplete vector/SIMD support, but unlike earlier failures such as unsupported vector initializer lists, this case triggers an internal panic in translator/simd.rs.
Reproducer

typedef int v4si __attribute__((vector_size(16)));

int main(void) {
    v4si a = {1, 2, 3, 4};
    v4si b = {5, 6, 7, 8};
    v4si c = __builtin_shufflevector(a, b, 3, 1, 2, 0);
    return c[0];
}

Observed Behavior
C2Rust reports unsupported vector type handling and then panics:

Transpiling test.c
error: Skipping declaration Some(Typedef { name: "v4si", typ: CQualTypeId { qualifiers: Qualifiers { is_const: false, is_restrict: false, is_volatile: false }, ctype: CTypeId(47) }, 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(31) }, 4)

thread 'main' panicked at 'internal error: entered unreachable code: Found something other than a cast cast: DeclRef(CQualTypeId { qualifiers: Qualifiers { is_const: false, is_restrict: false, is_volatile: false }, ctype: CTypeId(60) }, CDeclId(76), LValue)', c2rust-transpile/src/translator/simd.rs:496:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The input program is valid C using GCC/Clang vector extensions.
Even if this vector/SIMD feature is not yet supported, C2Rust should fail gracefully with a structured error, rather than panicking with entered unreachable code.
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