1 // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:MinimumCloneComplexity=10 -verify %s
3 // Tests that macros and non-macro clones aren't mixed into the same hash
4 // group. This is currently necessary as all clones in a hash group need
5 // to have the same complexity value. Macros have smaller complexity values
6 // and need to be in their own hash group.
8 int foo(int a
) { // expected-warning{{Duplicate code detected}}
12 a
= a
+ 1 - 1 + 1 + 1;
13 a
= a
+ 1 * 1 + 1 + 1 + 1;
14 a
= a
+ 1 / 1 + 1 + 1 + 1;
18 int fooClone(int a
) { // expected-note{{Similar code here}}
22 a
= a
+ 1 - 1 + 1 + 1;
23 a
= a
+ 1 * 1 + 1 + 1 + 1;
24 a
= a
+ 1 / 1 + 1 + 1 + 1;
28 // Below is the same AST as above but this time generated with macros. The
29 // clones below should land in their own hash group for the reasons given above.
31 #define ASSIGN(T, V) T = T + V
33 int macro(int a
) { // expected-warning{{Duplicate code detected}}
37 ASSIGN(a
, 1 - 1 + 1 + 1);
38 ASSIGN(a
, 1 * 1 + 1 + 1 + 1);
39 ASSIGN(a
, 1 / 1 + 1 + 1 + 1);
43 int macroClone(int a
) { // expected-note{{Similar code here}}
47 ASSIGN(a
, 1 - 1 + 1 + 1);
48 ASSIGN(a
, 1 * 1 + 1 + 1 + 1);
49 ASSIGN(a
, 1 / 1 + 1 + 1 + 1);
53 // FIXME: Macros with empty definitions in the AST are currently ignored.
57 int fooFalsePositiveClone(int a
) { // expected-note{{Similar code here}}
61 a
= a
+ 1 - 1 + 1 + 1;
62 a
= a
+ 1 * 1 + 1 + 1 + 1;
63 a
= a
+ 1 / 1 + 1 + 1 + 1;