diff options
| author | Artem Dergachev <artem.dergachev@gmail.com> | 2016-08-04 19:37:00 +0000 |
|---|---|---|
| committer | Artem Dergachev <artem.dergachev@gmail.com> | 2016-08-04 19:37:00 +0000 |
| commit | 7a0088bbae10f867a842b02d3e49047b3c350d35 (patch) | |
| tree | f3d5583185fb439e8e1b2b09cecfc4149c926ffe /clang/test | |
| parent | c8acb4f37b95b1eb7b633c9ccf7c42ea54531297 (diff) | |
| download | bcm5719-llvm-7a0088bbae10f867a842b02d3e49047b3c350d35.tar.gz bcm5719-llvm-7a0088bbae10f867a842b02d3e49047b3c350d35.zip | |
[analyzer] Make CloneDetector recognize different variable patterns.
CloneDetector should be able to detect clones with renamed variables.
However, if variables are referenced multiple times around the code sample,
the usage patterns need to be recognized.
For example, (x < y ? y : x) and (y < x ? y : x) are no longer clones,
however (a < b ? b : a) is still a clone of the former.
Variable patterns are computed and compared during a separate filtering pass.
Patch by Raphael Isemann!
Differential Revision: https://reviews.llvm.org/D22982
llvm-svn: 277757
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Analysis/copypaste/false-positives.cpp | 21 | ||||
| -rw-r--r-- | clang/test/Analysis/copypaste/functions.cpp | 10 |
2 files changed, 9 insertions, 22 deletions
diff --git a/clang/test/Analysis/copypaste/false-positives.cpp b/clang/test/Analysis/copypaste/false-positives.cpp deleted file mode 100644 index 4c6275949da..00000000000 --- a/clang/test/Analysis/copypaste/false-positives.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s - -// This test contains false-positive reports from the CloneChecker that need to -// be fixed. - -void log(); - -int max(int a, int b) { // expected-warning{{Detected code clone.}} - log(); - if (a > b) - return a; - return b; -} - -// FIXME: Detect different variable patterns. -int min2(int a, int b) { // expected-note{{Related code clone is here.}} - log(); - if (b > a) - return a; - return b; -} diff --git a/clang/test/Analysis/copypaste/functions.cpp b/clang/test/Analysis/copypaste/functions.cpp index bedd374b79d..2a871f74b03 100644 --- a/clang/test/Analysis/copypaste/functions.cpp +++ b/clang/test/Analysis/copypaste/functions.cpp @@ -37,7 +37,7 @@ int testBaseClass2(int a, int b) { // no-warning return b; } - +// No clone because of the different comparison operator. int min1(int a, int b) { // no-warning log(); if (a < b) @@ -45,6 +45,14 @@ int min1(int a, int b) { // no-warning return b; } +// No clone because of the different pattern in which the variables are used. +int min2(int a, int b) { // no-warning + log(); + if (a > b) + return b; + return a; +} + int foo(int a, int b) { // no-warning return a + b; } |

