Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: phillip.wood@dunelm.org.uk
Cc: "Git Mailing List" <git@vger.kernel.org>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: Bug in unused.cocci?
Date: Thu, 11 May 2023 10:55:20 -0400	[thread overview]
Message-ID: <ZF0B2Prhc7jsqa3p@nand.local> (raw)
In-Reply-To: <5720a23e-6ac0-9a6d-3d05-4e0f34bc0589@gmail.com>

On Thu, May 11, 2023 at 10:16:21AM +0100, Phillip Wood wrote:
> I think this is due to a bug in unused.cocci. I'm not sure what is going
> wrong and admittedly we're unlikely to see code where an strbuf is
> initialized and then used it without calling any of the strbuf_* functions
> within our main codebase but it would be nice if the rule could handle this.

I don't think that this is a bug in unused.cocci, but rather a bug in
spatch not being able to read t/unit-tests/test-lib.h.

    $ spatch --verbose-parsing --debug --all-includes \
        --sp-file contrib/coccinelle/unused.old.cocci \
        t/unit-tests/t-strbuf.c | grep '^bad'
    init_defs_builtins: /usr/lib/coccinelle/standard.h
    -----------------------------------------------------------------------
    processing semantic patch file: contrib/coccinelle/unused.old.cocci
    with isos from: /usr/lib/coccinelle/standard.iso
    -----------------------------------------------------------------------

    HANDLING: t/unit-tests/t-strbuf.c
    parse error
     = error in t/unit-tests/test-lib.h; set verbose_parsing for more info
    badcount: 3
    bad: int test_done(void);
    bad:
    bad: /* Skip the current test. */
    BAD:!!!!! __attribute__((format (printf, 1, 2)))

From my understanding, spatch happily ignores macros that it doesn't
understand (like check_uint() and check_char()), so to it this code
looks like:

    struct strbuf buf;

    strbuf_init(&buf, 1024);
    strbuf_release(&buf);

which it marks as unused and applies the patch. Strangely, if you force
it to pre-process with the appropriate macro file by passing it
explicitly, it works as expected:

    $ spatch --macro-file t/unit-tests/test-lib.h \
        --sp-file contrib/coccinelle/unused.old.cocci \
        t/unit-tests/t-strbuf.c
    init_defs_builtins: /usr/lib/coccinelle/standard.h
    init_defs: t/unit-tests/test-lib.h
    HANDLING: t/unit-tests/t-strbuf.c

I am puzzled by spatch's behavior here.

Thanks,
Taylor

  reply	other threads:[~2023-05-11 14:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-11  9:16 Bug in unused.cocci? Phillip Wood
2023-05-11 14:55 ` Taylor Blau [this message]
2023-05-12 15:07   ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZF0B2Prhc7jsqa3p@nand.local \
    --to=me@ttaylorr.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).