Skip to content

C2Rust Crashes on Anonymous Enum Without Field in Anonymous Union Inside Struct #1233

@Yeaseen

Description

@Yeaseen

C2Rust crashes when transpiling valid C code that includes an anonymous enum inside an anonymous union within a struct, due to the lack of a field name for the enum. While this is standard-compliant C (accepted by GCC and Clang), C2Rust panics with a missing key lookup in its AST processing.

C code:

struct temp {
    union {
        enum {
            VALUE_1,
            VALUE_2
        };
        int int_value;
    } u;
};

int main() {
    struct temp b;
    b.u.int_value = VALUE_2;
    return 0;
}

C2Rust error:

$c2rust-transpile compile_commands.json -e -o transpiled_code --binary runner
Transpiling runner.c
thread 'main' panicked at c2rust-transpile/src/c_ast/mod.rs:653:57:
no entry found for key
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

c2rust version: C2Rust 0.20.0

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