增進編譯器測試的擴展實際程式碼注入技術
Towards More Effective Compiler Testing with Expanded Real-Code Injection Techniques
摘要
確保編譯器的正確性對產生可靠的程式至關重要。雖然形式化驗證可以證明個別優化的正確性,但現代優化流程日益複雜,並且構建形式化驗證需要大量的人工投入,使得在實踐中很難實現完全驗證的編譯器。因此,編譯器開發人員通常依賴隨機測試(random testing)來檢測錯誤編譯並提高優化實現的穩定性。隨機差異測試通過預定義的語法自動建構大量的測試程式,並已被證實在編譯器測試上有顯著效用。然而,隨著程式生成工具被反覆運行,其產生的輸入空間會逐漸飽和,降低了發現錯誤編譯的可能性。為了在不從頭開發新生成工具的情況下減輕這一限制,近期的研究提出引入預定義語法以外的語法結構,來增強生成的程式。例如, Creal 將實際專案的程式碼(real-world code)插入生成的程式中來增加測試的多樣性,與作為基準的 Csmith 相比,在 GCC 與 LLVM 上分別達到了 6.3% 及 2.5% 的程式碼行覆蓋率(line coverage)提升。然而, Creal 將插入的函式簽章(function signature)限制在基於整數的型別(整數和整數指針),這限制了其使用的程式碼結構,並因此限制其發現錯誤的能力。在本論文中,我們提出了 XCreal ,一種增強支持任意資料型別的基於變異的測試技術。 XCreal 引入了一個內部類型系統來應對複雜的資料型別,並將實際專案的程式碼安全地集成到生成的程式中,從而增加測試的多樣性。實驗使用 Csmith 作為底層的生成工具並以 AnghaBench 作為函式語料庫,結果表明,與作為基準的 Csmith 相比, XCreal 在 GCC 上提升了 8.3% 的程式碼行覆蓋率,並在 LLVM 上提升了 2.9% 的程式碼行覆蓋率,顯示其能夠進一步使生成的程式多樣化,並提高編譯器測試的有效性。
Ensuring the correctness of a compiler is crucial for generating reliable executables. Although formal verification techniques can prove the correctness of individual optimizations, the growing complexity of modern optimization pipelines and the substantial manual effort required to build formal models make fully verified compilers difficult to achieve in practice. Consequently, compiler developers often rely on random testing to detect miscompilations and improve the robustness of their optimization implementations. Randomized differential testing has shown strong effectiveness in compiler testing by automatically constructing large numbers of test programs from predefined grammars. However, as the generator is repeatedly exercised, the resulting input space progressively saturates, reducing the likelihood of discovering new miscompilations. To alleviate this limitation without developing a new generator from scratch, recent work proposes augmenting generated programs with syntactic structures beyond the predefined grammars. For example, Creal inserts real-world functions into generated programs to increase test diversity, achieving 6.3% and 2.5% line coverage improvements on GCC and LLVM, respectively, over baseline Csmith. Nevertheless, Creal restricts the inserted functions to integer-based signatures (i.e., integers and integer pointers), which limits the range of real-world code constructs and consequently the strength of bug-finding capability. In this thesis, we propose XCreal, an enhanced mutation-based testing technique that supports arbitrary data types. XCreal introduces an internal type system to reason about complex types and safely integrate real-world code into generated programs, thereby increasing test diversity. Using Csmith as the underlying generator and AnghaBench as the function corpus, our evaluation shows that XCreal increased line coverage by 8.3% on GCC and 2.9% on LLVM compared to baseline Csmith, demonstrating its ability to further diversify generated programs and improve the effectiveness of compiler testing.