🤖 AI Summary
Detecting semantic-breaking modifications in non-functional changes—such as code refactoring and performance optimization—remains challenging due to their subtle behavioral impact. To address this, we propose a pairwise learning-guided execution framework that jointly models pre- and post-change behavioral discrepancies via dynamic execution monitoring, neural program embedding, pairwise contrastive learning, and mutation-driven input generation. Unlike conventional regression testing (which achieves only 7.6% recall), our approach is the first to integrate pairwise contrastive learning into the guided execution paradigm, significantly enhancing robustness and path coverage. Evaluated on 224 real-world, manually labeled code changes and three sets of automated transformations, our method achieves 77.1% precision and 69.5% recall—substantially outperforming baseline approaches—and successfully identifies unintended behavioral regressions introduced by mainstream automated refactoring tools.
📝 Abstract
Code changes are an integral part of the software development process. Many code changes are meant to improve the code without changing its functional behavior, e.g., refactorings and performance improvements. Unfortunately, validating whether a code change preserves the behavior is non-trivial, particularly when the code change is performed deep inside a complex project. This paper presents ChangeGuard, an approach that uses learning-guided execution to compare the runtime behavior of a modified function. The approach is enabled by the novel concept of pairwise learning-guided execution and by a set of techniques that improve the robustness and coverage of the state-of-the-art learning-guided execution technique. Our evaluation applies ChangeGuard to a dataset of 224 manually annotated code changes from popular Python open-source projects and to three datasets of code changes obtained by applying automated code transformations. Our results show that the approach identifies semantics-changing code changes with a precision of 77.1% and a recall of 69.5%, and that it detects unexpected behavioral changes introduced by automatic code refactoring tools. In contrast, the existing regression tests of the analyzed projects miss the vast majority of semantics-changing code changes, with a recall of only 7.6%. We envision our approach being useful for detecting unintended behavioral changes early in the development process and for improving the quality of automated code transformations.