Tool Demonstration: Finding Duplicated Code Using Program Dependences

  • Raghavan Komondoor
  • Susan Horwitz
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 2028)


The results of several studies [1,7,8] indicate that 7-23% of the source code for large programs is duplicated code. Duplication makes programs harder to maintain because when enhancements or bug fixes are made in one instance of the duplicated code, it is necessary to search for the other instances in order to perform the corresponding modification.

A tool that finds clones (instances of duplicated code) can help to alleviate this problem. When code is modified, the tool can be used to find the other copies that also need modification. Alternatively, the clones identified by the tool can be extracted into a new procedure, and the clones themselves replaced by calls to that procedure. In that case, there is only one copy to maintain (the new procedure), and the fact that the procedure can be reused may cut down on future duplication.

We have designed and implemented a tool for C programs that finds clones and displays them to the programmer. To find clones in a program, we represent each procedure using its program dependence graph (PDG) [6]. In the PDG, nodes represent program statements and predicates, and edges represent data and control dependences. To find a pair of clones we use a variation on backward slicing [11,10].


Isomorphic Subgraph Ideal Clone Clone Group Control Dependence Clone Detection 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. 1.
    B. Baker. On finding duplication and near-duplication in large software systems. In Proc. IEEE Working Conf. on Reverse Eng., pages 86–95, July 1995.Google Scholar
  2. 2.
    B. Baker. Parameterized duplication in strings: Algorithms and an application to software maint. SIAM Jrnl. of Computing, 26(5):1343–1362, Oct. 1997.zbMATHCrossRefGoogle Scholar
  3. 3.
    I. Baxter, A. Yahin, L. Moura, M. Sant’Anna, and L. Bier. Clone detection using abstract syntax trees. In Int. Conf. on Software Maint., pages 368–378, 1998.Google Scholar
  4. 4.
    N. Davey, P. Barson, S. Field, R. Frank, and D. Tansley. The development of a software clone detector. Int. Jrnl. of Applied Software Tech., 1(3-4):219–36, 1995.Google Scholar
  5. 5.
    S. Debray, W. Evans, R. Muth, and B. D. Sutter. Compiler techniques for code compaction. ACM Trans. on Prog. Lang. and Sys., 22(2):378–415, Mar. 2000.CrossRefGoogle Scholar
  6. 6.
    J. Ferrante, K. Ottenstein, and J. Warren. The program dependence graph and its use in optimization. ACM Trans. on Prog. Lang. and Sys., 9(3):319–349, July 1987.zbMATHCrossRefGoogle Scholar
  7. 7.
    K. Kontogiannis, R. Demori, E. Merlo, M. Galler, and M. Bernstein. Pattern matching for clone and concept detection. Automated Software Eng., 3(1-2):77–108, 1996.MathSciNetGoogle Scholar
  8. 8.
    B. Lague, D. Proulx, J. Mayrand, E. Merlo, and J. Hudepohl. Assessing the benefits of incorporating function clone detection in a development process. In Int. Conf. on Software Maint., pages 314–321, 1997.Google Scholar
  9. 9.
    J. Mayrand, C. Leblanc, and E. Merlo. Experiment on the automatic detection of function clones in a software system using metrics. In Proc. of the Int. Conf. on Software Maint., pages 244–254, 1996.Google Scholar
  10. 10.
    K. Ottenstein and L. Ottenstein. The program dependence graph in a software development environment. In Proc. ACM SIGSOFT/SIGPLAN Software Eng. Symp. on Practical Software Development Environments, pages 177–184, 1984.Google Scholar
  11. 11.
    M. Weiser. Program slicing. IEEE Trans. on Software Eng., SE-10(4):352–357, July 1984.CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2001

Authors and Affiliations

  • Raghavan Komondoor
    • 1
  • Susan Horwitz
    • 1
  1. 1.Computer Sciences DepartmentUniversity of Wisconsin-MadisonWisconsin-Madison

Personalised recommendations