arXiv:2608.23961cs.SEcs.AI2026-08

测试大模型跨语言判断代码功能等价的能力,发现其表现不可靠。

Evaluating Language Models on Cross-Language Code Functional Equivalence

  • 构建人类编写代码的跨语言数据集,评估模型对功能等价的判断能力。
  • 模型在难题上易误判非等价代码为等价,且存在运行不一致问题。
  • 发现模型依赖表面相似性,且对不同语言反应差异明显,适合研究者参考。

大型语言模型(LLMs)在多种代码理解任务中表现出色,使人们相信它们能推理程序语义。然而,现有评估多集中于单语言场景或依赖合成代码,引发对其是否具备真正语义理解能力的质疑。本文研究人类编写的代码中,跨编程语言的功能等价性判断能力,要求超越表层相似性的深层推理。我们提出PolyHuman数据集,包含C++、Java和Python的人类编写程序,并在此基础上评估开源与专有模型在同语言与跨语言等价检测中的表现,以GPT-o4-mini为代表模型分析稳定性。通过手动分析81例系统性错误案例,考察代码逻辑与生成的思维链推理,分类失败模式并对比GPT-o4-mini、Claude-Opus-4.7与Gemini-3-Flash的表现。结果表明:模型在难题上越来越倾向于将非等价代码误判为等价;最佳模型对编程语言敏感,尤其在Python上表现更保守;部分依赖相似性线索。此外,GPT-o4-mini在相同设置下仍存在显著运行间不稳定性,反映其能力不稳定而非缺失。结论:当前大模型无法可靠捕捉语言内或跨语言的功能等价性。

原文摘要 · Abstract (English)

Background: Large Language Models (LLMs) have demonstrated strong performance across a variety of code-understanding tasks, leading many to believe that they can reason about program semantics. However, existing evaluations primarily focus on single-language settings or rely on synthetically generated code, raising concerns about whether current results reflect true semantic understanding. Aims: We investigate whether LLMs can accurately judge functional equivalence across different programming languages in human-written code, a setting that requires deeper reasoning beyond superficial similarity. Method: We introduce PolyHuman, a dataset of human-written programs in CPP, Java, and Python. Using this dataset, we evaluate intra- and inter-language equivalence detection across open-weight and proprietary LLMs, selecting GPT-o4-mini as a representative model to assess stability. We then manually analyze 81 cases of systematic disagreement in which models incorrectly judge functional equivalence, examining the code logic and the generated Chain-of-Thought reasoning. Finally, we categorize these failures and compare them across GPT-o4-mini, Claude-Opus-4.7, and Gemini-3-Flash to determine whether they reflect model-specific issues or broader limitations of state-of-the-art LLMs. Results: We identify a difficulty-dependent breakdown in equivalence judgment (harder problems make the model increasingly prone to misclassifying non-equivalent code as equivalent), a model-specific sensitivity to programming language for the best-performing model (particularly a more conservative behavior on Python), and a partial reliance on similarity-based cues. GPT-o4-mini also shows substantial run-to-run instability under identical settings, indicating inconsistent rather than absent capability. Conclusions: Current LLMs do not reliably capture functional equivalence within or across languages.

代码理解大模型评测跨语言功能等价

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