用大模型生成代码,自动发现编译器遗漏的优化漏洞
Finding Missed Code Size Optimizations in Compilers using LLMs
- 用现成大模型生成随机代码,结合差分测试找异常行为
- 在多个编译器中发现24个已确认的代码尺寸优化缺陷
- 代码少于150行,可轻松扩展到Rust、Swift等语言
编译器复杂度高,已有大量测试技术用于验证其正确性,如随机程序生成和差分测试,已发现数千个缺陷。但多数工作聚焦于正确性,较少关注性能优化。本文将差分测试应用于发现编译器遗漏的代码尺寸优化机会。我们提出一种新方法,结合大语言模型(LLMs)与一系列差分测试策略,用于检测C/C++编译器中的缺失优化。该方法优势在于简单:用现成大模型生成随机代码,通过启发式规则和分析识别异常编译行为,实现仅需不足150行代码。这一简洁性使其易于扩展——只需更换目标编译器和初始提示词,即可迁移到Rust和Swift,均发现相关缺陷。截至目前,已在生产编译器中报告24个已确认的漏洞,结论表明大模型辅助测试是检测真实世界编译器优化错误的有前景方向。
原文摘要 · Abstract (English)
Compilers are complex, and significant effort has been expended on testing them. Techniques such as random program generation and differential testing have proved highly effective and have uncovered thousands of bugs in production compilers. The majority of effort has been expended on validating that a compiler produces correct code for a given input, while less attention has been paid to ensuring that the compiler produces performant code. In this work we adapt differential testing to the task of identifying missed optimization opportunities in compilers. We develop a novel testing approach which combines large language models (LLMs) with a series of differential testing strategies and use them to find missing code size optimizations in C / C++ compilers. The advantage of our approach is its simplicity. We offload the complex task of generating random code to an off-the-shelf LLM, and use heuristics and analyses to identify anomalous compiler behavior. Our approach requires fewer than 150 lines of code to implement. This simplicity makes it extensible. By simply changing the target compiler and initial LLM prompt we port the approach from C / C++ to Rust and Swift, finding bugs in both. To date we have reported 24 confirmed bugs in production compilers, and conclude that LLM-assisted testing is a promising avenue for detecting optimization bugs in real world compilers.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。