Introduction
CodeSense is a new benchmark designed to move beyond simple code generation and evaluate how well Large Language Models (LLMs) actually understand the execution of real-world code. By tracing the execution of Python, C, and Java projects from GitHub, researchers found that even top-tier models like Claude 3.5 and GPT-4o struggle with basic "fine-grained" reasoning—such as tracking variable values across three lines of code or predicting how many times a loop will run.
The Problem with Current Benchmarks
Most existing code benchmarks (like HumanEval or MBPP) focus on code generation using simple, synthetic problems often found in introductory programming courses. While LLMs have become quite adept at writing boilerplate or solving "LeetCode-style" puzzles, they frequently fail at complex, real-world software engineering tasks like debugging, vulnerability detection, or refactoring.
The authors argue that these failures stem from a lack of semantic reasoning—the ability to mentally "execute" code and understand how data flows through it. Current benchmarks usually only test "coarse-grained" reasoning (e.g., "What is the final output of this entire function?"). CodeSense fills this gap by testing "fine-grained" reasoning: can the model predict the state of a variable after a single assignment, or determine if two pointers in C point to the same memory address?
Methodology
The researchers built an automated pipeline to extract ground truth from the "wild" rather than relying on synthetic, human-labeled data.
- Data Collection: They gathered 744 real-world projects from GitHub across Python, C, and Java.
- Execution Tracing: Using dynamic analysis tools (
GDBfor C,PySnooperfor Python, andJDBfor Java), they recorded the actual values of variables, return values of API calls, and loop iteration counts during test execution. - Task Design: They defined four levels of reasoning:
- Block-level: Predicting input/output for chunks of code.
- Statement-level: Predicting the result of a single line (arithmetic, boolean, etc.).
- Code Properties: Reasoning about pointers (aliasing), loop behavior, and branch outcomes.
- Approximation: Testing if models can guess the range of a value (e.g., "Positive Large" vs. a specific integer).
- Evaluation: They tested 14 state-of-the-art LLMs, including proprietary models (Claude 3.5, GPT-4o) and open-source reasoning models (DeepSeek R1, Qwen 2.5).
The CodeSense Dataset
The primary contribution is the dataset itself, which provides execution-based ground truth for complex code:
- 744 real-world projects.
- 4,483 curated samples.
- Multi-lingual support: 3,050 Python samples, 1,359 C samples, and 74 Java samples.
- Diversity: Unlike synthetic benchmarks, these functions range from 3 to 516 lines of code and include complex third-party API calls.
Key Findings & Results
- Arithmetic and APIs are Hard: As shown in the evaluation of Python programs, even for the best models, arithmetic expressions and third-party API calls (like
os.pathorsys.argv) are major stumbling blocks. Models often lack the "execution knowledge" of how standard libraries behave internally. - Low Baseline Accuracy: On single-statement blocks in C, top models like Claude 3.5 and GPT-4o achieved under 30% accuracy.
- The "Reverse" Reasoning Gap: Models are significantly worse at input prediction (given the output, what was the input?) than output prediction. For small functions, the best model (Claude 3.5) only hit ~12% accuracy on input prediction.
- Performance Decay: As the number of statements in a block increased from one to three, accuracy dropped sharply (e.g., from ~50% to ~20% for Python).
- Pattern Matching vs. Reasoning: Models often "cheat" by correlating natural language patterns. For example, if they see
p = q, they correctly guess thatpandqalias the same memory. However, if the logic is slightly more obscured, their performance plummets. - Prompting Efficacy: Chain-of-Thought (CoT) helped significantly with loop reasoning but provided almost no benefit for simple statement-level predictions.
Limitations and Future Work
- Language Scope: The current benchmark is limited to three languages. The authors plan to expand to functional and system-level languages.
- Data Types: The study focused primarily on primitive data types (integers, strings, booleans). Future iterations will need to address complex object aliasing and heap structures in Java and Python.
- Data Leakage: While using real-world code is a plus, there is always a risk that some of these popular GitHub repositories were included in the models' training sets. The authors' framework for generating new traces from new projects is intended to mitigate this over time.
Summary updated