cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Thomas Adam <thomas@xteddy.org>
To: Coccinelle <cocci@systeme.lip6.fr>
Subject: [Cocci] Removing the last return statement from a void function
Date: Thu, 18 Mar 2021 18:26:13 +0000	[thread overview]
Message-ID: <CAOhcEPYTkAqYM4q4p6q=nvF3eS6QX_-ajRykn08YfnOK9+VHUg@mail.gmail.com> (raw)

Hello all,

I've another Coccinelle question I'm hoping you can help me with.  The
codebase I'm working on is old, and has some interesting styles which
by themselves probably don't cause any problems, but newer C compilers
are now starting to flag them.

In particular, there seems to be a pattern in this code base of using
explicit `return;` statements at the end of void functions.  Here's an
example:

static void broadcast_mini_icon(FvwmWindow *fw)
{
    if (!FMiniIconsSupported)
    {
        return;
    }
    if (fw->mini_pixmap_file && fw->mini_icon)
    {
        BroadcastFvwmPicture( M_MINI_ICON, FW_W(fw),
            FW_W_FRAME(fw), (unsigned long)fw,
            fw->mini_icon, fw->mini_pixmap_file);
    }
    return;
}

Here you can see the last return statement is not necessary.

I'm trying to make coccinelle recognise this and remove such cases.
Here's what I've tried:

@@
identifier f;
@@

void f(...) {
  <...
- return;
...>

}

... which sort of works, but proceeds to remove *all* `return;`
statements from void functions, rather than the last occurance in the
function.

Am I on the right track with this approach, or do I need to do
something more creative?

Thanks once more for your help.

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

             reply	other threads:[~2021-03-18 18:26 UTC|newest]

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

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='CAOhcEPYTkAqYM4q4p6q=nvF3eS6QX_-ajRykn08YfnOK9+VHUg@mail.gmail.com' \
    --to=thomas@xteddy.org \
    --cc=cocci@systeme.lip6.fr \
    /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).