一句话:提出迭代反馈驱动的 LLM 自动 C→Rust 翻译系统,通过多类反馈逐步提升生成代码的内存安全与语义等价。
内存安全漏洞在现有软件中依然普遍,将遗留 C 代码迁移到 Rust 等内存安全语言是重要缓解手段,而基于大语言模型(LLM)的自动翻译已显示出潜力,却仍面临生成代码无法编译、unsafe 语句过多以及语义功能偏离等问题,这源于 LLM 的 token 长度限制与输出不稳定等固有缺陷。本文设计并实现了自动化 C 到 Rust 翻译系统 SmartC2Rust,其核心思想是对 C 代码进行分段并转换为 Rust,同时利用额外反馈对输出进行迭代精化,反馈包括编译错误、分段上下文、语义差异以及内存不安全语句。这些反馈逐步提升所生成 Rust 代码的质量,从而缓解不安全、不一致与语义问题。评估表明,SmartC2Rust 显著减少了 unsafe 语句,并在安全性与语义等价性上优于先前工作。
Memory safety vulnerabilities remain prevalent in today’s software systems and one promising solution to mitigate them is to adopt memory-safe languages such as Rust. Due to legacy code written in memory unsafe C, there is strong motivation to translate legacy C code into Rust. Prior works have already shown promise in using Large Language Models (LLMs) for such translations. However, significant challenges persist for LLM-based translation: the translated code often fails to compile, let alone reduce unsafe statements and maintain the semantic functionalities due to inherent limitations of LLMs such as limited token size and inconsistent outputs. In this paper, we design an automated C-to-Rust translation system, called SmartC2Rust, to segment and convert the C code to Rust with memory safety and semantic equivalence. The key insight is to iteratively refine the output Rust code with additional feedback, e.g., compilation errors, segmentation contexts, semantic discrepancies, and memory unsafe statements. Such feedback will gradually improve the quality of generated Rust code, thus mitigating unsafety, inconsistency, and semantic issues. Our evaluation shows that SmartC2Rust significantly decreases the unsafe statements and outperforms prior works in security and semantic equivalence.
@inproceedings{paperbot11725,
title = {SmartC2Rust: Iterative, Feedback-Driven C-to-Rust Translation via Large Language Models for Safety and Equivalence},
author = {Momoko Shiraishi and Yinzhi Cao and Takahiro Shinagawa},
booktitle = {ICSE},
year = {2026},
doi = {10.1145/3744916.3773259}
}