一句话:提出程序重条件化,使含未定义行为且无检测工具的语言也能做程序生成、差分测试与用例缩减,在 GLSL/WGSL 编译器中发现 57 个缺陷。
程序生成、差分测试与测试用例缩减是发现并简化编译器误编译缺陷的有力手段,但当目标语言存在未定义行为(UB)且没有自动 UB 检测工具时,会误把触发 UB 的程序当作误编译证据,也难以安全地缩减用例。本文提出程序重条件化(program reconditioning):在生成与缩减过程中主动约束并调理程序,使其避开 UB 与浮点舍入误差等非确定性来源。作者据此实现了面向 OpenGL Shading Language 的 GLSLsmith 与面向 WebGPU Shading Language 的 WGSLsmith,首次让 GLSL/WGSL 编译器能够应用差分测试与用例缩减。大规模测试活动中分别在 GLSL 与 WGSL 编译器发现 24 和 33 个缺陷;对照实验表明关闭重条件化后,大量看似触发误编译的测试程序实际只是存在 UB。
We introduce program reconditioning, a method for allowing program generation and differential testing to be used to find miscompilation bugs, and test-case reduction to be used to simplify bug-triggering programs, even when (a) the programming language of interest features undefined behaviour (UB) and (b) no tools exist to detect and avoid this UB. We present two program generation tools based on our reconditioning idea: GLSLsmith for the OpenGL Shading Language (GLSL), a widely-used language for graphics programming, and WGSLsmith for the WebGPU Shading Language (WGSL), a new language for web-based graphics rendering. GLSL features many UBs, but unlike for languages such as C and C++ no tools exist to detect them automatically. While the WGSL language specification features very limited UB, early WGSL implementations do exhibit UB, for reasons of initial implementation simplicity, making it challenging to test them to quickly detect and eliminate unrelated miscompilation bugs. Thanks to reconditioning, we show that GLSLsmith and WGSLsmith allow differential testing and test-case reduction to be applied to compilers for GLSL and WGSL for the first time, despite the unavailability of UB detection techniques for these languages. Through a large testing campaign, we have found 24 and 33 bugs in GLSL and WGSL compilers, respectively. We present experiments showing that when reconditioning is disabled, compiler testing leads to a high rate of test programs that appear to trigger miscompilation bugs, but actually just feature UB. We also present a novel approach to managing floating-point roundoff error using reconditioning, implemented for both GLSL and WGSL.
@article{paperbot1990,
title = {Program Reconditioning: Avoiding Undefined Behaviour When Finding and Reducing Compiler Bugs},
author = {Bastien Lecoeur and Hasan Mohsin and Alastair F. Donaldson},
journal = {Proceedings of the ACM on Programming Languages},
volume = {7},
number = {PLDI},
year = {2023},
doi = {10.1145/3591294}
}