A Learning-Based Approach to Static Program Slicing
Open Access
- 29 April 2024
- journal article
- research article
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Programming Languages
- Vol. 8 (OOPSLA1) , 83-109
Abstract
Traditional program slicing techniques are crucial for early bug detection and manual/automated debugging of online code snippets. Nevertheless, their inability to handle incomplete code hinders their real-world applicability in such scenarios. To overcome these challenges, we present NS-Slicer, a novel learning-based approach that predicts static program slices for both complete and partial code Our tool leverages a pre-trained language model to exploit its understanding of fine-grained variable-statement dependencies within source code. With this knowledge, given a variable at a specific location and a statement in a code snippet, NS-Slicer determines whether the statement belongs to the backward slice or forward slice, respectively. We conducted a series of experiments to evaluate NS-Slicer's performance. On complete code, it predicts the backward and forward slices with an F1-score of 97.41% and 95.82%, respectively, while achieving an overall F1-score of 96.77%. Notably, in 85.20% of the cases, the static program slices predicted by NS-Slicer exactly match entire slices from the oracle. For partial programs, it achieved an F1-score of 96.77%–97.49% for backward slicing, 92.14%–95.40% for forward slicing, and an overall F1-score of 94.66%–96.62%. Furthermore, we demonstrate NS-Slicer's utility in vulnerability detection (VD), integrating its predicted slices into an automated VD tool. In this setup, the tool detected vulnerabilities in Java code with a high F1-score of 73.38%. We also include the analyses studying NS-Slicer’s promising performance and limitations, providing insights into its understanding of intrinsic code properties such as variable aliasing, leading to better slicing.Keywords
Funding Information
- National Science Foundation (CNS-2120386)
- National Security Agency (NCAE-C-002-2021)
This publication has 28 references indexed in Scilit:
- A Program Slicer for Java (Tool Paper)2022
- An Empirical Study of C++ Vulnerabilities in Crowd-Sourced Code ExamplesIEEE Transactions on Software Engineering, 2020
- Toxic Code Snippets on Stack OverflowIEEE Transactions on Software Engineering, 2019
- Client-side web application slicing2011
- Using Static Analysis to Find BugsIEEE Software, 2008
- A Survey of Empirical Results on Program Slicing2004
- An overview of program slicingSoftware Focus, 2001
- Slicing Software for Model ConstructionHigher-Order and Symbolic Computation, 2000
- Program Slicing1996
- Dynamic program slicingInformation Processing Letters, 1988