大型語言模型生成程式碼的驗證框架

A Verification Framework for LLM-Generated Code

檔案

全文將於 2030年8月16日 起公開。

日期

2025

類型

語言

中文

摘要

利用大型語言模型進行自動化程式碼生成的發展和應用,在科技產業中已經取得
了顯著的進展。在技術上,像 OpenAI 的 GPT 系列這樣的大型語言模型已能提供準確
且具有上下文意識的程式碼生成能力。然而,在實際應用中,要將這些模型生成的程
式碼片段整合至原有軟體專案中,常會遭遇語法不一致或潛在安全漏洞的問題。
本研究建立了一套綜合性的程式碼驗證框架,針對 LLM 生成的 C/C++程式碼進
行多維度分析。首先使用 Clang Static Analyzer 進行靜態程式碼分析,透過單元測試
驗證功能正確性,並利用 Valgrind 檢測運行時的記憶體錯誤。進一步開發 C++到 Dafny
的自動轉換系統,將傳統程式碼轉換為可進行形式驗證的格式,以檢測語意層面的邏
輯錯誤。
透過整合傳統軟體測試方法與現代形式驗證技術,本研究提供了從語法正確性到
語意一致性的完整程式碼驗證流程。實驗結果顯示該框架能夠有效識別 LLM 生成程
式碼中的各類問題,包括功能錯誤、記憶體安全問題,為 LLM 輔助程式開發提供可
靠的驗證機制。
The development and application of automated code generation using large
language models has achieved significant progress in the technology industry. Technically,
large language models such as OpenAI's GPT series are already capable of providing
accurate and context-aware code generation capabilities. However, in practical
applications, integrating code snippets generated by these models into existing software
projects often encounters issues such as syntax inconsistencies, semantic discontinuities, or
potential security vulnerabilities.
This research establishes a comprehensive code quality verification framework for
multi-dimensional analysis of C/C++ code generated by LLMs. First, functional
correctness is verified through unit testing, static code analysis is performed using Clang
Static Analyzer, and runtime memory errors are detected using Valgrind. Furthermore, an
automatic conversion system from C++ to Dafny is developed to transform traditional code
into a format suitable for formal verification, enabling detection of semantic-level logical
errors.
By integrating traditional software testing methods with modern formal verification
techniques, this research provides a complete code quality assurance process from syntactic
correctness to semantic consistency. Experimental results demonstrate that this framework
can effectively identify various types of issues in LLM-generated code, including functional
errors, memory safety problems, providing a reliable quality assurance mechanism for LLM-
iii
assisted program development.
顯示完整詮釋資料 統計資料

引用此條目

黃秉為 (2025). 大型語言模型生成程式碼的驗證框架. https://thesis.lib.nycu.edu.tw/handle/20.500.14371/86404

BibTeX RIS

引用文字依 APA 第 7 版格式自動產生,使用前請再核對。

分享

永久網址:https://thesis.lib.nycu.edu.tw/handle/20.500.14371/86404