一句话:提出形式化宏翻译器 MerC 与基准 MacroBench,并证明 MerC 先翻译、LLM 补余的接力法优于单独使用。
现代关键软件大量用 C,但 C 缺乏内存安全,促使研究者自动将 C 翻译为 Rust。真实 C 程序常使用宏,而宏不属于 C 语言本身;现有方法先预处理再翻译,会内联所有宏定义,导致译文与源码结构差异大。为在译文中保留宏,本文提炼宏与 C 共享的语言特性,设计首个形式化规约的宏翻译器 MerC,并提出首个宏翻译基准 MacroBench,其用例来自真实 C 程序随机采样的宏。实验表明,MerC 支持 50% 用例;LLM 比 MerC 多翻译 22%–77%,但有 8%–28% 的翻译错误,而 MerC 只产生正确翻译。关键洞见是先运行 MerC,再用 LLM 处理剩余宏:该接力法平均失败率比 LLM 低 32%,比 MerC 多翻译 51% 用例。
Modern critical software infrastructure is largely written in C. Since C lacks memory safety, researchers are investigating automatic translation of C to safer languages like Rust. But real-world C software consists of more than just C code, often using named code fragments called macros which are not part of the C language proper. State-of-the-art techniques avoid translating macros by preprocessing C code first before translating it. But this approach produces translations that are dissimilar to the original C code, because preprocessing inlines all macro definitions. To preserve macro usage in translated code, we study the language features that macros and C share and distill them into the first formally- specified translator, MerC. To evaluate MerC, we introduce the first macro translation benchmark, MacroBench, with test cases based on macros randomly sampled from real-world C programs. We find that MerC supports 50% of MacroBench’s macro test cases. We also use MacroBench to evaluate how effective large language models (LLMs) are at performing the previously-unstudied task of macro translation. LLMs translate 22% to 77% more of MacroBench than MerC, but with 8% and 28% of these translations being incorrect translations requiring additional validation by developers. In contrast, MerC only produces correct translations. Our key insight is that running MerC first then using LLMs on the remainder reaps greater benefits than using either technique alone. This tag team approach has an average failure rate 32% lower than that of LLMs, while also translating an average of 51% more test cases than MerC.
@inproceedings{paperbot12420,
title = {Translation Tag Team: Formal Rules and LLMs Translate More Macros Together Than Apart},
author = {Brent Pappas and Joseph Zalusky and Zachary Burkett and Paul Gazzillo},
booktitle = {ASE},
year = {2026},
doi = {10.1145/3832783.3837412}
}