评估AI生成代码的质量与安全性:定量分析
Assessing the Quality and Security of AI-Generated Code: A Quantitative Analysis
AI总结:
本研究通过SonarQube静态分析4442个Java任务的LLM输出,评估5个主流LLM生成代码的质量与安全性,发现其存在缺陷且功能性能与质量无直接关联,证明静态分析是AI代码部署的重要保障。
摘要:
本研究对5个主流大型语言模型(LLMs)的代码质量和安全性进行了定量评估,包括Claude Sonnet 4、Claude 3.7 Sonnet、GPT-4o、Llama 3.2 90B和OpenCoder 8B。尽管先前研究已评估了LLM生成代码的功能性能,但本研究通过SonarQube的全面静态分析,测试了4442个Java编码任务的LLM输出。研究结果表明,虽然LLMs能生成功能性代码,但也会引入一系列软件缺陷,包括错误、安全漏洞和代码异味。这些缺陷并非孤立存在,而是可能代表当前LLM代码生成方法中系统性限制导致的共同弱点。特别是,多个模型均出现硬编码密码和路径遍历漏洞等严重问题。这些结果表明,LLM生成的代码需要经过验证才能被视为可用于生产环境。本研究发现,模型的功能性能(通过单元测试的Pass@1率衡量)与其生成代码的整体质量和安全性(通过通过功能测试的基准解决方案中的SonarQube问题数量衡量)之间无直接相关性。这表明功能基准性能得分并非整体代码质量和安全性的良好指标。本研究的目标并非对LLM性能进行排名,而是强调所有评估模型似乎都存在某些共同弱点。因此,这些发现支持以下观点:静态分析可作为检测潜在缺陷的宝贵工具,也是在软件开发中部署AI的组织的重要保障。
英文摘要:
This study presents a quantitative evaluation of the code quality and security of five prominent Large Language Models (LLMs): Claude Sonnet 4, Claude 3.7 Sonnet, GPT-4o, Llama 3.2 90B, and OpenCoder 8B. While prior research has assessed the functional performance of LLM-generated code, this research tested LLM output from 4,442 Java coding assignments through comprehensive static analysis using SonarQube. The findings suggest that although LLMs can generate functional code, they also introduce a range of software defects, including bugs, security vulnerabilities, and code smells. These defects do not appear to be isolated; rather, they may represent shared weaknesses stemming from systemic limitations within current LLM code generation methods. In particular, critically severe issues, such as hard-coded passwords and path traversal vulnerabilities, were observed across multiple models. These results indicate that LLM-generated code requires verification in order to be considered production-ready. This study found no direct correlation between a model's functional performance (measured by Pass@1 rate of unit tests) and the overall quality and security of its generated code, measured by the number of SonarQube issues in benchmark solutions that passed the functional tests. This suggests that functional benchmark performance score is not a good indicator of overall code quality and security. The goal of this study is not to rank LLM performance but to highlight that all evaluated models appear to share certain weaknesses. Consequently, these findings support the view that static analysis can be a valuable instrument for detecting latent defects and an important safeguard for organizations that deploy AI in software development.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。