git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* excluding a function from coccinelle transformation
@ 2018-08-24  6:42 Jeff King
  2018-08-24 11:04 ` [Cocci] " Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2018-08-24  6:42 UTC (permalink / raw)
  To: git, cocci

In Git's Coccinelle patches, we sometimes want to suppress a
transformation inside a particular function. For example, in finding
conversions of hashcmp() to oidcmp(), we should not convert the call in
oidcmp() itself, since that would cause infinite recursion. We write the
semantic patch like this:

  @@
  identifier f != oidcmp;
  expression E1, E2;
  @@
    f(...) {...
  - hashcmp(E1->hash, E2->hash)
  + oidcmp(E1, E2)
    ...}

This catches some cases, but not all. For instance, there's one case in
sequencer.c which it does not convert. Now here's where it gets weird.
If I instead use the angle-bracket form of ellipses, like this:

  @@
  identifier f != oidcmp;
  expression E1, E2;
  @@
    f(...) {<...
  - hashcmp(E1->hash, E2->hash)
  + oidcmp(E1, E2)
    ...>}

then we do generate the expected diff! Here's a much more cut-down
source file that demonstrates the same behavior:

  int foo(void)
  {
    if (1)
      if (!hashcmp(x, y))
        return 1;
    return 0;
  }

If I remove the initial "if (1)" then a diff is generated with either
semantic patch (and the particulars of the "if" are not important; the
same thing happens if it's a while-loop. The key thing seems to be that
the code is not in the top-level block of the function).

And here's some double-weirdness. I get those results with spatch 1.0.4,
which is what's in Debian unstable. If I then upgrade to 1.0.6 from
Debian experimental, then _neither_ patch produces any results! Instead
I get:

  init_defs_builtins: /usr/lib/coccinelle/standard.h
  (ONCE) Expected tokens oidcmp hashcmp hash
  Skipping:foo.c

(whereas before, even the failing case said "HANDLING: foo.c").

And then one final check: I built coccinelle from the current tip of
https://github.com/coccinelle/coccinelle (1.0.7-00504-g670b2243).
With my cut-down case, that version generates a diff with either
semantic patch. But for the full-blown case in sequencer.c, it still
only works with the angle brackets.

So my questions are:

  - is this a bug in coccinelle? Or I not understand how "..." is
    supposed to work here?

    (It does seem like there was possibly a separate bug introduced in
    1.0.6 that was later fixed; we can probably ignore that and just
    focus on the behavior in the current tip of master).

  - is there a better way to represent this kind of "transform this
    everywhere _except_ in this function" semantic patch? (preferably
    one that does not tickle this bug, if it is indeed a bug ;) ).

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-24 21:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-24  6:42 excluding a function from coccinelle transformation Jeff King
2018-08-24 11:04 ` [Cocci] " Julia Lawall
2018-08-24 20:53   ` Jeff King
2018-08-24 21:00     ` Julia Lawall

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).