paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Cpp2Rust: Automatic Translation of C++ to Safe Rust

Cpp2Rust:将 C++ 自动翻译为安全 Rust
PLDI 10(PLDI)2026匹配度 3/10 · 该论文研究C++到Rust的自动翻译,属于编程语言与编译器领域,但完全不涉及LLM/Agent、静态分析(仅有运行时检查)、浮点程序分析或贝叶斯程序分析,与用户画像的核心交叉方向(PL与AI结合)无直接关联。引用 1 inbox
Lucian Popescu, Francisco Gouveia, Henrique Preto, João Silveira, Dmytro Hrybenko, José Fragoso Santos, Nuno P. Lopes
crossref: 2026-09-10

AI 速览

一句话:首个将 C++ 程序自动翻译为功能等价且内存安全 Rust 代码的系统,以运行时所有权检查换取安全,并用源到源优化降低开销。

C/C++ 中的内存安全缺陷导致了广泛部署软件约 70% 的安全漏洞,而手工将遗留 C++ 代码迁移到 Rust 成本高昂且易出错。本文提出 Cpp2Rust,首个能把 C++ 程序自动翻译为功能等价且内存安全 Rust 代码的系统。针对 C++ 无限制别名与 Rust 所有权模型之间的根本不匹配,Cpp2Rust 选择以部分性能换取安全性:插入运行时强制执行的所有权与可变性检查,在保持原语义的同时保证内存安全。为缓解动态检查带来的开销,作者设计了一套面向 Rust 的源到源优化,消除冗余的所有权操作以恢复性能。在 WOFF2 字体压缩库和 Brunsli JPEG 无损压缩库两个真实 C++ 程序(共 1.3 万行代码)上评估:WOFF2 实现完全内存安全且压缩性能仅下降 2%,而 Brunsli 因大量指针运算慢 6 倍。结果表明,自动、保持语义的 C++ 到安全 Rust 翻译对部分安全关键应用是可行的。

问题
C/C++ 的内存安全问题导致大量安全漏洞,而将遗留 C++ 代码手工迁移到内存安全语言 Rust 的成本极高且容易出错。
方法
Cpp2Rust 通过插入运行时强制执行的所有权与可变性检查,弥合 C++ 无限制别名与 Rust 所有权模型之间的不匹配,并配套一套 Rust 源到源优化以消除冗余所有权操作、降低动态检查开销。
评估
在两个真实 C++ 程序(共约 1.3 万行代码)WOFF2 与 Brunsli 上评估:WOFF2 达到完全内存安全且性能损失仅 2%,Brunsli 因大量指针运算性能下降 6 倍。
原文摘要(Abstract)

About 70% of security vulnerabilities in widely deployed software originate from memory-safety bugs in languages such as C and C++. Despite decades of investment in mitigations, from static analysis and sanitizers to hardware isolation, attackers continue to exploit unsafe memory operations. A promising long-term solution is to migrate existing C++ codebases to memory-safe languages such as Rust, but doing so manually is prohibitively expensive and error-prone. In this paper, we present Cpp2Rust, the first system capable of translating C++ programs into functionally equivalent and memory-safe Rust code automatically. By trading some performance for security, Cpp2Rust addresses the fundamental mismatch between C++’s unrestricted aliasing and Rust’s ownership model by inserting runtime-enforced ownership and mutability checks, ensuring safety while preserving semantics. To mitigate the performance overhead of dynamic checks, we developed a suite of source-to-source optimizations for Rust code that eliminate redundant ownership operations and recover much of the lost performance. We evaluate Cpp2Rust on two real-world C++ programs, totaling 13k lines of code: WOFF2, a font compression library, and Brunsli, a JPEG lossless compression library. Cpp2Rust achieves full memory safety with only a 2% performance penalty on WOFF2 compression, while being 6× slower on Brunsli due to heavy usage of pointer arithmetic. These results demonstrate that automated, semantics-preserving translation from C++ to safe Rust is practical for some safety-critical applications, offering a viable path toward eliminating memory-safety vulnerabilities in legacy systems.

链接与引用

DOI 原文 · PDF(开放获取) · DBLP

BibTeX
@article{PopescuGPSHSL26,
  title = {Cpp2Rust: Automatic Translation of C++ to Safe Rust},
  author = {Lucian Popescu and Francisco Gouveia and Henrique Preto and João Silveira and Dmytro Hrybenko and José Fragoso Santos and Nuno P. Lopes},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {10},
  number = {PLDI},
  year = {2026},
  doi = {10.1145/3808266}
}