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.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

From C to Rust: Evaluating LLM Capabilities in Transpilation Through Compilation Errors

  • Andrea Valenzuela,
  • Marta Gonzalez-Mallo,
  • Cristian Gutierrez,
  • Dario Garcia-Gasulla,
  • Gokcen Kestor,
  • Sara Royuela

摘要

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.