[论文解读] Automated Repair of Programs from Large Language Models
本文研究了自动化程序修复(APR)技术是否能够提升大型语言模型(如Codex)生成的代码在编程竞赛场景下的可靠性。研究发现,在故障定位的引导下,APR工具——尤其是Codex的编辑模式——能够有效修复自动生成代码中的许多错误,表明将语言模型与APR结合可显著提升代码质量和鲁棒性。
Large language models such as Codex, have shown the capability to produce code for many programming tasks. However, the success rate of existing models is low, especially for complex programming tasks. One of the reasons is that language models lack awareness of program semantics, resulting in incorrect programs, or even programs which do not compile. In this paper, we systematically study whether automated program repair (APR) techniques can fix the incorrect solutions produced by language models in LeetCode contests. The goal is to study whether APR techniques can enhance reliability in the code produced by large language models. Our study revealed that: (1) automatically generated code shares common programming mistakes with human-crafted solutions, indicating APR techniques may have potential to fix auto-generated code; (2) given bug location information provided by a statistical fault localization approach, the newly released Codex edit mode, which supports editing code, is similar to or better than existing Java repair tools TBar and Recoder in fixing incorrect solutions. By analyzing the experimental results generated by these tools, we provide several suggestions: (1) enhancing APR tools to surpass limitations in patch space (e.g., introducing more flexible fault localization) is desirable; (2) as large language models can derive more fix patterns by training on more data, future APR tools could shift focus from adding more fix patterns to synthesis/semantics based approaches, (3) combination of language models with APR to curate patch ingredients, is worth studying.
研究动机与目标
- 分析大型语言模型(如Codex)自动生成代码中常见的错误类型。
- 评估现有自动化程序修复(APR)工具(TBar和Recoder)在修复LLM生成代码中的错误时的有效性。
- 评估Codex的编辑模式(Codex-e)作为新型APR技术在修复自动生成程序方面的性能。
- 探索将语言模型与APR结合以通过更优的补丁生成和故障定位来提升代码质量的潜力。
- 识别当前APR方法的关键局限性,并为提升LLM生成代码的可修复性提出未来研究方向。
提出的方法
- 从LeetCode收集113个编程任务,并使用Codex生成解决方案,构建LMDefects数据集。
- 应用统计故障定位(SFL)识别错误解决方案中可能的错误位置,为APR工具提供指导。
- 使用测试套件评估传统APR工具(TBar和Recoder)在修复Codex生成代码中的错误时的能力。
- 将Codex-e用作黑盒修复工具,通过自然语言指令和错误位置提示生成补丁。
- 在有无故障定位引导的条件下,比较TBar、Recoder和Codex-e的修复成功率。
- 分析补丁特征和错误模式,以识别LLM生成代码中反复出现的缺陷及修复挑战。

实验结果
研究问题
- RQ1大型语言模型(如Codex)生成的代码中,常见的错误类型有哪些?
- RQ2现有基于模式和基于学习的APR工具(如TBar、Recoder)在修复LLM生成代码中的错误时效果如何?
- RQ3Codex的编辑模式(Codex-e)是否能在修复大型语言模型生成的错误代码方面优于传统APR工具?
- RQ4包含故障定位信息是否能提升Codex-e生成补丁的质量和成功率?
- RQ5当前APR技术在应用于LLM生成代码时存在哪些关键局限性?未来APR研究应如何借助语言模型能力进行引导?
主要发现
- Codex生成代码中57%的错误为算法错误,11%为语法错误,表明LLM的错误模式与人类程序员相似。
- 13.4%的错误仅需小幅度修改(如操作符或变量替换),而18.5%的错误需要较大的代码修改,显示出显著的修复复杂性。
- 在获得故障定位引导的情况下,Codex-e在修复错误代码方面的表现优于TBar和Recoder,修复成功率更高。
- 即使没有明确的故障位置信息,Codex-e的表现也与传统APR工具相当或更优,表明其作为灵活修复机制具有强大潜力。
- 现有APR工具在搜索空间受限、无法生成多编辑补丁以及对程序依赖关系缺乏认知方面存在困难,凸显了可扩展性和表达能力的关键局限。
- 本研究指出,未来APR研究应聚焦于提升故障定位的灵活性,并利用语言模型从大规模代码生成数据中自动整理修复模式。

更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。