]> git.ipfire.org Git - thirdparty/git.git/blob - contrib/coccinelle/unused.cocci
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / contrib / coccinelle / unused.cocci
1 // This rule finds sequences of "unused" declerations and uses of a
2 // variable, where "unused" is defined to include only calling the
3 // equivalent of alloc, init & free functions on the variable.
4 @@
5 type T;
6 identifier I;
7 // STRBUF_INIT, but also e.g. STRING_LIST_INIT_DUP (so no anchoring)
8 constant INIT_MACRO =~ "_INIT";
9 identifier MALLOC1 =~ "^x?[mc]alloc$";
10 identifier INIT_ASSIGN1 =~ "^get_worktrees$";
11 identifier INIT_CALL1 =~ "^[a-z_]*_init$";
12 identifier REL1 =~ "^[a-z_]*_(release|reset|clear|free)$";
13 identifier REL2 =~ "^(release|clear|free)_[a-z_]*$";
14 @@
15
16 (
17 - T I;
18 |
19 - T I = { 0 };
20 |
21 - T I = INIT_MACRO;
22 |
23 - T I = MALLOC1(...);
24 |
25 - T I = INIT_ASSIGN1(...);
26 )
27
28 <... when != \( I \| &I \)
29 (
30 - \( INIT_CALL1 \)( \( I \| &I \), ...);
31 |
32 - I = \( INIT_ASSIGN1 \)(...);
33 |
34 - I = MALLOC1(...);
35 )
36 ...>
37
38 (
39 - \( REL1 \| REL2 \)( \( I \| &I \), ...);
40 |
41 - \( REL1 \| REL2 \)( \( &I \| I \) );
42 )
43 ... when != \( I \| &I \)