Skip to content

C2Rust panics when translating C99 complex number using I from <complex.h> #1802

@lynae99

Description

@lynae99

C2Rust crashes when translating a valid C program that uses C99 complex numbers and the imaginary unit macro I from <complex.h>.
The translator first reports an invalid exported Clang AST involving a TagUnaryOperator node from the macro expansion I, then panics with no entry found for key.
Even if C2Rust does not fully support complex floating-point types or the I macro, it should emit a graceful unsupported-feature diagnostic instead of panicking.
To Reproduce

#include <complex.h>

int main(void) {
    double complex z = 1.0 + 2.0 * I;
    return 0;
}

Run C2Rust translation:

c2rust transpile test.c

Observed Behavior

Transpiling test.c
warning: Missing child 96774104899376 of node AstNode { tag: TagUnaryOperator, children: [Some(96774104899376)], loc: SrcSpan { fileid: 5, begin_line: 4, begin_column: 36, end_line: 4, end_column: 36 }, type_id: Some(96774104846208), rvalue: RValue, macro_expansions: [], macro_expansion_text: Some("I"), extras: [Text("__extension__"), Bool(false)] }
Exported Clang AST was invalid. Check warnings above for unimplemented features.
--> test.c:4:36
 [-Wclang-ast]
thread 'main' panicked at 'no entry found for key', c2rust-transpile/src/c_ast/iterators.rs:332:69
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected Behavior
C2Rust should not panic. It should either:

  1. translate the C99 complex expression correctly, or
  2. report that complex floating-point expressions or the I macro are unsupported, without crashing during AST traversal.
    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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions