Connecting Program Synthesis and Reachability: Automatic Program Repair Using Test-Input Generation

ThanhVu Nguyen, Westley Weimer, Deepak Kapur, Stephanie ForrestTACAS 2017

Abstract

We prove that certain formulations of program synthesis and reachability are equivalent. Specifically, our constructive proof shows the reductions between the template-based synthesis problem, which generates a program in a pre-specified form, and the reachability problem, which decides the reachability of a program location. This establishes a link between the two research fields and allows for the transfer of techniques and results between them. To demonstrate the equivalence, we develop a program repair prototype using reachability tools. We transform a buggy program and its required specification into a specific program containing a location reachable only when the original program can be repaired, and then apply an off-the-shelf test-input generation tool on the transformed program to find test values to reach the desired location. Those test values correspond to repairs for the original program. Preliminary results suggest that our approach compares favorably to other repair methods.

Introduction

Software maintenance is a significant burden in modern development, with manual bug fixing being both time-consuming and error-prone. Automatic Program Repair (APR) aims to mitigate this by automatically generating patches for buggy code. Fundamentally, APR is a program synthesis task: given a buggy program and a specification—typically a suite of test cases—the goal is to synthesize a code modification that satisfies the specification.

While program synthesis and program reachability (determining if a specific state is reachable in a program) have historically been treated as separate domains, this work establishes a formal, constructive link between them. We demonstrate that template-based synthesis can be reduced to a reachability problem, allowing the use of mature verification tools for automated repair.

Methodology: The GadgetS2R Reduction

The primary contribution of this research is the GadgetS2R (Synthesis to Reachability) reduction. This transformation allows a synthesis problem to be solved using off-the-shelf test-input generation tools like KLEE.

Template-Based Synthesis

The approach utilizes templates to define the search space for potential repairs. Instead of generating arbitrary code, a buggy statement is replaced with a template containing "holes" or symbolic parameters ($c_i$). For example, a buggy assignment might be replaced by a linear combination of existing variables.

Encoding Specification as Reachability

The reduction transforms the buggy program into a new "reachability instance." The template parameters are treated as global input variables. The entire test suite is then encoded into a single conjunctive expression $e$, which evaluates to true only if the program passes every test case for a given set of parameter values. A target location $L$ is placed within an if(e) block.

Transformation of a synthesis problem into a reachability instance.

By targeting the reachability of $L$, we leverage symbolic execution engines to find the specific values for $c_i$ that satisfy the entire specification. These values are then substituted back into the template to produce the final patch.

Evaluation

We implemented this approach in a prototype tool named CETI (Correcting Errors using Test Inputs) and evaluated it using the Tcas benchmark from the Software Infrastructure Repository (SIR). Tcas is a 180-line C program used for aircraft traffic collision avoidance, accompanied by a suite of 1,608 test cases.

Example of a buggy program and its associated test suite used for evaluation.

We tested CETI against 41 seeded defects, ranging from incorrect operators to missing logic. CETI successfully repaired 26 out of 41 (63%) defects. Notably, the tool was highly efficient, requiring an average of only 22 seconds to find a valid repair. In comparative tests, CETI outperformed specialized repair frameworks such as GenProg and Debroy/Wong on the same benchmark.

Conclusion

The established equivalence between program synthesis and reachability provides a powerful framework for automated program repair. By reducing synthesis to a reachability problem, we can exploit the efficiency and robustness of existing verification tools. This connection not only simplifies the development of repair tools but also enables the cross-pollination of heuristics and optimization techniques between the two fields. Future research will focus on expanding template expressivity and scaling the approach to larger, more complex software systems.

Summary updated

BibTeX
@inproceedings{nguyen2017connecting,
  author = {ThanhVu Nguyen and Westley Weimer and Deepak Kapur and Stephanie Forrest},
  title = {{Connecting Program Synthesis and Reachability: Automatic Program Repair Using Test-Input Generation}},
  booktitle = {TACAS},
  year = {2017},
  url = {https://openreview.net/forum?id=Ti5zvQvK7E},
}
Figure