基于微分模糊测试的LLM生成代码重构功能等价性评估
A Differential Fuzzing-Based Evaluation of Functional Equivalence in LLM-Generated Code Refactorings
AI总结:
本文提出基于微分模糊测试的方法,评估LLM生成代码重构的功能等价性,发现LLM生成的重构存在显著语义偏差,现有测试套件难以检测。
摘要:
随着大型语言模型(LLMs)在自动化代码重构中的快速应用,评估和确保LLM生成的重构与原始实现之间功能等价性变得至关重要。尽管以往的工作通常依赖于预定义的测试用例来评估正确性,但在这项工作中,我们利用微分模糊测试来检查LLM生成的代码重构的功能等价性。与基于测试的评估不同,基于微分模糊测试的等价检查器不需要预定义的测试用例,可以通过执行和比较成千上万个自动生成的测试输入来探索更大的输入空间。在对六个LLM(CodeLlama、Codestral、StarChat2、Qwen-2.5、Olmo-3和GPT-4o)在三个数据集和两种重构类型上的大规模评估中,我们发现LLM有非平凡的倾向改变程序语义,产生19-35%功能上不等价的重构。我们的实验进一步表明,大约21%的这些不等价的重构仍无法被三个评估数据集的现有测试套件检测到。总体而言,本研究的发现表明,依赖现有测试可能会高估LLM生成代码重构的功能等价性,这些重构仍然容易出现语义偏离。
英文摘要:
With the rapid adoption of large language models (LLMs) in automated code refactoring, assessing and ensuring functional equivalence between LLM-generated refactoring and the original implementation becomes critical. While prior work typically relies on predefined test cases to evaluate correctness, in this work, we leverage differential fuzzing to check functional equivalence in LLM-generated code refactorings. Unlike test-based evaluation, a differential fuzzing-based equivalence checker needs no predefined test cases and can explore a much larger input space by executing and comparing thousands of automatically generated test inputs. In a large-scale evaluation of six LLMs (CodeLlama, Codestral, StarChat2, Qwen-2.5, Olmo-3, and GPT-4o) across three datasets and two refactoring types, we find that LLMs show a non-trivial tendency to alter program semantics, producing 19-35% functionally non-equivalent refactorings. Our experiments further demonstrate that about 21% of these non-equivalent refactorings remain undetected by the existing test suites of the three evaluated datasets. Collectively, the findings of this study imply that reliance on existing tests might overestimate functional equivalence in LLM-generated code refactorings, which remain prone to semantic divergence.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。