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

Compiler Testing Approach based on Generalized Equivalent Substitution

Xinwei Wu, Peng Zhang, Qiang Huang, Qirong Ma, Guanglei Shao, Pengcheng Li2017

Abstract

The correctness of compilers is fundamental to software reliability. This paper proposes a testing approach based on generalized equivalent substitution, which generates numerous equivalent program variants from a single seed. By comparing the outputs of these semantically identical assemblies, the approach effectively bypasses the traditional "test oracle" problem. Experimental results using an SNL compiler demonstrate a 93.75% bug detection rate, confirming the effectiveness of the method.

Introduction: The Oracle Problem

Compilers are among the most complex software systems, making them notoriously difficult to verify. A significant hurdle in compiler testing is the Oracle Problem: determining the correct expected output for a given source program is labor-intensive and often requires a pre-existing, bug-free reference. While techniques like Randomized Differential Testing (RDT) compare multiple compilers, they are limited by the availability of high-precision alternatives. This research explores a self-verifying framework that ensures different versions of the same logic produce identical results.

Methodology: Generalized Equivalent Substitution

The proposed framework leverages Metamorphic Testing principles. Instead of verifying Compiler(Program) == Expected_Output, the system checks for consistency across variants: Output(Variant_1) == Output(Variant_2). If two semantically equivalent programs yield different outputs after compilation, a bug is present in the compiler.

The generalized equivalent substitution testing framework, showing the flow from seed program P to final report.

The core of the approach lies in three mutation operators used to transform source code while preserving its functional logic:

1. Augmentation Operator (AO)

The AO adds "irrelevant" statements to the code. It utilizes identity equations to bloat the program without altering its core logic. For instance, a variable x might be replaced with x * 2 / 2, or a new assignment y = x + x might be added if y is never subsequently used.

Iterative generation of equivalent expressions using identity equations to create complex code variants.

By iteratively nesting these simple equations, the framework generates complex "noise" code that is difficult for a compiler's optimization layers to simplify or ignore.

2. Elimination Operator (EO)

The EO identifies and removes non-execution paths. By analyzing which code segments are never reached for a specific test input, the framework can delete those segments. The resulting program should remain functionally identical for that specific input, providing a "generalized" form of equivalence.

3. Modification Operator (MO)

The MO alters existing code structures without changing semantics. This includes replacing expressions with equivalent forms, reordering non-dependent statements, and performing Loop Invariant Hoisting—moving calculations that remain constant within a loop to a position outside of it.

Experimental Evaluation

The researchers evaluated the framework using a Small Network Language (SNL) compiler. Seven original SNL programs served as seeds, from which the mutation operators generated 171 sets of equivalent assemblies. To measure detection capabilities, 32 "mutant" versions of the SNL compiler were created, each containing an intentional bug (e.g., operator swapping in the compiler source).

The framework successfully detected 30 out of 32 compiler mutants, achieving a 93.75% success rate. This demonstrates that a small set of seed programs can be transformed into a robust testing suite capable of identifying deep-seated compiler flaws.

Conclusion and Future Work

Generalized equivalent substitution offers a powerful, automated way to test compilers without a manual oracle. However, challenges remain. Floating-point operations often fail to maintain exact equivalence due to precision and rounding differences, limiting the current study to integer arithmetic. Furthermore, the random nature of mutations means that code coverage is not guaranteed. Future research will focus on developing more comprehensive seed programs and refining mutation strategies to improve path coverage and handle complex data types.

Summary updated

BibTeX
@misc{wu2017compiler,
  author = {Xinwei Wu and Peng Zhang and Qiang Huang and Qirong Ma and Guanglei Shao and Pengcheng Li},
  title = {{Compiler Testing Approach based on Generalized Equivalent Substitution}},
  year = {2017},
  doi = {10.2991/mecs-17.2017.91},
}
Figure