1 // RUN: %clang_cc1 -analyze -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:ReportSuspiciousClones=true -analyzer-config alpha.clone.CloneChecker:ReportNormalClones=false -verify %s
3 // Tests finding a suspicious clone that references local variables.
7 int max(int a, int b) {
11 return b; // expected-note{{Similar code using 'b' here}}
14 int maxClone(int x, int y, int z) {
18 return z; // expected-warning{{Potential copy-paste error; did you really mean to use 'z' here?}}
21 // Tests finding a suspicious clone that references global variables.
32 void busyIncrement() {
36 m1.unlock(); // expected-note{{Similar code using 'm1' here}}
44 void faultyBusyIncrement() {
48 m2.unlock(); // expected-warning{{Potential copy-paste error; did you really mean to use 'm2' here?}}
56 // Tests that we provide two suggestions in cases where two fixes are possible.
58 int foo(int a, int b, int c) {
61 c -= b * a; // expected-warning{{Potential copy-paste error; did you really mean to use 'b' here?}}
65 int fooClone(int a, int b, int c) {
68 c -= a * a; // expected-note{{Similar code using 'a' here}}
73 // Tests that for clone groups with a many possible suspicious clone pairs, at
74 // most one warning per clone group is generated and every relevant clone is
75 // reported through either a warning or a note.
77 long bar1(long a, long b, long c, long d) {
80 d = b * b - c; // expected-warning{{Potential copy-paste error; did you really mean to use 'b' here?}}
84 long bar2(long a, long b, long c, long d) {
87 d = c * b - c; // expected-note{{Similar code using 'c' here}} \
88 // expected-warning{{Potential copy-paste error; did you really mean to use 'c' here?}}
92 long bar3(long a, long b, long c, long d) {
95 d = a * b - c; // expected-note{{Similar code using 'a' here}}