git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
blob a1b09d2d73d6481742fdd5e020254be549bc1795 2746 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
// This rule finds sequences of "unused" declerations and uses of
// "struct strbuf" and other common types.
//
// I.e. this finds cases where we only declare the variable, and then
// release it, e.g.:
//
//	struct strbuf buf = STRBUF_INIT;
//      [.. no other use of "buf" in the function ..]
//	strbuf_release(&buf)
//
// Or:
//
//	struct strbuf buf;
//	[.. no other use of "buf" in the function ..]
//	strbuf_init(&buf, 0);
//	[.. no other use of "buf" in the function ..]
//	strbuf_release(&buf)
//
// To do do this we find (continued below)...
@@
type T;
identifier I;
// STRBUF_INIT, but also e.g. STRING_LIST_INIT_DUP (so no anchoring)
constant INIT_MACRO =~ "_INIT";
// x[mc]alloc() etc.
identifier MALLOC1 =~ "^x?[mc]alloc$";
// I = get_worktrees() etc.
identifier INIT_ASSIGN1 =~ "^get_worktrees$";
// strbuf_init(&I, ...) etc.
identifier INIT_CALL1 =~ "^[a-z_]*_init$";
// stbuf_release(), string_list_clear() etc.
identifier REL1 =~ "^[a-z_]*_(release|clear|free)$";
// release_patch(), clear_pathspec() etc.
identifier REL2 =~ "^(release|clear|free)_[a-z_]*$";
@@

// .. A declaration like "struct strbuf buf;"...
(
- T I;
// ... or "struct strbuf buf = { 0 };" ...
|
- T I = { 0 };
// ... or "struct STRBUF buf = STRBUF_INIT;" ...
|
- T I = INIT_MACRO;
|
// ... or "struct strbuf *buf = xmalloc(...)" etc. ...
- T I = MALLOC1(...);
)

// ... Optionally followed by lines that make no use of "buf", "&buf"
// etc., but which ...
<... when != \( I \| &I \)
(
// .. (only) make use of "buf" or "&buf" to call something like
// "strbuf_init(&buf, ...)" ...
- \( INIT_CALL1 \)( \( I \| &I \), ...);
|
// .. or e.g. "worktrees = get_worktrees();", i.e. a known "assignment
// init" ...
- I = \( INIT_ASSIGN1 \)(...);
|
// .. or to follow-up a "struct strbuf *buf" with e.g. "buf =
// xmalloc(...)" (which may in turn be followed-up by a
// "strbuf_init()", which we'll match with INIT_CALL1) ...
- I = MALLOC1(...);
)
...>

// ... and then no mention of "buf" or "&buf" until we get to a
// strbuf_release(&buf) at the end ...
(
- \( REL1 \| REL2 \)( \( I \| &I \), ...);
|
- \( REL1 \| REL2 \)( \( &I \| I \) );
)
// ... and no use *after* either, e.g. we don't want to delete
// init/strbuf_release() patterns, where "&buf" could be used
// afterwards.
  ... when != \( I \| &I \)
// Note that we're intentionally loose in accepting e.g. a
// "strbuf_init(&buf)" followed by a "string_list_clear(&buf,
// 0)". It's assumed that the compiler will catch any such invalid
// code, i.e. that our constructors/destructors don't take a "void *".
//
// This rule also isn't capable of finding cases where &buf is used,
// but only to e.g. pass that variable to a static function which
// doesn't use it. The analysis is only function-local.

debug log:

solving a1b09d2d73d ...
found a1b09d2d73d in https://public-inbox.org/git/patch-v3-4.4-45a429b9cc9-20220701T102506Z-avarab@gmail.com/
found 9f0101c1350 in https://public-inbox.org/git/patch-v3-3.4-9a5e7208dec-20220701T102506Z-avarab@gmail.com/
found 43942f3cd4f in https://public-inbox.org/git/patch-v3-2.4-6324d3956ed-20220701T102506Z-avarab@gmail.com/
found bc26d39b313 in https://public-inbox.org/git/patch-v3-1.4-49e9ccb5819-20220701T102506Z-avarab@gmail.com/

applying [1/4] https://public-inbox.org/git/patch-v3-1.4-49e9ccb5819-20220701T102506Z-avarab@gmail.com/
diff --git a/contrib/coccinelle/unused.cocci b/contrib/coccinelle/unused.cocci
new file mode 100644
index 00000000000..bc26d39b313


applying [2/4] https://public-inbox.org/git/patch-v3-2.4-6324d3956ed-20220701T102506Z-avarab@gmail.com/
diff --git a/contrib/coccinelle/unused.cocci b/contrib/coccinelle/unused.cocci
index bc26d39b313..43942f3cd4f 100644


applying [3/4] https://public-inbox.org/git/patch-v3-3.4-9a5e7208dec-20220701T102506Z-avarab@gmail.com/
diff --git a/contrib/coccinelle/unused.cocci b/contrib/coccinelle/unused.cocci
index 43942f3cd4f..9f0101c1350 100644


applying [4/4] https://public-inbox.org/git/patch-v3-4.4-45a429b9cc9-20220701T102506Z-avarab@gmail.com/
diff --git a/contrib/coccinelle/unused.cocci b/contrib/coccinelle/unused.cocci
index 9f0101c1350..a1b09d2d73d 100644

Checking patch contrib/coccinelle/unused.cocci...
Applied patch contrib/coccinelle/unused.cocci cleanly.
Checking patch contrib/coccinelle/unused.cocci...
Applied patch contrib/coccinelle/unused.cocci cleanly.
Checking patch contrib/coccinelle/unused.cocci...
Applied patch contrib/coccinelle/unused.cocci cleanly.
Checking patch contrib/coccinelle/unused.cocci...
Applied patch contrib/coccinelle/unused.cocci cleanly.

index at:
100644 a1b09d2d73d6481742fdd5e020254be549bc1795	contrib/coccinelle/unused.cocci

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).