[Paper Review] Detecting Code Clones with Graph Neural Networkand Flow-Augmented Abstract Syntax Tree
This paper introduces FA-AST, a flow-augmented AST graph representation, and applies GGNN and GMN graph neural networks to detect semantic code clones, achieving state-of-the-art results on GCJ and BigCloneBench datasets.
Code clones are semantically similar code fragments pairs that are syntactically similar or different. Detection of code clones can help to reduce the cost of software maintenance and prevent bugs. Numerous approaches of detecting code clones have been proposed previously, but most of them focus on detecting syntactic clones and do not work well on semantic clones with different syntactic features. To detect semantic clones, researchers have tried to adopt deep learning for code clone detection to automatically learn latent semantic features from data. Especially, to leverage grammar information, several approaches used abstract syntax trees (AST) as input and achieved significant progress on code clone benchmarks in various programming languages. However, these AST-based approaches still can not fully leverage the structural information of code fragments, especially semantic information such as control flow and data flow. To leverage control and data flow information, in this paper, we build a graph representation of programs called flow-augmented abstract syntax tree (FA-AST). We construct FA-AST by augmenting original ASTs with explicit control and data flow edges. Then we apply two different types of graph neural networks (GNN) on FA-AST to measure the similarity of code pairs. As far as we have concerned, we are the first to apply graph neural networks on the domain of code clone detection. We apply our FA-AST and graph neural networks on two Java datasets: Google Code Jam and BigCloneBench. Our approach outperforms the state-of-the-art approaches on both Google Code Jam and BigCloneBench tasks.
Motivation & Objective
- Motivate the challenge of detecting semantic (type-4) code clones beyond syntactic similarity.
- Propose a graph-based representation (FA-AST) that encodes syntax, control flow, and data flow.
- Develop and compare two GNN models (GGNN and GMN) for code clone detection.
- Evaluate on two Java datasets (Google Code Jam and BigCloneBench) and show improved performance over AST-based baselines.
Proposed method
- Construct FA-AST by augmenting ASTs with control flow edges (If, While, For) and data flow cues (NextUse, NextToken).
- Represent programs as graphs and apply GGNN to learn graph embeddings with MLP-based message and GRU-based updates.
- Apply GMN to jointly learn embeddings for code pairs with cross-graph attention mechanisms, using a readout similar to GGNN for graph-level vectors.
- Train with MSE loss on similarity predictions and use cosine similarity of graph embeddings for clone decision.
- Compare against baselines (DECKARD, RtvNN, CDLH, ASTNN) on GCJ and BigCloneBench, tuning a threshold on validation data.
Experimental results
Research questions
- RQ1Can FA-AST effectively encode both syntactic structure and semantic flow information for code fragments?
- RQ2Do graph neural networks (GGNN and GMN) outperform AST-based deep learning approaches for code clone detection?
- RQ3Is cross-graph attention in GMN beneficial for detecting semantic clones across code pairs?
- RQ4How does the proposed method perform on type-4/semantic clones across different datasets (GCJ and BigCloneBench)?
Key findings
- FA-AST+GMN achieves precision 0.99, recall 0.97, and F1 0.98 on Google Code Jam, outperforming ASTNN and other baselines.
- FA-AST+GGNN achieves precision 0.96, recall 1.0, and F1 0.97 on Google Code Jam, better than most baselines but slightly below GMN.
- On BigCloneBench, FA-AST+GMN attains precision 0.96, recall 0.94, and F1 0.95, surpassing ASTNN and other baselines.
- GMN models generally outperform GGNN models, indicating cross-graph attention improves clone detection performance.
- FA-AST+GMN demonstrates strong performance for semantic (WT3/T4) clones, outperforming ASTNN on these harder cases.
Better researchstarts right now
From reading papers to final review, dramatically reduce your research time.
No credit card · Free plan available
This review was created by AI and reviewed by human editors.