This re-roll of [1] gets to the same end-state as far as the changed C code is concerned, but I rewrote the coccinelle rule to be much more general, based on the more recent discussion at [2]. See the "contrib/coccinelle/unused.cocci" part of 1/2 for extensive commentary and what the rule does & doesn't spot, which I won't repeat here. The 2/2 is then split up to show the effect that "when strict" has on this. I noted in [2] that I had a WIP rule to to remove that unused "get_worktrees()" but couldn't figure out a bug, this coccinelle code will properly remove that sort of code, but only if it's actually unused. 1. https://lore.kernel.org/git/patch-1.1-7d90f26b73f-20220520T115426Z-avarab@xxxxxxxxx/ 2. https://lore.kernel.org/git/220620.865ykvw2l4.gmgdl@xxxxxxxxxxxxxxxxxxx/ Ævar Arnfjörð Bjarmason (2): cocci: add and apply a rule to find "unused" variables cocci: remove "when strict" from unused.cocci builtin/fetch.c | 3 +- builtin/merge.c | 4 --- builtin/repack.c | 2 -- contrib/coccinelle/unused.cocci | 64 +++++++++++++++++++++++++++++++++ contrib/scalar/scalar.c | 3 +- diff.c | 2 -- 6 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 contrib/coccinelle/unused.cocci Range-diff against v1: 1: 7d90f26b73f < -: ----------- cocci: add and apply a rule to find "unused" variables -: ----------- > 1: d14036521ab cocci: add and apply a rule to find "unused" variables -: ----------- > 2: 4130dc15287 cocci: remove "when strict" from unused.cocci -- 2.36.1.1239.gfba91521d90