AI
Large Language Models Struggle When Code Gets Lightly Modified
Researchers find that even minor transformations to code significantly degrade LLMs' ability to recognize whether two programs do the same thing.
A new study reveals a critical weakness in how large language models handle code equivalence—the task of determining whether two programs perform the same function despite surface-level differences. Researchers have found that current state-of-the-art LLMs perform dramatically worse when code undergoes simple transformations, and the problem gets even worse when comparing programs written in different languages.
The Challenge with Code Transformations#
The gap between how LLMs handle original code and slightly modified versions is surprisingly large. When researchers applied straightforward code transformations—changes that don't alter what a program actually does—performance dropped sharply. This is troubling because code rewriting and translation tasks often involve exactly these kinds of modifications.
Introducing CETBench#
To measure this problem systematically, researchers created CETBench (Code Equivalence with Transformations Benchmark). The benchmark works by:
- Starting with a repository of programs that may or may not solve the same underlying task
- Randomly applying predefined code transformations to pairs of programs
- Creating datasets where pairs are either functionally equivalent or genuinely different
- Supporting cross-lingual comparisons and varying difficulty levels
This approach lets researchers test LLM performance under controlled conditions and measure how vulnerable these models are to seemingly minor code changes.
Cross-Language Complications#
The problems intensify significantly when comparing code across different programming languages. This suggests that LLMs may lack robust semantic understanding of code that transcends language-specific syntax and idioms.
A Partial Solution#
The researchers propose a fine-tuning approach that can improve LLM performance on transformed code pairs. However, their broader analysis indicates that large language models may still be far from achieving genuine semantic understanding of code—they appear to rely more on surface patterns than on deeper logical equivalence.

