TL;DR
While Large Language Models (LLMs) excel at generating and predicting code outputs on standard benchmarks, they are highly fragile under minor syntactic changes. By applying semantics-preserving mutations (like renaming variables or unrolling loops), this paper reveals that even top-tier proprietary models suffer performance drops of up to 70%, while open-access models frequently rely on flawed reasoning or lucky guesses for up to 55% of their "correct" answers.
What Problem Does This Paper Address?
With the rapid adoption of AI-assisted development (or "vibe coding"), engineers increasingly rely on LLMs to write, debug, and explain code. Current evaluations often measure an LLM's capability purely by its output accuracy on standard benchmarks. However, high accuracy can mask a critical flaw: just as LLMs can solve math problems using completely broken logic, they might also predict code behavior through superficial pattern matching rather than genuine semantic understanding.
The authors tackle this gap by investigating whether state-of-the-art LLMs truly understand program semantics or are merely exploiting surface-level syntactic cues.
Methods
The authors evaluate LLMs on a code execution prediction task: given a Python function and a specific input, the model must predict the output and explain its reasoning. They implement an iterative querying framework with a feedback loop (up to 5 iterations) to see if models can self-correct when notified of an error.
To rigorously test semantic robustness, the authors apply five types of semantics-preserving mutations—syntactic transformations that alter the code's structure but leave its runtime behavior completely unchanged:
- Variable Renaming: Changing local variable and argument names to random strings.
- Comparison Expression Mirroring: Flipping operands and operators (e.g., changing
x > 0to0 < x). - Swap If-Else Branches: Negating the
ifcondition and swapping the corresponding code blocks. - For-to-While Loop Conversion: Rewriting standard
forloops as explicitwhileloops with manual index tracking. - Partial Loop Unrolling: Extracting and duplicating the final iterations of a loop body outside the loop itself.
Crucially, the authors conduct a blind manual expert review of the models' Chain-of-Thought (CoT) explanations to classify correct answers as either "sound reasoning" or "flawed reasoning/guesses."
Datasets
The evaluation relies on two widely adopted Python benchmarks:
- LIVECODEBENCH: 479 problems collected from competitive programming platforms (like LeetCode and CodeForces) to minimize training data contamination.
- CRUXEVAL: 800 code execution functions generated by CodeLlama, designed to test basic program execution logic.
Key Insights and Ideas
- The "Right Answer, Wrong Reason" Phenomenon: Open-access models frequently "bluff." Between 10% and 55% of their correct output predictions are backed by completely broken logical steps in their explanation traces.
- High Baseline Accuracy $\neq$ Robustness: State-of-the-art closed-access models (GPT-5.2 and Gemini-3) achieve near-perfect scores on original benchmarks with highly sound reasoning. However, they prove shockingly fragile when the code's syntax is perturbed.
- Syntax Over Semantics: Structurally invasive changes like loop unrolling completely derail LLM reasoning. This proves that models rely heavily on pattern recognition of standard code templates rather than an abstract understanding of control and data flow.
- The Contamination Caveat: The stellar baseline performance of newer models (released late 2025) on 2024 benchmarks must be taken with a grain of salt, as they likely suffered from benchmark contamination during training.
Key Results
- Reasoning Quality: In the expert evaluation on LIVECODEBENCH, Gemini-3 and GPT-5.2 achieved 100% and 97.5% accuracy, respectively, with almost zero reliance on flawed reasoning. Among open-access models, Qwen2.5-Coder hit 62.6% accuracy but had a 10.3% guessing rate, while Llama3.2 guessed its way to a correct answer 55.1% of the time.
- Mutation Catastrophe: Structurally invasive mutations caused dramatic performance drops across the board. Under Loop Unrolling on LIVECODEBENCH, GPT-5.2's accuracy plummeted from 97.1% to 29.0% (a 68.1 point drop), and Gemini-3 dropped from 100% to 29.6% (a 70.4 point drop).
- Variable Renaming Quirks: Interestingly, variable renaming improved performance for several open-source models (e.g., Qwen2.5-Coder jumped +14.0%), but caused Gemini-3 to drop by 31.9 points, showing unpredictable sensitivity to identifier names.
Limitations and Future Work
The primary limitation of current LLMs is the absence of formal semantic constraints; purely data-driven statistical models lack the boundaries required for stable code reasoning. Additionally, the exact composition of proprietary training corpora remains unknown, making it difficult to fully decouple genuine reasoning from memorization.
The authors advocate for neuro-symbolic hybrid approaches—integrating formal methods (such as abstract syntax trees and formal semantic constraints) into machine learning objectives to build truly robust, semantics-aware code models.
Summary updated