This patch adds the CloneDetector class which allows searching source code for clones. For every statement or group of statements within a compound statement, CloneDetector computes a hash value, and finds clones by detecting identical hash values. This initial patch only provides a simple hashing mechanism that hashes the kind of each sub-statement. This patch also adds CloneChecker - a simple static analyzer checker that uses CloneDetector to report copy-pasted code. Patch by Raphael Isemann! Differential Revision: https://reviews.llvm.org/D20795 llvm-svn: 276782
20 lines
423 B
C++
20 lines
423 B
C++
// RUN: %clang_cc1 -analyze -fblocks -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
|
|
|
|
// This tests if we search for clones in blocks.
|
|
|
|
void log();
|
|
|
|
auto BlockA = ^(int a, int b){ // expected-warning{{Detected code clone.}}
|
|
log();
|
|
if (a > b)
|
|
return a;
|
|
return b;
|
|
};
|
|
|
|
auto BlockB = ^(int a, int b){ // expected-note{{Related code clone is here.}}
|
|
log();
|
|
if (a > b)
|
|
return a;
|
|
return b;
|
|
};
|