Are Large Language Models Robust in Understanding Code Against Semantics-Preserving Mutations?
This paper reveals that while state-of-the-art Large Language Models achieve high predictive accuracy on code tasks, they frequently rely on flawed reasoning and exhibit significant fragility, often changing their predictions when faced with semantics-preserving code mutations.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you have a very talented student who can solve complex math problems and write essays that sound incredibly smart. You ask them to explain how they solved a problem, and they give you a perfect, step-by-step story. You feel confident they truly understand the material.
But what if you told that same student, "Okay, now solve the exact same problem, but instead of using the word 'apple,' use the word 'fruit,' and instead of saying 'add,' say 'sum up'?"
If the student suddenly gets confused, changes their answer, or gives a completely different (and wrong) explanation, you'd realize they weren't actually understanding the logic of the math. They were just memorizing the specific words and patterns you used before.
This is exactly what the researchers at Oxford University found out about Large Language Models (LLMs) when they asked them to understand computer code.
The "Vibe Coding" Trap
Today, many people use AI tools to write code, a trend called "vibe coding." We trust these AI models to fix bugs and write programs. But the researchers asked a scary question: Do these AI models actually understand how code works, or are they just really good at guessing based on patterns?
To find out, they treated the AI like a student taking a test, but with a twist.
The "Shape-Shifting" Test
The researchers took a bunch of computer programs and performed five specific "magic tricks" on them. These tricks changed how the code looked (the syntax) but kept exactly the same meaning and result (the semantics). It's like taking a sentence, "The cat sat on the mat," and rewriting it as, "On the mat, the feline rested." The meaning is identical, but the words are different.
The five tricks they used were:
- Renaming Variables: Changing
my_listtox9z2. - Mirroring Comparisons: Changing
if x > 5toif 5 < x. - Swapping Logic: Switching the "if" and "else" parts of a decision.
- Loop Conversion: Changing a "for" loop into a "while" loop.
- Loop Unrolling: Manually writing out the last few steps of a loop instead of letting the computer repeat them.
The Results: Smart Guessers, Not True Thinkers
When the researchers ran these tests on nine different AI models (including the most famous ones like GPT-5.2 and Gemini-3), they found some troubling patterns:
- The "Flawed Reasoning" Problem: Even when the AI got the right answer, it often did so for the wrong reasons. In fact, between 10% and 50% of the time, the AI produced a correct answer based on a completely broken or nonsensical explanation. It was like a student guessing the right answer on a math test but writing down a made-up formula to justify it.
- The "Fragile" Problem: When the code was "shape-shifted" using the tricks above, the AI's performance crashed. Some models dropped in accuracy by as much as 70%.
- Analogy: Imagine a chef who can perfectly cook a steak if you say "cook the beef." But if you say "cook the cow," they panic and burn the kitchen. The AI models are like that chef; they are confused by simple changes in wording, even though the "meal" (the program's result) is exactly the same.
- The "Variable Name" Sensitivity: The models were surprisingly sensitive to variable names. Changing a name from
totaltosum_totaloften made them fail, even though the code logic was identical. Interestingly, humans also get slightly confused by bad naming, but the AI's reaction was much more extreme.
The "Top Students" Aren't Perfect Either
The researchers tested both free, open-source models and expensive, private models (like GPT-5.2 and Gemini-3).
- The expensive models were the best at getting the right answer and giving good explanations on the original code.
- However, when the code was changed slightly, even these "top students" stumbled badly. Their performance dropped significantly, proving that high accuracy on a standard test doesn't mean they truly understand the underlying logic.
The Bottom Line
The paper concludes that current AI models are brittle. They are excellent at recognizing patterns and mimicking human reasoning, but they lack a "formal" understanding of how code actually works.
If you ask them to solve a problem one way, they might get it right. But if you ask the same question in a slightly different way (even if the meaning is identical), they might fail completely. This suggests that for now, we shouldn't blindly trust these models to understand code deeply; they are more like very advanced parrots that can recite the right answers but don't always know why those answers are right.
The researchers suggest that to make AI truly reliable for coding, we need to combine their learning power with strict, formal rules (like a math teacher checking the work, not just the answer) to ensure they aren't just guessing.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.