一句话:DEAR 结合频谱定位、深度学习与数据流分析定位缺陷,并用两级树状 LSTM 一次性修复跨代码块的多语句缺陷。
现有基于深度学习的自动程序修复(APR)模型大多只能处理单点、局部修改,难以修复需要在一个或多个代码块中对一条或多条连续语句同时做依赖变更的通用软件缺陷。为应对该问题,本文提出 DEAR。其一是面向多代码块、多语句修复的新型缺陷定位技术:先用频谱定位(SBFL)模型给出可疑语句,再结合深度学习与数据流分析判定需一次性修复的缺陷代码块,并将块内某条可疑语句扩展为包含其周围可疑语句的修复上下文。其二是两级、基于树的 LSTM 模型,通过循环训练与分治策略,在由周围子树构成的合适修复上下文中学习多条语句的代码变换。作者在 Defects4J、BigFix 与 CPatMiner 三个数据集上评估:在 Defects4J 上仅用 top-1 补丁即可比基线多修复 42%–683% 的缺陷,在 BigFix 上比现有 DL-based APR 模型多修复 31–145 个缺陷;在 CPatMiner 上,其修复的 667 个缺陷中 169 个(25.3%)属于多代码块/多语句缺陷,且相对最先进的 DL-based APR 模型分别多修复 71 与 164 个缺陷,其中包括 52 与 61 个多代码块/多语句缺陷。
The existing deep learning (DL)-based automated program repair (APR) models are limited in fixing general software defects. We present DEAR, a DL-based approach that supports fixing for the general bugs that require dependent changes at once to one or mul-tiple consecutive statements in one or multiple hunks of code. We first design a novel fault localization (FL) technique for multi-hunk, multi-statement fixes that combines traditional spectrum-based (SB) FL with deep learning and data-flow analysis. It takes the buggy statements returned by the SBFL model, detects the buggy hunks to be fixed at once, and expands a buggy statement $s$ in a hunk to include other suspicious statements around s. We design a two-tier, tree-based LSTM model that incorporates cycle training and uses a divide-and-conquer strategy to learn proper code transformations for fixing multiple statements in the suitable fixing context consisting of surrounding subtrees. We conducted several experiments to evaluate DEAR on three datasets: Defects4J (395 bugs), BigFix (+26k bugs), and CPatMiner (+44k bugs). On Defects4J dataset, DEAR outperforms the baselines from 42%-683% in terms of the number of auto-fixed bugs with only the top-1 patches. On BigFix dataset, it fixes 31–145 more bugs than existing DL-based APR models with the top-1 patches. On CPatMiner dataset, among 667 fixed bugs, there are 169 (25.3%) multi-hunk/multi-statement bugs. DEAR fixes 71 and 164 more bugs, including 52 and 61 more multi-hunk/multi-statement bugs, than the state-of-the-art, DL-based APR models.