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 // Tests finding a suspicious clone that references global variables.
35 void busyIncrement() {
39 m1
.unlock(); // expected-note{{Similar code using 'm1' here}}
47 void faultyBusyIncrement() {
51 m2
.unlock(); // expected-warning{{Potential copy-paste error; did you really mean to use 'm2' here?}}
59 // Tests that we provide two suggestions in cases where two fixes are possible.
61 int foo(int a
, int b
, int c
) {
64 c
-= b
* a
; // expected-warning{{Potential copy-paste error; did you really mean to use 'b' here?}}
68 int fooClone(int a
, int b
, int c
) {
71 c
-= a
* a
; // expected-note{{Similar code using 'a' here}}
76 // Tests that for clone groups with a many possible suspicious clone pairs, at
77 // most one warning per clone group is generated and every relevant clone is
78 // reported through either a warning or a note.
80 long bar1(long a
, long b
, long c
, long d
) {
83 d
= b
* b
- c
; // expected-warning{{Potential copy-paste error; did you really mean to use 'b' here?}}
87 long bar2(long a
, long b
, long c
, long d
) {
90 d
= c
* b
- c
; // expected-note{{Similar code using 'c' here}} \
91 // expected-warning{{Potential copy-paste error; did you really mean to use 'c' here?}}
95 long bar3(long a
, long b
, long c
, long d
) {
98 d
= a
* b
- c
; // expected-note{{Similar code using 'a' here}}