git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 0/2] add and apply a rule to find "unused" init+free

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 21, 2022, 22:44 UTC
Message-ID
<cover-v2-0.2-00000000000-20220621T223954Z-avarab@gmail.com>
In-Reply-To
<patch-1.1-7d90f26b73f-20220520T115426Z-avarab@gmail.com>

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@gmail.com/
2. https://lore.kernel.org/git/220620.865ykvw2l4.gmgdl@evledraar.gmail.com/
Æ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
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 2 of 24 in “cocci: add and apply a rule to find "unused" variables”
  1. cocci: add and apply a rule to find "unused" variablesÆvar Arnfjörð Bjarmason, May 20, 2022
  2. 0/2 add and apply a rule to find "unused" init+freeÆvar Arnfjörð Bjarmason, Jun 21, 2022
  3. 1/2 cocci: add and apply a rule to find "unused" variablesÆvar Arnfjörð Bjarmason, Jun 21, 2022
  4. Junio C HamanoJun 22, 2022
  5. 2/2 cocci: remove "when strict" from unused.cocciÆvar Arnfjörð Bjarmason, Jun 21, 2022
  6. 0/4 add and apply a rule to find "unused" init+freeÆvar Arnfjörð Bjarmason, Jul 1, 2022
  7. 1/4 cocci: add and apply a rule to find "unused" strbufsÆvar Arnfjörð Bjarmason, Jul 1, 2022
  8. Jeff KingJul 1, 2022
  9. Eric SunshineJul 1, 2022
  10. 2/4 cocci: catch unused "strbuf" using an xmalloc() patternÆvar Arnfjörð Bjarmason, Jul 1, 2022
  11. 4/4 cocci: generalize "unused" rule to cover more than "strbuf"Ævar Arnfjörð Bjarmason, Jul 1, 2022
  12. 3/4 cocci: remove "when strict" from unused.cocciÆvar Arnfjörð Bjarmason, Jul 1, 2022
  13. Eric SunshineJul 1, 2022
  14. Jeff KingJul 1, 2022
  15. 0/6 add and apply a rule to find "unused" init+freeÆvar Arnfjörð Bjarmason, Jul 5, 2022
  16. 2/6 Makefile & .gitignore: ignore & clean "git.res", not "*.res"Ævar Arnfjörð Bjarmason, Jul 5, 2022
  17. 1/6 Makefile: remove mandatory "spatch" arguments from SPATCH_FLAGSÆvar Arnfjörð Bjarmason, Jul 5, 2022
  18. 3/6 cocci: add a "coccicheck-test" target and test *.cocci rulesÆvar Arnfjörð Bjarmason, Jul 5, 2022
  19. 4/6 cocci: have "coccicheck{,-pending}" depend on "coccicheck-test"Ævar Arnfjörð Bjarmason, Jul 5, 2022
  20. 5/6 cocci: add and apply a rule to find "unused" strbufsÆvar Arnfjörð Bjarmason, Jul 5, 2022
  21. 6/6 cocci: generalize "unused" rule to cover more than "strbuf"Ævar Arnfjörð Bjarmason, Jul 5, 2022
  22. Junio C HamanoJul 6, 2022
  23. Jeff KingJul 11, 2022
  24. Ævar Arnfjörð BjarmasonJul 11, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.