Skip to content

transpile panics on GNU label-address expr (&&label) -> TagTypeUnknown at conversion.rs:1024 #1

Description

@awto-au

Summary

Running c2rust transpile against Linux kernel lib/*.c translation units (riscv64 target) crashes reliably:

thread 'main' panicked at c2rust-transpile/src/c_ast/conversion.rs:1024:22:
Type conversion not implemented for TagTypeUnknown expecting 3

Root cause (traced, not yet fixed)

Baseline run against 104 lib/*.c compilation units: 104/104 crash with the panic above. Preceding the crash, ~70/104 units emit:

warning: c2rust: Cannot translate GNU address of label expression

traced to the kernel's _THIS_IP_ macro (include/linux/instruction_pointer.h):

#define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })

This is GCC's "label as value" / computed-goto extension (&&label, address-of-label). It's pulled in pervasively via spinlock macros (raw_spin_lock_bh, __LOCK_BH, raw_spin_unlock_bh) and separately via __sb_writers_acquired/__sb_writers_release (39/104 units) in VFS writer-lock accounting.

Hypothesis: the Clang AST exporter emits an incomplete/placeholder type (TagTypeUnknown) for the &&label expression's type node since it has no real handling for AddrLabelExpr, and the Rust-side transpiler's exhaustive type-conversion match in c_ast/conversion.rs then panics on that placeholder rather than degrading gracefully.

Impact

Every kernel source file that (transitively) uses spinlocks or VFS writer-lock accounting (i.e. nearly the entire lib/ tree) currently cannot be transpiled at all, not even with warnings-and-best-effort output. This is a hard blocker, not a quality/fidelity issue.

Requested fix shape

At minimum: don't panic. Emit a warning and skip/stub the offending declaration (matching the "Missing top-level node" dropped-declaration behavior seen elsewhere), so the rest of a translation unit still produces output.

Ideally: real AddrLabelExpr/computed-goto support, though label values have no direct Rust equivalent, so any full translation needs a real semantic rewrite, not just an AST passthrough.

Environment

  • c2rust 0.22.1 / git rev 19afbea (this fork, freshly forked from upstream master)
  • Built via cargo +nightly install --git ... (nightly-pinned per upstream's own build requirements)
  • Reproduced against lib/parser.c, lib/bcd.c, and 102 other kernel lib/*.c files

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