随着软件剽窃和代码克隆现象的不断增加,对相似代码段的有效检测变得至关重要,特别是涉及语义相似克隆的代码克隆检测,对于推动研究进展和维护知识产权具有重要意义。语义相似克隆的特征涉及功能和语义的相似性,相较于句法相似性,这种相似性更难检测。为解决这一问题,提出了一种新颖的检测方法,采用程序依赖图而非抽象语法树,以更有效地表达代码的语义信息;通过引入图注意网络,从程序依赖图中提取出关键的语义特征,并最终计算出两段代码之间的功能相似性。实验证明,提出的基于程序依赖图和图注意网络的方法在语义相似克隆的检测方面明显优于当前已有的方法。
With the escalating prevalence of software plagiarism and code cloning incidents, the efficient detection of similar code segments has become increasingly vital, particularly in the context of semantic similarity-based code clone detection, which holds significant implications for advancing research and safeguarding intellectual property rights. Semantic similarity clones, characterized by their shared functionality and semantic underpinnings, pose a greater challenge to detection than syntactic similarities. To address this issue, this paper proposes an innovative detection approach that employs Program Dependency Graph(PDG) instead of Abstract Syntax Tree, thereby offering a more effective means of representing code's semantic information. By integrating Graph Attention Networks (GAT)into our method, it can extract salient semantic features from PDG and subsequently calculate the functional similarity between two pieces of codes. Experimental results demonstrate that the proposed method based on PDG and GAT significantly outperforms existing methods in detecting semantic similarity clones.
[1] KIM M, BERGMAN L, LAU T, et al. An ethnographic study of copy and paste programming practices in OOPL[C]//Proceedings. 2004 International Symposium on Empirical Software Engineering, 2004. ISESE'04. IEEE, 2004:83-92.
[2] BURD E, BAILEY J. Evaluating clone detection tools for use during preventative maintenance[C]//Proceedings. Second IEEE International Workshop on Source Code Analysis and Manipulation. IEEE, 2002:36-43.
[3] SVAJLENKO J, ISLAM J F, KEIVANLOO I, et al. Towards a big data curated benchmark of inter-project code clones[C]//2014 IEEE International Conference on Software Maintenance and Evolution. IEEE, 2014:476-480.
[4] BELLON S, KOSCHKE R, ANTONIOL G, et al. Comparison and evaluation of clone detection tools[J]. IEEE Transactions on Software Engineering, 2007,33(9):577-591.
[5] SAINI V, FARNAHINIFARAHANI F, LU Y, et al. Oreo: Detection of clones in the twilight zone[C]//Proceedings of the 2018 26th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering. 2018:354-365.
[6] WHITE M, TUFANO M, VENDOME C, et al. Deep learning code fragments for code clone detection[C]//Proceedings of the 31st IEEE/ACM International Conference on Automated Software Engineering. Singapore,ACM,2016:87-98.
[7] ZHANG J, WANG X, ZHANG H, et al. A novel neural source code representation based on abstract syntax tree[C]//2019 IEEE/ACM 41st International Conference on Software Engineering (ICSE). IEEE, 2019:783-794.
[8] JIANG L, MISHERGHI G, SU Z, et al. Deckard: Scalable and accurate tree-based detection of code clones[C]//29th International Conference on Software Engineering (ICSE'07). IEEE, 2007:96-105.
[9] WEI H, LI M. Supervised deep features for software functional clone detection by exploiting lexical and syntactical information in source code[C]//Proceedings of the Twenty-Sixth International Joint Conference on Artificial Intelligence. Melbourne, Australia. California: International Joint Conferences on Artificial Intelligence Organization, 2017:3034-3040.
[10] WANG W, LI G, MA B, et al. Detecting code clones with graph neural network and flow-augmented abstract syntax tree[C]//2020 IEEE 27th International Conference on Software Analysis, Evolution and Reengineering (SANER). IEEE, 2020:261-271.
[11] ALLAMANIS M, BROCKSCHMIDT M, KHADEMI M. Learning to represent programs with graphs[J].[EB/OL].(2018-05-04)[2023-06-08].http://arxiv.org/abs/1711.00740.
[12] SIOW J K, LIU S, XIE X, et al. Learning program semantics with code representations: An empirical study[C]//2022 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER). IEEE, 2022:554-565.
[13] KAUR M, RATTAN D. A systematic literature review on the use of machine learning in code clone research[J]. Computer Science Review, 2023,47:100528.
[14] ZHANG W, GUO S, ZHANG H, et al. Challenging machine learning-based clone detectors via semantic-preserving code transformations[J]. IEEE Transactions on Software Engineering, 2023,49(5):3052-3070.
[15] VELIČKOVIĆ P, CUCURULL G, Casanova A, et al. Graph attention networks[EB/OL]. (2018-02-04)[2023-06-08].http://arxiv.org/abs/1710.10903.
[16] XU K, LIU Y. SCCD-GAN: an enhanced semantic code clone detection model using GAN[C]//2021 IEEE 4th International Conference on Electronics and Communication Engineering (ICECE). IEEE, 2021:16-22.
[17] WANG M, WANG P, XU Y. CCSharp: An efficient three-phase code clone detector using modified PDGs[C]//2017 24th Asia-Pacific Software Engineering Conference (APSEC). IEEE, 2017:100-109.
[18] HORWITZ S, PRINS J, REPS T. On the adequacy of program dependence graphs for representing programs[C]//Proceedings of the 15th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. San Diego, California, USA. ACM, 1988:146-157.