paperbot · PL 论文追踪

全部论文 待读 收藏

P2 GenC2Rust: Towards Generating Generic Rust Code from C

GenC2Rust:从 C 生成泛型 Rust 代码
ICSE 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE)2025匹配度 3/10 · 该论文使用静态分析/类型约束推断将 C 的 void 指针翻译为 Rust 泛型,属于程序分析与代码生成工作;但用户的核心方向是 PL 与 LLM/Agent 的交叉(用静态分析分析 Agentic 程序、用 LLM 改进静态分析)以及浮点/贝叶斯程序分析,本文完全不涉及 LLM 或这些特定分析对象,属于相邻但非核心的工作。引用 6 inbox
Xiafa Wu, Brian Demsky
crossref: 2026-09-12

AI 速览

一句话:提出 GenC2Rust,通过静态分析 C 中 void 指针的类型约束,将其翻译为使用泛型的 Rust 代码。

Rust 兼具安全保证与高性能,但大量遗留 C 代码难以直接享受这些优势,而人工重写成本高昂。现有 C 到 Rust 翻译工具因 C 抽象与惯用 Rust 抽象不匹配,常生成非惯用代码,尤其无法把 C 中多态使用的 void 指针映射为 Rust 泛型指针。本文提出翻译工具 GenC2Rust,它静态分析 C 程序中 void 指针的使用,计算类型约束,并将参数多态的 void 指针重新类型化为泛型指针,从而把非泛型 C 代码翻译为泛型 Rust 代码。作者在 42 个不同规模和领域的 C 程序上评估,验证了可扩展性与正确性,共将 4,572 个 void 指针转换为泛型,并讨论了翻译过程中的限制因素。

问题
遗留 C 代码难以低成本迁移到 Rust,而现有 C-to-Rust 工具难以生成利用 Rust 泛型等特性的惯用代码,尤其无法处理多态 void 指针。
方法
提出 GenC2Rust,静态分析 C 中 void 指针的用法并计算类型约束,将参数多态的 void 指针重新类型化为 Rust 泛型指针,从而生成泛型 Rust 代码。
评估
在 42 个规模与领域各异的 C 程序上进行评估,展示可扩展性与正确性;共将 4,572 个 void 指针翻译为泛型,并讨论翻译限制。
原文摘要(Abstract)

Rust provides an exciting combination of strong safety guarantees and high performance. Many new systems are being implemented in Rust. Nevertheless, there is a large body of existing C code that could greatly benefit from Rust's safety guarantees. Unfortunately, the manual effort required to rewrite C code into Rust is often prohibitively expensive. Researchers have explored tools to assist developers in trans-lating legacy C code into Rust code. However, the mismatch between C abstractions and idiomatic Rust abstractions makes it challenging to automatically utilize Rust's language features, resulting in non-idiomatic Rust code that requires extensive manual effort to further refactor. For example, existing tools often fail to map polymorphic uses of void pointers in C to Rust's generic pointers. In this paper, we present a translation tool, GenC2Rust, that translates non-generic C code into generic Rust code. GenC2Rust statically analyzes the use of void pointers in the C program to compute the typing constraints and then retypes the parametric polymorphic void pointers into generic pointers. We conducted an evaluation of GenC2Rust across 42 C programs that vary in size and span multiple domains to demonstrate its scalability as well as correctness. We discovered GenC2Rust has translated 4,572 void pointers to use generics. We also discuss the limiting factors encountered in the translation process.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot8729,
  title = {GenC2Rust: Towards Generating Generic Rust Code from C},
  author = {Xiafa Wu and Brian Demsky},
  booktitle = {ICSE},
  year = {2025},
  doi = {10.1109/icse55347.2025.00127}
}