Introduction
While Large Language Models (LLMs) have demonstrated remarkable proficiency in code generation, their ability to reason about "functional equivalence"—the property where two syntactically distinct code snippets perform the identical task—remains a significant challenge. This paper introduces SeqCoBench, a comprehensive benchmark designed to evaluate whether LLMs can distinguish between "semantic clones" (different code, same logic) and "semantic lookalikes" (similar code, different logic). Identifying functional equivalence is a cornerstone of software engineering tasks such as refactoring, optimization, and automated bug detection.
Methodology and the SeqCoBench Framework
The researchers developed a systematic framework to probe the "semantic gap" in LLMs using two primary categories of code transformations:
- Semantic-Preserving (SP): These changes alter the syntax while maintaining identical logic. Examples include variable renaming, swapping
forloops forwhileloops, or inserting "dead code" that does not affect execution. - Semantic-Altering (SA): These are subtle, adversarial changes that appear similar to the original code but break the underlying logic, such as flipping comparison operators or changing boolean constants.
The SeqCoBench dataset was constructed using functions from the MBPP (Mostly Basic Python Problems) dataset, resulting in over 14,000 code pairs. The evaluation spanned several open-source models, including Llama2, CodeLlama, and StarCoder2, across zero-shot, few-shot, and fine-tuned settings.
Experimental Results
The study reveals a "surface-level trap" where LLMs are frequently misled by high textual similarity. For instance, models often fail to detect logic errors introduced by changing an is operator to is not, as illustrated in the zero-shot prompt examples.
As shown in the results, code-specific pre-training is a critical factor. CodeLlama-13B emerged as the top performer with an Average Precision (AP) of 70.85, significantly outperforming the general-purpose Llama2-13B (43.32). Notably, simple match-based metrics like ChrF (55.25) often outperformed several LLM configurations, suggesting that many models rely on pattern matching rather than deep logical reasoning. Furthermore, while Parameter-Efficient Fine-Tuning (PEFT) improved invariance to SP changes, it struggled to enhance the detection of SA changes.
Discussion and Conclusion
The findings highlight a substantial gap between current LLM capabilities and true functional understanding. Existing LLM-based metrics show a weak correlation ($r \approx 0.31$) with actual execution-based correctness. Currently limited to Python and static analysis, future work should explore hybrid approaches that integrate neural models with formal logic or symbolic reasoning to better capture the execution flow of code.
Summary updated