arXiv:2504.04372cs.SEcs.AI2025-04被引 7

测试大模型代码修复能力,发现其推理常依赖表面语法而非语义。

Assessing the Impact of Code Changes on the Fault Localizability of Large Language Models

  • 用变异测试法构建新评估框架,避免数据污染与可扩展性问题。
  • 78%的故障定位在语义保持变异后失效,说明模型依赖无关语法特征。
  • 代码位置靠前时推理更强,提示需优化模型对语义的优先级理解。

生成式大语言模型(LLMs)越来越多地应用于非生成类软件维护任务,如缺陷定位(FL)。FL的成功依赖于模型对程序语义的深层理解,而非仅表面的语法和词汇特征。然而,现有广泛使用的LLM基准主要评估代码生成能力,与语义推理存在本质差异。传统缺陷定位基准如Defect4J和BugsInPy因数据已进入训练集而变得不可靠,导致结果偏差。本文首次开展大规模实证研究,评估LLMs在缺陷定位中的鲁棒性。受变异测试启发,我们构建了一个端到端评估框架,解决现有方法在数据污染、可扩展性、自动化和可拓展性方面的关键局限。利用超过1,300个真实程序及其规格说明,注入未见过的缺陷,要求LLMs进行定位,并剔除不明确的程序以避免歧义。对成功定位的每个程序,应用语义保持变异(SPMs),重新执行定位以评估鲁棒性,判断模型是否依赖语法线索而非语义。我们在750,013个任务上评估了10个先进LLMs。结果显示,SPMs使78%的先前成功定位失败,且相关代码在上下文中越靠前,推理越强。这表明,当前LLM的代码推理往往依赖于与语义无关的特征。我们还识别出若干难以处理的代码模式。总体而言,这些发现推动了对LLMs如何表示、解释和优先处理代码语义的根本改进。

原文摘要 · Abstract (English)

Generative Large Language Models (LLMs) are increasingly used in non-generative software maintenance tasks, such as fault localization (FL). Success in FL depends on a models ability to reason about program semantics beyond surface-level syntactic and lexical features. However, widely used LLM benchmarks primarily evaluate code generation, which differs fundamentally from semantic program reasoning. Meanwhile, traditional FL benchmarks such as Defect4J and BugsInPy are either not scalable or obsolete, as their datasets have become part of LLM training data, leading to biased results. This paper presents the first large-scale empirical investigation into the robustness of LLMs fault localizability. Inspired by mutation testing, we develop an end-to-end evaluation framework that addresses key limitations in existing LLM evaluation, including data contamination, scalability, automation, and extensibility. Using real-world programs with specifications, we inject unseen faults and ask LLMs to localize them, filtering out underspecified programs where localization is ambiguous. For each successfully localized program, we apply semantic-preserving mutations (SPMs) and rerun localization to assess robustness and determine whether LLM reasoning relies on syntactic cues rather than semantics. We evaluate 10 state-of-the-art LLMs on 750,013 fault localization tasks from over 1,300 Java and Python programs. We find that SPMs cause LLMs to fail on previously localized faults in 78% of cases, and that reasoning is stronger when relevant code appears earlier in context. These results indicate that LLM code reasoning is often tied to features irrelevant to semantics. We also identify code patterns that are challenging for LLMs to reason about. Overall, our findings motivate fundamental advances in how LLMs represent, interpret, and prioritize code semantics to reason more deeply about program logic

缺陷定位大模型评估代码理解语义推理

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。