What's Wrong with Your Code Generated by Large Language Models? An Extensive Study

Shihan Dou, Haoxiang Jia, Shenxi Wu, Huiyuan Zheng, Muling Wu, Yunbo Tao, Ming Zhang, Mingxu Chai, Jessica Fan, Zhiheng Xi, Rui Zheng, Yueming Wu, Ming Wen, Tao Gui, Qi Zhang, Xipeng Qiu, Xuanjing Huang

TL;DR

This paper presents a massive empirical autopsy of code generated by nine leading LLMs, revealing that AI-generated code is often "shorter but messier"—more complex and harder to maintain than human solutions. The authors introduce a new 10-category bug taxonomy and a real-world benchmark (RWPB) to prove that current models struggle significantly more with practical projects than standard coding puzzles.

What Problem Does This Paper Address?

While LLMs have revolutionized code generation, we still treat them as "black boxes" that either pass or fail a unit test. There is a lack of deep understanding regarding why they fail, how their code structure differs from human "canonical" solutions, and whether our current benchmarks (like HumanEval) actually reflect real-world software engineering challenges. Furthermore, many existing benchmarks suffer from "data contamination," where the models have already seen the test questions during training.

Methods

The researchers evaluated nine state-of-the-art models, including closed-source giants (GPT-4, Claude-3) and open-source powerhouses (DeepSeek-V3, Llama-3). Their approach involved:

  1. Multi-dimensional Analysis: Beyond just "pass/fail," they measured code length, cyclomatic complexity (a measure of logical paths), and API usage.
  2. Bug Taxonomy Development: They manually annotated 5,741 bugs to create a hierarchy of three primary types (Syntax, Runtime, Functional) and ten sub-categories (e.g., API Misuse, Hallucination, Logic Errors).
  3. Iterative Self-Critique: They proposed a training-free method where the LLM is prompted to analyze its own incorrect code using the new bug taxonomy and compiler feedback to fix itself.

Datasets

The study utilized three classic benchmarks:

  • HumanEval+ & MBPP+: Enhanced versions of standard benchmarks with more rigorous unit tests.
  • APPS+: A benchmark focused on high-difficulty competitive programming.

Crucially, the authors introduced RWPB (Real-World Project Benchmark). This dataset consists of 140 functions curated from GitHub repositories created in 2024 to ensure the models hadn't seen the code during pre-training, specifically filtering for standalone functions with high test coverage.

Key Insights and Ideas

  • The "Short but Messy" Paradox: LLMs tend to produce code that has fewer lines than human solutions but higher cyclomatic complexity. Essentially, they cram too much logic into too few lines, making the code harder to maintain. Code characteristics comparison
  • The Commenting Trap: Counterintuitively, models often generate more comments when they are uncertain or about to produce incorrect code. The exception is reasoning-heavy models like DeepSeek-R1, which maintain consistent comment density because they "think" internally rather than through externalized comments. Comment density in correct vs incorrect code
  • Reasoning > Scale: Architectural innovations that favor explicit reasoning (like DeepSeek-R1) show a massive performance jump (up to 40%) over traditional autoregressive models, especially on complex tasks.
  • Real-World Divergence: Bugs in real-world projects (RWPB) are distributed differently than in coding puzzles. Real-world code sees a much higher proportion of runtime bugs, particularly related to incorrect arguments and boundary conditions.
Code characteristics comparison
Comment density in correct vs incorrect code

Key Results

  • Top Performer: DeepSeek-R1 led the pack with a 71.2% average success rate across all benchmarks, significantly outperforming GPT-4 (63.8%).
  • Complexity Failure: On the hardest "Competition" level tasks in APPS+, performance cratered. StarCoder-2 managed only a 2% success rate, while even GPT-4 only hit 36%.
  • Bug Mitigation: The proposed self-critique method (using the prompt template below) achieved a 29.2% repair success rate after just two iterations, proving that LLMs can fix their own logic if given the right taxonomic framework. Self-critique prompt template
  • Bug Taxonomy: Functional bugs (logic errors) are the most common, while syntax bugs are relatively rare, suggesting models have mastered grammar but not intent. Bug taxonomy overview
Self-critique prompt template
Bug taxonomy overview

Limitations and Future Work

The study is currently monolingual, focusing exclusively on Python. The authors acknowledge that bug distributions and model performance might shift significantly in strictly typed languages like C++ or Java. Additionally, while the self-critique method is effective, it relies on the model's own ability to recognize its mistakes, which can lead to "lazy annotation" or hallucinations during the critique phase. Future work aims to automate the RWPB construction pipeline and explore multilingual scenarios.

Summary updated

Abstract

The increasing development of LLMs in code generation has drawn significant attention among researchers. To enhance LLM-based code generation ability, current efforts are predominantly directed towards collecting high-quality datasets and leveraging diverse training technologies. However, there is a notable lack of comprehensive studies examining the limitations and boundaries of existing methods. To bridge this gap, we conducted an extensive empirical study evaluating the performance of three leading closed-source LLMs and six popular open-source LLMs on three commonly used benchmarks. Our investigation, which evaluated the length, cyclomatic complexity and API number of the generated code, revealed that these LLMs face challenges in generating successful code for more complex problems, and tend to produce code that is shorter yet more complicated as compared to canonical solutions. Additionally, we developed a taxonomy of bugs for incorrect codes that includes three categories and ten sub-categories, and analyzed the root cause for common bug types. To better understand the performance of LLMs in real-world projects, we also manually created a real-world benchmark RWPB. We analyzed bugs on RWPB to highlight distinct differences in bug distributions between actual scenarios and existing benchmarks. Finally, we propose a novel training-free iterative method that introduces self-critique, enabling LLMs to critique and correct their generated code based on bug types and compiler feedback. Our comprehensive and extensive study provides insights into the current limitations of LLM-based code generation and opportunities for enhancing the accuracy and quality of the generated code.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
GPT-4 code-repair evaluationSelf-critique/self-revision bug repair using bug taxonomy and compiler feedbackRepair success rate, iteration 229.2%+0.9 vs baselinesplit: test · iteration=2
Source quote
L925: Ours │ 24.1% │ 29.2%
Reported baseline / comparator measurements (3)
BenchmarkMethodMetricScoreProtocol / Evidence
RWPBDeepSeek-R1 (DSR) baselinePASS rate77.9%Real-world benchmark of 140 programming requirements collected from GitHub; table value…
Source quote
L799: PASS │ 31.4 │ 32.9 │ 22.9 │ 22.1 │ 75.7 │ 77.9 │ 44.3 │ 34.3 │ 45.7
RWPBPhi-3 (table label: Phi3) baselinePASS rate22.1%Real-world benchmark of 140 programming requirements collected from GitHub; table value…
Source quote
L799: PASS │ 31.4 │ 32.9 │ 22.9 │ 22.1 │ 75.7 │ 77.9 │ 44.3 │ 34.3 │ 45.7
GPT-4 code-repair evaluationIntervenor baselineRepair success rate, iteration 228.3%split: test · iteration=2
Source quote
L924: Intervenor \cite{wang2024intervenor} │ 22.5% │ 28.3%
BibTeX
@article{dou2026what,
  author = {Shihan Dou and Haoxiang Jia and Shenxi Wu and Huiyuan Zheng and Muling Wu and Yunbo Tao and Ming Zhang and Mingxu Chai and Jessica Fan and Zhiheng Xi and Rui Zheng and Yueming Wu and Ming Wen and Tao Gui and Qi Zhang and Xipeng Qiu and Xuanjing Huang},
  title = {{What's Wrong with Your Code Generated by Large Language Models? An Extensive Study}},
  journal = {Science China Information Sciences},
  year = {2026},
  doi = {10.1007/s11432-025-4632-8},
}
Figure