LLMDFA:利用大型语言模型分析代码中的数据流
LLMDFA: Analyzing Dataflow in Code with Large Language Models
AI总结:
本文提出LLMDFA框架,利用LLM结合外部解析工具和定理证明器实现无需编译的可定制数据流分析,在合成程序与Android应用中检测错误时F1分数最高提升0.35。
摘要:
数据流分析是一种基础代码分析技术,用于识别程序值之间的依赖关系。传统方法通常需要成功编译和专家定制,这阻碍了它们在现实场景中分析无法编译的程序以及应对不断演变的分析需求时的适用性和可用性。本文提出了LLMDFA,一个由LLM驱动、无需编译且可定制的数据流分析框架。为了解决幻觉问题以获得可靠结果,我们将问题分解为若干子任务,并引入一系列新颖策略。具体而言,我们利用LLM合成代码,将精细推理外包给外部专家工具,例如使用解析库提取感兴趣的程序值,并调用自动定理证明器验证路径可行性。此外,我们采用少样本思维链提示来总结单个函数中的数据流事实,使LLM与小程序片段的程序语义对齐,以缓解幻觉。我们在合成程序上评估LLMDFA以检测三种代表性错误类型,并在真实世界Android应用程序上进行定制化错误检测。平均而言,LLMDFA达到87.10%的精确率和80.77%的召回率,超越现有技术,F1分数提升最高达0.35。我们已在https://github.com/chengpeng-wang/LLMDFA开源LLMDFA。
英文摘要:
Dataflow analysis is a fundamental code analysis technique that identifies dependencies between program values. Traditional approaches typically necessitate successful compilation and expert customization, hindering their applicability and usability for analyzing uncompilable programs with evolving analysis needs in real-world scenarios. This paper presents LLMDFA, an LLM-powered compilation-free and customizable dataflow analysis framework. To address hallucinations for reliable results, we decompose the problem into several subtasks and introduce a series of novel strategies. Specifically, we leverage LLMs to synthesize code that outsources delicate reasoning to external expert tools, such as using a parsing library to extract program values of interest and invoking an automated theorem prover to validate path feasibility. Additionally, we adopt a few-shot chain-of-thought prompting to summarize dataflow facts in individual functions, aligning the LLMs with the program semantics of small code snippets to mitigate hallucinations. We evaluate LLMDFA on synthetic programs to detect three representative types of bugs and on real-world Android applications for customized bug detection. On average, LLMDFA achieves 87.10% precision and 80.77% recall, surpassing existing techniques with F1 score improvements of up to 0.35. We have open-sourced LLMDFA at https://github.com/chengpeng-wang/LLMDFA.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。