cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: Thomas Adam <thomas@xteddy.org>
Cc: Coccinelle <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] Removing the last return statement from a void function
Date: Fri, 19 Mar 2021 22:10:07 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2103192206510.2947@hadrien> (raw)
In-Reply-To: <CAOhcEPZuVRGFXTHj+jw_o7EqK1=m0ZpN2-SvPK3sQkS+r4sGow@mail.gmail.com>



On Fri, 19 Mar 2021, Thomas Adam wrote:

> On Thu, 18 Mar 2021 at 19:24, Julia Lawall <julia.lawall@inria.fr> wrote:
>
> > The ... in Coccinelle is based on control flow, so it is a bit hard to
> > find the return at the bottom of the function.  Actually, from
> > Coccinelle's point of view, all returns are at the bottom of the function,
> > because one leaves the function after a return.
>
> Interesting, that helps me understand a little more about Coccinelle.  Thanks.
>
> > You can try the following:
> >
> > @r@
> > position p;
> > identifier f;
> > }
> >
> > f(...) {
> > <...
> > { .. return@p; }
> > ...>
> > }
> >
> > @@
> > position p != r.p;
> > @@
> >
> > - return@p;
>
> So I tried this:
>
> @r@
> position p;
> identifier f;
> @@
>
> f(...) {
> <...
>    { ... return@p; }
> ...>
> }
>
> @@
> position p != r.p;
> @@
>
> - return@p;
>
> Which I ran as:
>
> spatch --in-place --debug --iso-file contrib/coccinelle/empty.iso \
>     --sp-file ./contrib/coccinelle/remove-void-return.cocci --dir fvwm
>
> With "--dir fvwm", I found that my CPU was being chewed at 100%, which I left
> running overnight.  Some 8 hours later, spatch was still running.  Presumably,
> Coccinelle is having an interesting time coordinating the positions?
>
> Instead, I decided to loop over the .c files which "--dir fvwm" would have
> done.  What I found was that for some files, spatch took a few seconds, and
> produced no output, yet for some, spatch was still running without any result
> known (so I killed it).
>
> Indeed, I'm attaching a debug run of spatch to this email (cocci-debug) for
> one file that definitely has functions where I would expect Coccinelle to have
> matched a "return;" statement to be removed, but this wasn't the case.
>
> Would you be able to suggest what I might have done wrong, or if there's any
> additional debugging I can provide?

If Coccinelle gets stuck on one part of a file, it won't move on to the
next part.  So the fact that the something should have been done in the
file is not really helpful.

You can use the argument --show-trying to see what function it is working
on at the moment.

You can use --timeout N to limit the treatment of a given file to N
seconds.

It may help to replace @r@ by @r exists@.

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

      reply	other threads:[~2021-03-19 21:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18 18:26 [Cocci] Removing the last return statement from a void function Thomas Adam
2021-03-18 19:24 ` Julia Lawall
2021-03-19 20:40   ` Thomas Adam
2021-03-19 21:10     ` Julia Lawall [this message]

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=alpine.DEB.2.22.394.2103192206510.2947@hadrien \
    --to=julia.lawall@inria.fr \
    --cc=cocci@systeme.lip6.fr \
    --cc=thomas@xteddy.org \
    /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 NNTP newsgroup(s).