Can LLMs Really Reason about Code? Studying How Well LLMs Understand the Relation between Input, Code, and Output
Open Access
- 5 July 2026
- conference paper
- Published by Association for Computing Machinery (ACM)
- p. 21-30
Abstract
In the past years, large language models (LLMs) have demonstrated remarkable progress in code generation. However, their ability to reason about program behavior remains an open challenge—an ability that is relevant for applications including reverse engineering, debugging, secure code generation, test-driven synthesis, input reconstruction, reverse fuzzing, behavioral monitoring, and safe execution modeling. To study this ability, we examine the capacity of LLMs to reason about the semantics of code—specifically, their ability to relate code, its inputs, and its outputs to each other. To this end, we investigate whether and how well LLMs can predict one of these three components given the other two—that is, (1) predict the input given code and output, (2) predict the output given code and input, and (3) predict the code given input and output. This way, we assess how well LLMs can reason about and understand the underlying relationships that govern program execution. We construct four datasets covering string processing, array operations, and coding challenges in JavaScript and Python to evaluate diverse program-understanding capabilities, incorporating various code mutation techniques to increase complexity. In our evaluation on tasks covering string processing, array operations, and coding challenges, we find that closed-weight models achieve the strongest performance across all datasets, including perfect input recovery on deterministic string tasks. Across tasks, output prediction is comparatively stable, whereas code prediction remains the hardest setting and often fails for smaller models. Finally, cross-codebase transfer is feasible, especially for input prediction, but highly sensitive to model capacity and fine-tuning strategy.Keywords
Funding Information
- ERC S3 (101093186)
This publication has 12 references indexed in Scilit:
- Learning Program Behavioral Models from Synthesized Input–Output PairsACM Transactions on Software Engineering and Methodology, 2026
- Reasoning Runtime Behavior of a Program with LLM: How Far are We?2025
- CRUXEVAL-X: A Benchmark for Multilingual Code Reasoning, Understanding and Execution2025
- AI models collapse when trained on recursively generated dataNature, 2024
- Evaluating Large Language Models in Class-Level Code Generation2024
- TRACED: Execution-aware Pre-training for Source Code2024
- Code Execution with Pre-trained Language Models2023
- A systematic evaluation of large language models of code2022
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation2021
- BLEU2001