用大模型+静态分析自动修代码缺陷,效果显著提升。
Augmenting Large Language Models with Static Code Analysis for Automated Code Quality Improvements
- 结合静态分析与大模型,结构化生成修复建议。
- 迭代提示工程+RAG增强准确性,问题减少超60%。
- 适合研发团队快速提升代码质量,减少人工审阅。
本研究通过将大型语言模型(如 OpenAI GPT-3.5 Turbo 与 GPT-4o)融入软件开发流程,探索代码问题检测与自动化修复。构建静态代码分析框架,在大规模项目中识别漏洞、缺陷与代码异味。提取每项问题的详细信息并结构化,用于指导大模型进行自动修复。采用迭代式提示工程确保输出准确且符合项目需求。引入检索增强生成(RAG)机制,使模型能调用实时外部知识,提升修复相关性与精度。针对大模型幻觉问题,设计自研“代码对比工具”,在应用前识别并纠正错误修改。后续静态扫描显示代码问题显著减少,验证了结合大模型、静态分析与RAG可有效提升代码质量,简化开发流程,节省时间与资源。
原文摘要 · Abstract (English)
This study examined code issue detection and revision automation by integrating Large Language Models (LLMs) such as OpenAI's GPT-3.5 Turbo and GPT-4o into software development workflows. A static code analysis framework detects issues such as bugs, vulnerabilities, and code smells within a large-scale software project. Detailed information on each issue was extracted and organized to facilitate automated code revision using LLMs. An iterative prompt engineering process is applied to ensure that prompts are structured to produce accurate and organized outputs aligned with the project requirements. Retrieval-augmented generation (RAG) is implemented to enhance the relevance and precision of the revisions, enabling LLM to access and integrate real-time external knowledge. The issue of LLM hallucinations - where the model generates plausible but incorrect outputs - is addressed by a custom-built "Code Comparison App," which identifies and corrects erroneous changes before applying them to the codebase. Subsequent scans using the static code analysis framework revealed a significant reduction in code issues, demonstrating the effectiveness of combining LLMs, static analysis, and RAG to improve code quality, streamline the software development process, and reduce time and resource expenditure.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。