Skip to main content
QUICK REVIEW

[论文解读] SkipAnalyzer: A Tool for Static Code Analysis with Large Language Models

Mohammad Mahdi Mohajer, Reem Aleithan|arXiv (Cornell University)|Oct 27, 2023
Software Engineering Research被引用 4
一句话总结

SkipAnalyzer 是一款基于大语言模型的工具,通过使用 ChatGPT 自动化静态代码分析,实现缺陷检测、误报过滤以及生成语法正确的补丁。其在检测资源泄漏缺陷方面准确率达 76.95%,在生成正确补丁方面成功率高达 97.30%,显著优于基线工具 Infer,精度和修复准确率均更优。

ABSTRACT

We introduce SkipAnalyzer, a large language model (LLM)-powered tool for static code analysis. SkipAnalyzer has three components: 1) an LLM-based static bug detector that scans source code and reports specific types of bugs, 2) an LLM-based false-positive filter that can identify false-positive bugs in the results of static bug detectors (e.g., the result of step 1) to improve detection accuracy, and 3) an LLM-based patch generator that can generate patches for the detected bugs above. As a proof-of-concept, SkipAnalyzer is built on ChatGPT, which has exhibited outstanding performance in various software engineering tasks. To evaluate SkipAnalyzer, we focus on two types of typical and critical bugs that are targeted by static bug detection, i.e., Null Dereference and Resource Leak as subjects. We employ Infer to aid the gathering of these two bug types from 10 open-source projects. Consequently, our experiment dataset contains 222 instances of Null Dereference bugs and 46 instances of Resource Leak bugs. Our study demonstrates that SkipAnalyzer achieves remarkable performance in the mentioned static analysis tasks, including bug detection, false-positive warning removal, and bug repair. In static bug detection, SkipAnalyzer achieves accuracy values of up to 68.37% for detecting Null Dereference bugs and 76.95% for detecting Resource Leak bugs, improving the precision of the current leading bug detector, Infer, by 12.86% and 43.13%, respectively. For removing false-positive warnings, SkipAnalyzer can reach a precision of up to 93.88% for Null Dereference bugs and 63.33% for Resource Leak bugs. Additionally, SkipAnalyzer surpasses state-of-the-art false-positive warning removal tools. Furthermore, in bug repair, SkipAnalyzer can generate syntactically correct patches to fix its detected bugs with a success rate of up to 97.30%.

研究动机与目标

  • 开发一种端到端的、基于大语言模型的工具,实现无需人工干预的自动化静态代码分析。
  • 解决像 Infer 这类静态缺陷检测工具中误报率过高的问题,此类问题需要耗费大量人力进行验证。
  • 通过集成基于大语言模型的检测、过滤和修复组件,提升静态分析的精度和准确性。
  • 评估大语言模型在真实软件工程任务(如缺陷检测和补丁生成)中的有效性。
  • 证明大语言模型在关键指标(如精度和修复成功率)上可超越传统静态分析工具。

提出的方法

  • SkipAnalyzer 采用三个基于大语言模型的组件:静态缺陷检测器、误报过滤器和补丁生成器,每个组件均使用微调后的提示词。
  • 利用 OpenAI 的 ChatGPT-3.5 Turbo 和 ChatGPT-4 模型,结合零样本、单样本和少样本提示策略,以提升性能。
  • 该工具使用 Infer 在 10 个开源 Java 项目中识别并标注了 222 个空指针解引用缺陷和 46 个资源泄漏缺陷,构建了标注数据集。
  • 通过提示工程最大化模型性能,为每个分析组件量身定制上下文感知和任务特定的提示词。
  • 系统对模型输出进行语法正确性和语义准确性评估,确保生成的补丁有效且可执行。
  • 性能通过检测、过滤和修复任务的精度、准确率和成功率进行衡量。

实验结果

研究问题

  • RQ1基于大语言模型的系统(如 SkipAnalyzer)是否能在检测空指针解引用和资源泄漏缺陷方面超越传统静态分析工具(如 Infer)?
  • RQ2大语言模型在多大程度上能减少静态代码分析中的误报,特别是当用于过滤现有工具的输出时?
  • RQ3大语言模型能否以高成功率生成语法正确且语义有效的补丁?
  • RQ4不同的提示策略(零样本、单样本、少样本)如何影响大语言模型在静态分析任务中的性能?
  • RQ5SkipAnalyzer 的性能是否能在多样化的开源项目和缺陷类型上保持泛化能力?

主要发现

  • SkipAnalyzer 在空指针解引用缺陷检测中准确率达 68.37%,在资源泄漏缺陷检测中准确率达 76.95%,分别较 Infer 提升了 12.86% 和 43.13% 的精度。
  • 误报过滤器在空指针解引用缺陷上的精度为 93.88%,在资源泄漏缺陷上的精度为 63.33%,优于现有基线工具。
  • 补丁生成器在空指针解引用缺陷上成功生成正确补丁的比例达 97.30%,在资源泄漏缺陷上为 91.77%。
  • 所有生成补丁中 98.77% 具备语法正确性,表明代码生成具有高度可靠性。
  • 误报过滤器使 SkipAnalyzer 自身检测器在空指针解引用缺陷上的精度提升了 16.31%,体现了系统内部的一致性。
  • SkipAnalyzer 在误报移除方面优于最先进工具,相较于 Infer,空指针解引用缺陷的精度提升了 28.68%。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。