Program slicing is a critical technique in software engineering, enabling developers to isolate relevant portions of code for tasks such as bug detection, code comprehension, and debugging. In this study, we investigate the application of large language models (LLMs) to both static and dynamic program slicing, with a focus on Java programs. We evaluate the performance of four state-of-the-art LLMs- GPT-4o, GPT-3.5 Turbo, Llama-2, and Gemma-7B leveraging advanced prompting techniques, including few-shot learning and chain-of-thought reasoning. Using a dataset of 100 Java programs derived from LeetCode problems, our experiments reveal that GPT-4o performs the best in both static and dynamic slicing across other LLMs, achieving an accuracy of 60.84% and 59.69%, respectively. Our results also show that the LLMs we experimented with are yet to achieve reasonable performance for either static slicing or dynamic slicing. Through a rigorous manual analysis, we developed a taxonomy of root causes and failure locations to explore the unsuccessful cases in more depth. We identified Complex Control Flow as the most frequent root cause of failures, with the majority of issues occurring in Variable Declarations and Assignments locations. To improve the performance of LLMs, we further examined two independent strategies for prompting guided by our taxonomy, including prompt crafting, which involved refining the prompts to better guide the LLM through the slicing process, and iterative prompting, where the model receives feedback on the root cause and location of the failure and re-generates its responses. Our evaluation shows these two prompting enhancement approaches can improve accuracy by 4% and 3.9%, respectively.
Enhancing LLM-based Specification Generation via Program Slicing and Logical Deletion
School of Computer Science and Technology, Xidian University(西安电子科技大学计算机科学与技术学院);National Key Laboratory of Science and Technology on Information System Security, AMS(信息系统安全国家重点实验室(AMS));Unit 32092 of PLA(中国人民解放军32092部队);School of Cyber Engineering, Xidian University(西安电子科技大学网络空间安全学院);Systems Engineering Institute, AMS(系统工程研究院(AMS))
程序切片是一种通过关注程序行为的选定方面来简化程序的技术。当前主流的静态切片方法在PDG(程序依赖图)或SDG(系统依赖图)上操作,但是这些友好的图表示对于一些用户来说可能是昂贵的并且容易出错。在本文中,我们试图研究一个轻量级的静态程序切片的方法,称为符号程序切片(Symbolic Program Slicing,SymbolPas),它的工作原理是对LLVM(低级虚拟机)的一个简单的分析。在我们的SymPas方法中,切片是符号化存储的,而不是重新分析的过程(参见。程序摘要)。SymPas不是多次重新分析过程以找到每个调用上下文的切片,而是计算单个符号(或参数化)切片,该切片可以在调用站点实例化,避免重新分析;它在LLVM中实现以对其中间表示(IR)执行切片。为了比较,我们系统地适应IFDS(过程间有限分布子集)分析和基于SDG的切片方法(SDG-IFDS)静态IR切片程序。在开源和基准程序上进行评估,与后向SDG-IFDS相比,我们的后向SymPas显示出时间成本降低了6倍,空间成本降低了4倍,因此更高效。此外,结果表明,在研究了66个程序的切片后,大小范围高达336,800条IR指令,SymPas具有高度的大小可伸缩性。
Static Program Slicing Using Language Models With Dataflow-Aware Pretraining and Constrained Decoding
Department of Computer Science, University of Manitoba(曼尼托巴大学计算机科学系);School of Engineering and Computer Science, Concordia University(Concordia大学工程与计算机科学学院);School of Computer Science, University of Windsor(温莎大学计算机科学学院)
Renaissance of Literate Programming in the Era of LLMs: Enhancing LLM-Based Code Generation in Large-Scale Projects
University of Illinois Chicago(伊利诺伊大学芝加哥分校);Stony Brook University(石溪大学);Rutgers University(罗格斯大学);John Hopkins University(约翰霍普金斯大学);The Chinese University of Hong Kong, Shenzhen(香港中文大学(深圳));Dali University(大理大学)