arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2503.11082cs.SE
收藏

LLM 是缺陷复制器:关于 LLM 完成易含缺陷代码能力的实证研究

LLMs are Bug Replicators: An Empirical Study on LLMs' Capability in Completing Bug-prone Code

Liwei Guo, Sixiang Ye, Zeyu Sun, Xiang Chen, Yuxia Zhang, Bo Wang, Jie M. Zhang, Zheng Li, Yong Liu

AI总结:

本文通过 7 个 LLM 在 Defects4J 上的实证研究,发现模型完成易含缺陷代码时准确率低且常复制历史缺陷,现有后处理也难以显著降错。

摘要:

大语言模型(LLM)在代码补全方面表现出卓越性能。然而,用于开发这些模型的训练数据通常包含大量有缺陷代码。目前仍不清楚,在处理易含缺陷代码的补全任务时,这些有缺陷实例会在多大程度上影响 LLM 的性能。为填补这一空白,本文提出首个评估 LLM 完成易含缺陷代码性能的实证研究。通过在 7 个 LLM 和 Defects4J 数据集上进行大量实验,我们分析了 LLM 在这一具有挑战性的情境中的准确性、鲁棒性和局限性。实验结果表明,对 LLM 而言,完成易含缺陷代码明显比完成普通代码更困难。值得注意的是,在易含缺陷任务中,LLM 生成正确代码的可能性几乎与生成有缺陷代码相同,并且显著低于普通代码补全任务(例如 GPT-4 为 12.27% 对 29.85%)。令我们惊讶的是,LLM 产生的缺陷中有 44.44% 与修复前版本完全相同,这表明 LLM 在补全代码时受到历史缺陷的严重偏置。此外,我们调查了现有后处理技术的有效性,发现尽管它们能够提升一致性,但在易含缺陷代码场景中并不能显著降低错误率。我们的研究强调了当前 LLM 在处理易含缺陷代码方面的局限,并表明需要改进模型和后处理策略,以提升真实开发环境中的代码补全准确性。

英文摘要:

Large Language Models (LLMs) have demonstrated remarkable performance in code completion. However, the training data used to develop these models often contain a significant amount of buggy code. Yet, it remains unclear to what extent these buggy instances influence LLMs' performance when tackling bug-prone code completion tasks. To fill this gap, this paper presents the first empirical study evaluating the performance of LLMs in completing bug-prone code. Through extensive experiments on 7 LLMs and the Defects4J dataset, we analyze LLMs' accuracy, robustness, and limitations in this challenging context. Our experimental results show that completing bug-prone code is significantly more challenging for LLMs than completing normal code. Notably, in bug-prone tasks, the likelihood of LLMs generating correct code is nearly the same as generating buggy code, and it is substantially lower than in normal code completion tasks (e.g., 12.27% vs. 29.85% for GPT-4). To our surprise, 44.44% of the bugs LLMs make are completely identical to the pre-fix version, indicating that LLMs have been seriously biased by historical bugs when completing code. Additionally, we investigate the effectiveness of existing post-processing techniques and find that while they can improve consistency, they do not significantly reduce error rates in bug-prone code scenarios. Our research highlights the limitations of current LLMs in handling bug-prone code and underscores the need for improved models and post-processing strategies to enhance code completion accuracy in real-world development environments.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑