TL;DR
This paper presents a comprehensive study of Large Language Models (LLMs) for code generation, revealing their limitations with complex problems and a tendency to produce shorter, more complicated code. The authors introduce a novel bug taxonomy and a real-world benchmark, then propose a self-critique method that significantly improves code repair success rates.
What Problem Does This Paper Address?
While LLMs have shown impressive capabilities in code generation, they still struggle with complex programming tasks, often producing incorrect or inefficient code. Existing research has primarily focused on accuracy (passing unit tests) and has lacked a deep dive into the characteristics of generated code, the root causes of bugs, and evaluation on real-world projects. This paper aims to bridge this gap by providing a thorough empirical study of LLM code generation, a detailed bug taxonomy, a new real-world benchmark, and a practical method for bug mitigation.
Methods
The authors conducted an extensive empirical study evaluating nine state-of-the-art LLMs (both closed-source and open-source) on three widely used benchmarks and a newly created real-world benchmark. They analyzed code characteristics like length, cyclomatic complexity, and API usage. A key methodological contribution is the development of a bug taxonomy with three primary and ten secondary bug types, derived from automated and manual annotation. Finally, they proposed a novel, training-free iterative method that leverages LLMs for self-critique and code correction, guided by the bug taxonomy and compiler feedback.
Datasets
- Existing Benchmarks: HumanEval+, MBPP+, and APPS+ were used for evaluation.
- Real-World Benchmark (RWPB): A new benchmark was constructed by manually collecting 140 real-world programming requirements from GitHub repositories established in 2024. This benchmark aims to address data leakage issues present in some existing benchmarks and to better reflect real-world coding scenarios.
Key Insights and Ideas
- Complexity is a Bottleneck: LLMs show systematic performance degradation as problem complexity increases (measured by cyclomatic complexity, API usage, and code length). Even top models struggle with competition-level tasks.
- Shorter, More Complex Code: Generated code tends to be shorter but more complex than canonical solutions, suggesting LLMs might prioritize brevity over maintainability.
- Bug Taxonomy is Crucial: A detailed bug taxonomy is essential for understanding LLM limitations and developing effective repair strategies.
- Self-Critique for Improvement: LLMs can be effectively used to critique and correct their own generated code, significantly improving accuracy without additional training.
- Real-World vs. Benchmarks: Bug distributions in real-world projects differ from existing benchmarks, particularly with higher rates of runtime bugs like incorrect arguments and boundary condition checks.
Key Results
- Overall Accuracy: LLMs achieved an average passing rate of 48.9% on the evaluated benchmarks. DeepSeek-R1 and DeepSeek-V3 performed best with 71.2% and 62.6% accuracy, respectively.
- Bug Distribution: Functional bugs are the most prevalent, while syntax bugs are the least common, a trend consistent across most models.
- RWPB Performance: DeepSeek-R1 and DeepSeek-V3 achieved the highest passing rates (77.9% and 75.7%) on the RWPB benchmark, outperforming closed-source models.
- Self-Critique Effectiveness: The proposed self-critique method achieved a repair success rate of 29.2% after two iterations, significantly mitigating bugs.
- Comparison with Other Methods: The authors' self-critique method outperformed existing methods like Self-debug and Intervenor, especially when incorporating the bug taxonomy.
Limitations and Future Work
- Dataset Validity: The study acknowledges potential issues with existing benchmarks, such as irrelevant background information and missing images in APPS+. They also note that all used benchmarks are monolingual (Python), limiting generalizability to other languages.
- External Validity: While the study uses a diverse set of LLMs and benchmarks, the generalizability of results to all scenarios might still be a concern.
- Annotation Process: The use of GPT-4 for annotation assistance, while efficient, could introduce "lazy annotation" or expert bias.
- Future Work:
- Explore multilingual code generation and bug analysis.
- Develop more effective code data synthesis pipelines for automated benchmark construction.
- Further leverage bug categorization for reward function design in reinforcement learning.
- Investigate the impact of different prompt engineering strategies and decoding methods on bug distributions.
- Enhance LLMs' ability to infer and validate API components for better runtime semantic understanding.
- Explore hybrid training approaches combining supervised learning and reinforcement learning from compiler feedback.
Summary updated