一句话:提出 Creal,以保语义方式将真实项目函数注入种子程序,借真实代码提升随机生成器的表达能力来测试优化编译器。
优化编译器的错误(miscompilation)隐蔽且难以发现,而现有随机程序生成器等工程化手段难以覆盖真实语言中丰富的语法与语义特性。本文提出一种新思路:从真实世界应用中按函数粒度抽取代码片段,将其函数调用注入种子程序,并利用动态执行信息维护语义、在注入函数与种子程序之间建立复杂数据依赖,从而以保持语义的方式融合真实代码,增强现有生成器的表达能力。作者实现工具 Creal 用于测试 C 编译器。在为期九个月的测试中,向 GCC 和 LLVM 报告了 132 个 bug,其中 121 个被确认为未知 bug,101 个已被修复;这些 bug 多为误编译,不少被认定为长期潜伏且关键的问题,证明真实世界代码对压测编译器具有显著优势。
We introduce a novel approach for testing optimizing compilers with code from real-world applications The main idea is to construct well-formed programs by fusing multiple code snippets from various realworld projects. The key insight is backed by the fact that the large volume of real-world code exercises rich syntactical and semantic language features, which current engineering-intensive approaches like random program generators are hard to fully support. To construct well-formed programs from real-world code our approach works by (1) extracting real-world code at the granularity of function, (2) injecting function calls into seed programs, and (3) leveraging dynamic execution information to maintain the semantics and build complex data dependencies between injected functions and the seed program. With this idea, our approach complements the existing generators by boosting their expressiveness via fusing real-world code in a semantics-preserving way. We implement our idea in a tool, Creal, to test C compilers. In a nine-month testing period, we have reported 132 bugs to GCC and LLVM, two of the most popular and well-tested C compilers. At the time of writing, 121 of them have been confirmed as unknown bugs, and 101 of them have been fixed. Most of these bugs were miscompilations, and many were recognized as long-latent and critical. Our evaluation results evidently demonstrate the significant advantage of using real-world code to stress-test compilers. We believe this idea will benefit the general compiler testing direction and will be directly applicable to other compilers.
@article{LiTS24,
title = {Boosting Compiler Testing by Injecting Real-World Code},
author = {Shaohua Li and Theodoros Theodoridis and Zhendong Su},
journal = {Proceedings of the ACM on Programming Languages},
volume = {8},
number = {PLDI},
year = {2024},
doi = {10.1145/3656386}
}