1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN: -analyzer-checker=alpha.clone.CloneChecker \
3 // RUN: -analyzer-config alpha.clone.CloneChecker:ReportNormalClones=false \
4 // RUN: -analyzer-config alpha.clone.CloneChecker:MinimumCloneComplexity=10
6 // Tests finding a suspicious clone that references local variables.
10 int max(int a
, int b
) {
14 return b
; // expected-note{{Similar code using 'b' here}}
17 int maxClone(int x
, int y
, int z
) {
21 return z
; // expected-warning{{Potential copy-paste error; did you really mean to use 'z' here?}}
24 // Test that the checker works with [[clang::suppress]].
25 int max_suppressed(int a
, int b
) {
30 // This [[clang::suppress]] doesn't suppress anything but we need it here
31 // because otherwise the other function won't count as a perfect clone.
32 // FIXME: The checker should probably skip the attribute entirely
33 // when detecting clones. Otherwise warnings will still get suppressed,
34 // but for a completely wrong reason.
39 int maxClone_suppressed(int x
, int y
, int z
) {
44 return z
; // no-warning
48 // Tests finding a suspicious clone that references global variables.
59 void busyIncrement() {
63 m1
.unlock(); // expected-note{{Similar code using 'm1' here}}
71 void faultyBusyIncrement() {
75 m2
.unlock(); // expected-warning{{Potential copy-paste error; did you really mean to use 'm2' here?}}
83 // Tests that we provide two suggestions in cases where two fixes are possible.
85 int foo(int a
, int b
, int c
) {
88 c
-= b
* a
; // expected-warning{{Potential copy-paste error; did you really mean to use 'b' here?}}
92 int fooClone(int a
, int b
, int c
) {
95 c
-= a
* a
; // expected-note{{Similar code using 'a' here}}
100 // Tests that for clone groups with a many possible suspicious clone pairs, at
101 // most one warning per clone group is generated and every relevant clone is
102 // reported through either a warning or a note.
104 long bar1(long a
, long b
, long c
, long d
) {
107 d
= b
* b
- c
; // expected-warning{{Potential copy-paste error; did you really mean to use 'b' here?}}
111 long bar2(long a
, long b
, long c
, long d
) {
114 d
= c
* b
- c
; // expected-note{{Similar code using 'c' here}} \
115 // expected-warning{{Potential copy-paste error; did you really mean to use 'c' here?}}
119 long bar3(long a
, long b
, long c
, long d
) {
122 d
= a
* b
- c
; // expected-note{{Similar code using 'a' here}}