Skip to main content
QUICK REVIEW

[Paper Review] CodeMind: Evaluating Large Language Models for Code Reasoning

Changshu Liu, Chen, Yang|arXiv (Cornell University)|Feb 15, 2024
Software Engineering ResearchComputer Science3 citations
TL;DR

CodeMind is a framework that evaluates large language models (LLMs) on three code reasoning tasks—Independent Execution Reasoning (IER), Dependent Execution Reasoning (DER), and Specification Reasoning (SR)—to assess their ability to reason about code execution and specifications beyond test passing. The study reveals that while LLMs perform well on simple programs and code they can synthesize, their reasoning degrades significantly with complexity, non-primitive types, and API calls, and specification reasoning does not imply execution reasoning.

ABSTRACT

Large Language Models (LLMs) have been widely used to automate programming tasks. Their capabilities have been evaluated by assessing the quality of generated code through tests or proofs. The extent to which they can reason about code is a critical question revealing important insights about their true capabilities. This paper introduces CodeMind, a framework designed to gauge the code reasoning abilities of LLMs through the following explicit and implicit code reasoning tasks: Independent Execution Reasoning (IER), Specification Reasoning (SR) and Dynamic Semantics Reasoning (DSR). The first evaluates the abilities of LLMs to simulate the execution of given inputs to a code and predict the output (IER). The second assesses the abilities of LLMs to incorporate the simulation of test data in the specification into code generation (SR). Finally, CodeMind evaluates LLMs' abilities to understand overall code semantics only given a specific input/output (DSR). Our extensive evaluation of ten LLMs across four widely used benchmarks using CodeMind shows that LLMs, depending on their size and training strategy, can reason about some dynamic aspects of code. However, their performance drops for code with higher complexity, non-trivial logical and arithmetic operators, non-primitive types, and API calls. We show that these reasoning tasks evaluate LLMs differently, and a comprehensive evaluation of code reasoning requires them all. Finally, we show that the performance of LLMs in bug repair is not correlated with any of the code reasoning tasks, and except for advanced frontier models, other LLMs do not incorporate code reasoning when performing bug repair.

Motivation & Objective

  • To address the limitations of test-passing evaluation in LLMs for code synthesis, which may mask data leakage or flawed reasoning.
  • To develop a framework that measures deeper code reasoning abilities, including execution traceability and specification adherence.
  • To investigate whether LLMs can reason about code execution without relying on natural language specifications or test data.
  • To compare the reasoning performance of general-purpose and code-specific LLMs across diverse programming benchmarks.
  • To identify failure patterns in reasoning related to control flow, operators, data types, and API usage.

Proposed method

  • Propose CodeMind, a framework with three core tasks: IER (reasoning about execution of arbitrary code), DER (reasoning about code the model itself generated), and SR (reasoning about specified input-output behavior).
  • Design prompts to elicit step-by-step chain-of-thought reasoning from LLMs for each task, ensuring no reliance on test data during reasoning.
  • Evaluate nine LLMs—including GPT-3.5, CodeLlama, StarCoder, and MagicCoder—on 5,395 programs from five benchmarks: HumanEval, MBPP, CRUXEval, CodeNet, and Avatar.
  • Use grounded theory analysis to identify failure patterns in reasoning, focusing on control flow, arithmetic/logic operators, data types, and API calls.
  • Classify output types (e.g., Int, List, Tuple, Decimal) and measure Type Match and Value Match to assess reasoning accuracy.
  • Conduct manual analysis on failed cases to understand root causes, such as misinterpreting conditional branches or bitwise operators.
Figure 1 : An example illustrating the importance of evaluating LLMs on code reasoning
Figure 1 : An example illustrating the importance of evaluating LLMs on code reasoning

Experimental results

Research questions

  • RQ1To what extent can LLMs reason about the execution of arbitrary code without test data or natural language references?
  • RQ2How does reasoning performance vary between code the model generated versus code it did not generate?
  • RQ3Is there a strong correlation between test-passing performance and execution reasoning ability in LLMs?
  • RQ4How do complex control structures, non-primitive types, and API calls affect LLM reasoning accuracy?
  • RQ5What are the primary failure modes in LLM reasoning, such as misinterpreting conditionals or bitwise operators?

Key findings

  • LLMs demonstrate strong reasoning for simple programs and code they correctly synthesize, but performance drops significantly with code complexity.
  • There is negligible to no correlation between model ranking based on test-passing performance and execution reasoning performance, indicating test passing is a weak proxy for reasoning ability.
  • LLMs struggle with conditional constructs, often misinterpreting branches or incorrectly evaluating predicates, especially in nested or complex conditions.
  • Bitwise operators (e.g., &, |, <<, >>) are more error-prone than arithmetic or comparison operators, even when models understand individual operator semantics.
  • LLMs achieve high Type Match (>80%) but significantly lower Value Match for complex types like Lists and Tuples, due to difficulty tracking multi-element data flow.
  • Reasoning about API calls (e.g., min(), next()) is a major bottleneck, as models often fail to understand their behavior despite correct understanding of basic operators.
CodeMind: Evaluating Large Language Models for Code Reasoning

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.