NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

SpecTest: Specification-Based Compiler Testing

Richard Schumi, Jun Sun

Abstract

SpecTest is a novel framework designed to uncover deep logic errors in compilers by utilizing executable formal semantics as a "strong oracle." By introducing a "semantic coverage" metric, SpecTest systematically identifies and mutates code to exercise rare language features that traditional fuzzing and differential testing often miss. Evaluated on Java and Solidity, the framework successfully identified 31 issues, including previously unknown compiler bugs and flaws in formal specifications.

Introduction

Compilers are the bedrock of the software ecosystem, yet their extreme complexity makes them notoriously buggy. Testing them is difficult because of the oracle problem: determining if a compiler's output is correct without already possessing a perfect version of that compiler.

Existing approaches have significant gaps. Fuzzing often only detects "shallow" bugs like crashes. Differential testing requires multiple mature compilers for comparison, which is often unavailable for new or domain-specific languages. Metamorphic testing (like EMI) relies on algebraic properties that may miss basic logic errors in "live" code. Furthermore, standard code coverage (line/branch) fails to indicate whether the logic of language features has been tested—only that the compiler's source code was touched.

Methodology

SpecTest bridges the gap between formal verification and automated testing by using a feedback loop centered on executable semantics.

The SpecTest workflow, illustrating the feedback loop between semantic coverage and program mutation.

The SpecTest Workflow

  1. Executable Semantics as an Oracle: The framework uses the K framework to run programs according to formal mathematical rules (Structural Operational Semantics). This acts as the "ground truth" for expected program behavior.
  2. Semantic Coverage: This key innovation tracks which formal rules of the language are triggered during execution, rather than just compiler source lines.
  3. Targeted Mutation: If certain language features (e.g., labeled blocks or hexadecimal literals) are rarely exercised, a program mutator injects those features into seed programs.
  4. The Comparison: Mutated programs are run through both the compiler-under-test and the executable specification. If the final states (such as variable values) differ, a bug is flagged.

Evaluation and Results

The authors evaluated SpecTest on two distinct ecosystems: Java (using 756 seed programs and the 1,385-rule K-Java specification) and Solidity (using 37 seed programs and the 304-rule KSolidity specification).

Key Findings

  • Bugs Discovered: SpecTest found 31 total issues. This included 6 bugs in the Solidity compiler and 4 in the Java compiler (specifically regarding inconsistent overflow handling during type casting).
  • Coverage Improvements: The framework significantly improved semantic coverage. For Java, it increased character coverage in the expressions.k rule file by over 14%.
  • Deep Logic Errors: In Solidity, it uncovered a bug where the increment operator (++) was applied in the wrong order during complex assignments—a bug that had persisted across multiple versions.
  • Specification Hardening: It identified 21 issues in the formal K-specifications themselves, helping developers refine the mathematical definitions of Java and Solidity.

Discussion

SpecTest offers several advantages over traditional methods. As a black-box semantic testing tool, it does not require the compiler's source code, making it suitable for proprietary or highly optimized systems. Its "strong oracle" allows it to find "silent" bugs—cases where the compiler produces an executable that runs without crashing but calculates the wrong result.

Furthermore, the process is bidirectional; disagreements between the compiler and the specification can reveal flaws in the formal definitions themselves, helping to "harden" the language's mathematical foundation. By focusing on "rare feature hunting," SpecTest shines a light on the "dark corners" of a language where bugs often hide.

Limitations and Future Work

Despite its success, SpecTest faces challenges. The bootstrap cost is high, as writing a high-quality executable specification can take 6–12 months. Performance is also an issue; running programs through a formal semantics engine is significantly slower than native execution, with some Solidity tests taking up to 24 minutes.

Future work may address context sensitivity—moving beyond binary rule coverage to examine the surrounding code context—and reducing the manual effort currently required to engineer language-specific mutators.

Summary updated

BibTeX
@inproceedings{schumi2021spectest,
  author = {Richard Schumi and Jun Sun},
  title = {{SpecTest: Specification-Based Compiler Testing}},
  booktitle = {FASE},
  year = {2021},
  doi = {10.1007/978-3-030-71500-7\_14},
}
Figure