Nuanced Code Clone Detection Through LLM-Based Code Revision and AST Graph Modeling
Detecting semantically equivalent but syntactically diverse code clones (Type-4) remains challenging for traditional AST- or token-based approaches. We propose a clone detection framework that couples <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">LLM-based code revision</i> with <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">AST graph modeling</i> and <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">Graph Attention Networks</i> (GAT), trained via a joint objective that includes a contrastive loss to align embeddings of semantically equivalent fragments. Concretely, we use an LLM to generate syntactically altered but functionally identical variants, thereby augmenting training data with <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">nuanced code clones</i>—subtle edits such as identifier renaming, control-flow restructuring, or statement reordering that preserve program behavior while confusing purely syntactic matchers. On Google Code Jam (GCJ), the proposed method attains Precision 0.99, Recall 0.98, and F1 0.985, outperforming the strongest baseline (F1 = 0.97) by +1.5 percentage points (relative ≈ +1.6%). On BigCloneBench, it achieves Precision 0.97, Recall 0.96, and F1 0.97, improving over the best baseline (F1 = 0.93) by +4.0 pp (relative ≈ +4.3%). For the hardest WT3/T4 category, the framework reaches F1 97.4 versus 93.6 for a strong GNN baseline (+3.8 pp). Ablations indicate that (i) LLM-based augmentation and (ii) GAT-based AST encoding are both critical to performance. In addition to accuracy, we discuss computational considerations (augmentation/training cost), portability beyond Java, and potential extensions toward dynamic clone detection. The results suggest that marrying LLM-generated <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">nuanced</i> variants with graph-based program representations yields robust Type-4 clone detection while remaining scalable to practical codebases.
Authors
- Jessada Konpang (ORCID: https://orcid.org/0000-0002-7199-6402)
- Chunguang Li (ORCID: https://orcid.org/0009-0007-4707-8832)
- Shilong Wang (ORCID: https://orcid.org/0000-0001-6086-0481)
- Adisorn Sirikham (ORCID: https://orcid.org/0009-0008-5537-7995)
Institutions
- Rajamangala University of Technology Krungthep (TH)
- College of Accounting (SI)
Publication Details
- Journal
- IEEE Access
- Published
- 2025-01-01
- DOI
- https://doi.org/10.1109/access.2025.3628856
- Citations
- 1
- Primary Topic
- Software Engineering Research
- Type
- article
- Field-Weighted Citation Impact
- 3.25