diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2016-10-03 08:11:50 +0000 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2016-10-03 08:11:50 +0000 |
commit | 071811a24c7d1f5a3c798d1a3455a312adc1bb82 (patch) | |
tree | 4ee401276932d57fdba02657494698c2c9c78e7d /test/Analysis/copypaste/suspicious-clones.cpp | |
parent | 23eb5dbf9c59b3422a9484c752e07f588402223a (diff) |
[analyzer] Improve CloneChecker diagnostics
Highlight code clones referenced by the warning message with the help of
the extra notes feature recently introduced in r283092.
Change warning text to more clang-ish. Remove suggestions from the copy-paste
error checker diagnostics, because currently our suggestions are strictly 50%
wrong (we do not know which of the two code clones contains the error), and
for that reason we should not sound as if we're actually suggesting this.
Hopefully a better solution would bring them back.
Make sure the suspicious clone pair structure always mentions
the correct variable for the second clone.
Differential Revision: https://reviews.llvm.org/D24916
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283094 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/copypaste/suspicious-clones.cpp')
-rw-r--r-- | test/Analysis/copypaste/suspicious-clones.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/test/Analysis/copypaste/suspicious-clones.cpp b/test/Analysis/copypaste/suspicious-clones.cpp index fb22d38c85..c64a1dc8b8 100644 --- a/test/Analysis/copypaste/suspicious-clones.cpp +++ b/test/Analysis/copypaste/suspicious-clones.cpp @@ -8,14 +8,14 @@ int max(int a, int b) { log(); if (a > b) return a; - return b; // expected-note{{suggestion is based on the usage of this variable in a similar piece of code}} + return b; // expected-note{{Similar code using 'b' here}} } int maxClone(int x, int y, int z) { log(); if (x > y) return x; - return z; // expected-warning{{suspicious code clone detected; did you mean to use 'y'?}} + return z; // expected-warning{{Potential copy-paste error; did you really mean to use 'z' here?}} } // Tests finding a suspicious clone that references global variables. @@ -33,7 +33,7 @@ void busyIncrement() { while (true) { if (m1.try_lock()) { ++i; - m1.unlock(); // expected-note{{suggestion is based on the usage of this variable in a similar piece of code}} + m1.unlock(); // expected-note{{Similar code using 'm1' here}} if (i > 1000) { return; } @@ -45,7 +45,7 @@ void faultyBusyIncrement() { while (true) { if (m1.try_lock()) { ++i; - m2.unlock(); // expected-warning{{suspicious code clone detected; did you mean to use 'm1'?}} + m2.unlock(); // expected-warning{{Potential copy-paste error; did you really mean to use 'm2' here?}} if (i > 1000) { return; } @@ -58,14 +58,14 @@ void faultyBusyIncrement() { int foo(int a, int b, int c) { a += b + c; b /= a + b; - c -= b * a; // expected-warning{{suspicious code clone detected; did you mean to use 'a'?}} + c -= b * a; // expected-warning{{Potential copy-paste error; did you really mean to use 'b' here?}} return c; } int fooClone(int a, int b, int c) { a += b + c; b /= a + b; - c -= a * a; // expected-note{{suggestion is based on the usage of this variable in a similar piece of code; did you mean to use 'b'?}} + c -= a * a; // expected-note{{Similar code using 'a' here}} return c; } @@ -77,21 +77,21 @@ int fooClone(int a, int b, int c) { long bar1(long a, long b, long c, long d) { c = a - b; c = c / d * a; - d = b * b - c; // expected-warning{{suspicious code clone detected; did you mean to use 'c'?}} + d = b * b - c; // expected-warning{{Potential copy-paste error; did you really mean to use 'b' here?}} return d; } long bar2(long a, long b, long c, long d) { c = a - b; c = c / d * a; - d = c * b - c; // expected-note{{suggestion is based on the usage of this variable in a similar piece of code; did you mean to use 'b'?}} \ - // expected-warning{{suspicious code clone detected; did you mean to use 'a'?}} + d = c * b - c; // expected-note{{Similar code using 'c' here}} \ + // expected-warning{{Potential copy-paste error; did you really mean to use 'c' here?}} return d; } long bar3(long a, long b, long c, long d) { c = a - b; c = c / d * a; - d = a * b - c; // expected-note{{suggestion is based on the usage of this variable in a similar piece of code; did you mean to use 'c'?}} + d = a * b - c; // expected-note{{Similar code using 'a' here}} return d; } |