[Paper Review] Do Large Code Models Understand Programming Concepts? Counterfactual Analysis for Code Predicates
This paper introduces CACP, a black-box counterfactual testing framework that evaluates whether large code models understand core programming concepts like control flow and data flow by applying minimal, targeted code mutations. The study reveals that state-of-the-art models suffer up to 33% accuracy drops on perturbations involving control-flow and data-flow predicates, indicating significant gaps in conceptual understanding despite strong performance on standard benchmarks.
Large Language Models' success on text generation has also made them better at code generation and coding tasks. While a lot of work has demonstrated their remarkable performance on tasks such as code completion and editing, it is still unclear as to why. We help bridge this gap by exploring to what degree auto-regressive models understand the logical constructs of the underlying programs. We propose Counterfactual Analysis for Programming Concept Predicates (CACP) as a counterfactual testing framework to evaluate whether Large Code Models understand programming concepts. With only black-box access to the model, we use CACP to evaluate ten popular Large Code Models for four different programming concepts. Our findings suggest that current models lack understanding of concepts such as data flow and control flow.
Motivation & Objective
- To investigate whether large code models truly understand fundamental programming concepts such as control flow, data flow, data types, and identifier naming.
- To address the lack of fine-grained evaluation in existing benchmarks, which cannot isolate failures due to specific programming concepts.
- To develop a black-box, automated framework that enables probing model understanding without fine-tuning or model access beyond hard-label outputs.
- To create a new benchmark dataset with counterfactual code perturbations to measure model robustness to concept-specific changes.
- To quantify how model size, training data (e.g., code-fine-tuned vs. general), and memorization affect understanding of programming predicates.
Proposed method
- Design four minimal, concept-specific code perturbations: flipping if-else conditions (control flow), swapping independent statements (control flow), breaking def-use chains (data flow), and renaming variables (identifier naming).
- Apply these mutations to existing code completion benchmarks (HumanEval, MBPP, CodeContests) to generate counterfactual inputs that preserve program functionality but alter only one programming concept predicate.
- Use hard-label black-box access to evaluate model outputs on perturbed inputs by measuring correctness via unit tests.
- Define and compute the Average Model Effect (AME) as a metric to quantify the impact of each perturbation on model performance.
- Perform ablation studies across model size, training data (e.g., code-fine-tuned vs. non-code models), and memorization effects using training data frequency analysis.
- Develop a new benchmark dataset by extending existing datasets with counterfactual examples, enabling reproducible evaluation of predicate understanding.

Experimental results
Research questions
- RQ1To what extent do large code models understand control flow, as measured by their sensitivity to if-else condition flips?
- RQ2How well do models preserve correctness when def-use chains are broken, indicating data flow understanding?
- RQ3Does model performance degrade significantly when variable names are changed, revealing reliance on identifier names?
- RQ4How does model size and code-specific fine-tuning affect robustness to concept-specific perturbations?
- RQ5To what extent is model failure due to memorization of specific relational operators in training data?
Key findings
- State-of-the-art code models exhibit up to a 33% drop in correctness on control-flow perturbations, indicating weak understanding of conditional execution flow.
- Data flow perturbations, such as breaking def-use chains, cause correctness drops exceeding 20% in several models, showing limited comprehension of variable lifetime and usage.
- Models trained on code (e.g., StarCoder, Llama Code) or fine-tuned on code (PaLM 2-S*) outperform general-purpose models, but still show significant vulnerability to concept-specific mutations.
- Smaller models perform significantly worse than larger ones on identifier naming perturbations, with performance improving monotonically with model size.
- Memorization effects are evident: relational operators appearing more frequently in training data show higher correctness drops when flipped, suggesting pattern memorization over semantic understanding.
- Perturbations for different PCPs show low correlation, confirming that the mutations are predicate-specific and not due to general model instability or error patterns.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.