Skip to content

C2Rust fails to translate indexing on GCC/Clang vector types (Attempting to index a vector type) #1676

@chisa22

Description

@chisa22

C2Rust fails to transpile a valid C program using the GCC/Clang vector_size extension when indexing a vector value.
The program defines a vector type via attribute((vector_size(16))), initializes a vector value, and then accesses one element with vec[0]. During transpilation, C2Rust skips the vector typedef due to unsupported CType::Vector, and then fails to translate main with Attempting to index a vector type.
Reproducer

#include <stdint.h>
#include <stdio.h>

int main(void) {
    typedef float v4sf __attribute__((vector_size(16)));
    v4sf vec = { 5.0f, 6.0f, 7.0f, 8.0f };
    printf("%g\n", vec[0]);
    return 0;
}

Observed Behavior
C2Rust reports:

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

error: Failed to translate main: Attempting to index a vector type

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