Rust-twins: Automatic Rust Compiler Testing through Program Mutation and Dual Macros Generation
Wenzhang Yang, Cuifeng Gao, Xiaoyuan Liu, Yuekang Li, Yinxing Xue
Abstract
Rust is a relatively new programming language known for its memory safety and numerous advanced features. It has been widely used in system software in recent years. Thus, ensuring the reliability and robustness of the only implementation of the Rust compiler, rustc, is critical. However, compiler testing, as one of the most effective techniques to detect bugs, faces difficulties in generating valid Rust programs with sufficient diversity due to its stringent memory safety mechanisms. Furthermore, existing research primarily focuses on testing rustc to trigger crash errors, neglecting incorrect compilation results -miscompilation. Detecting miscompilation remains a challenge in the absence of multiple implementations of the Rust compiler to serve as a test oracle. This paper tackles these challenges by introducing rust-twins, a novel and effective approach to performing automated differential testing for rustc to detect both crashes and miscompilations. We devise four Rust-specific mutators and adapt fourteen general mutators for Rust, each intends to produce a syntax and semantic valid Rust program to trigger rustc crashes. Additionally, we develop a macroize approach to rewrite a regular Rust program into dual macros with equivalent behaviors but in different implementations. Furthermore, we design an assessment component to check the equivalence by comparing the expansion results with a simple macro input. Finally, rust-twins attempts to expand the two macros with numerous complex inputs to detect differences. Due to the macro expansion mechanism, the root causes of differences can arise not only from the macro expansion part but also from any other mis-implemented compiler code. We have evaluated rust-twins on the latest version of rustc. Our experimental results indicate that rust-twins achieves twice * Yinxing Xue is the corresponding author.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 11b517b6-f961-48ed-9e33-b29459c38302Cited by top-tier papers3
- An Empirical Study of Bugs in the rustc CompilerZixi Liu, Yang Feng, Yunbo Ni, Shaohua Li et al.OOPSLA 2025 · 5 citations
- Rust’s Type Checker Implementation Is Unsound: An Empirical Study on Soundness Bugs in rustcYusung Sim, Sukyoung Ryu, Jaemin HongISSTA 2026
- RICE: Harnessing LLMs and Historical Issues to Discover Internal Rust Compiler ErrorsLangyi Lu, Wei You, Bin Liang, Jianjun HuangISSTA 2026
Builds on11
- Fuzzing JavaScript Engines with Aspect-preserving MutationSoyeon Park, Wen Xu, Insu Yun, Daehee Jang et al.S&P 2020 · 126 citations
- GrayC: Greybox Fuzzing of Compilers and Analysers for CKarine Even-Mendoza, Arindam Sharma, Alastair F. Donaldson, Cristian CadarISSTA 2023 · 52 citations
- History-Driven Test Program Synthesis for JVM TestingYingquan Zhao, Zan Wang, Junjie Chen, Mengdi Liu et al.ICSE 2022 · 51 citations
- JIT-Picking: Differential Fuzzing of JavaScript EnginesLukas Bernhard, Tobias Scharnowski, Moritz Schloegel, Tim Blazytko et al.CCS 2022 · 42 citations
- Learning and Programming Challenges of Rust: A Mixed-Methods StudyShuofei Zhu, Ziyi Zhang, Boqin Qin, Aiping Xiong et al.ICSE 2022 · 27 citations
Related papers
- Detecting Bugs in Rust Compiler Fix Suggestions via Constraint-Violation-Guided MutationZixi Liu, Yang Feng, Jialiang Jiang, Baowen XuFSE 2026
- RustSan: Retrofitting AddressSanitizer for Efficient Sanitization of RustKyuwon Cho, Jongyoon Kim, Kha Dinh Duy, Hajeong Lim et al.USENIX Security 2024 · 7 citations
- Rustlantis: Randomized Differential Testing of the Rust CompilerQian Wang, Ralf JungOOPSLA 2024 · 14 citations
- Validating Rust Compilers with Trait-Type Constraint GraphXin Lai, Ming Wen, Xiaofei Liao, Hai JinSOSP 2026
- CULPA: Universal Detection of Memory-Safety Bugs in Unsafe Rust Through the Lens of Safety RequirementsHung-Mao Chen, Bo Lu, Xu He, Xiaokuan Zhang et al.USENIX Security 2026
