From C to Rust: Evaluating LLM Capabilities in Transpilation Through Compilation Errors
摘要
Migrating C code bases to Rust is increasingly attractive due to Rust’s strong memory safety guarantees. However, code migration remains costly and time-consuming, motivating the use of Large Language Models (LLMs) to expedite the process while addressing limitations in traditional rule-based approaches. In this work, we evaluate the zero-shot performance of state-of-the-art open-source models on C-to-Safe-Rust transpilation, finding that general models achieve up to 50% in pass@1, with mid-sized coder models also performing competitively. Furthermore, we propose a hybrid approach where the C2Rust tool generates an initial unsafe Rust transpilation, which the LLM then refines into safe Rust. Results on this Unsafe-to-Safe-Rust transpilation task indicate general improvements across models, suggesting the usage of C2Rust as a preprocessing tool. Finally, we analyze common compilation errors, revealing LLM limitations in handling Rust-specific syntactic features such as null checks, C APIs, and iterators. Overall, this study characterizes the performance of LLMs for C-to-Rust transpilation and identifies their current limitations.