Re: [cocci] [PATCH 01/36] coccinelle: misc: add cond_return_no_effect.cocci
Julia Lawall <[email protected]> Fri, 24 Jul 2026 13:38:25 +0200 (CEST)
| Newsgroups | fr.inria.cocci,org.kernel.vger.kernel-janitors,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--8323329-1116840085-1784893105=:3487
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8BIT
On Fri, 24 Jul 2026, Markus Elfring wrote:
> …
> > +++ b/scripts/coccinelle/misc/cond_return_no_effect.cocci
> > @@ -0,0 +1,121 @@
> …
> > +@depends on patch@
> > +local idexpression ret;
> > +expression E;
> > +binary operator cmp = {<, <=, >, >=, ==, !=};
> > +constant C;
> > +@@
> > +- ret = E;
> > +- if (\(ret \| !ret \| ret cmp C\))
> > +- return ret;
> > +- return ret;
> > ++ return E;
> > +
> > +@depends on patch@
> > +idexpression ret;
> > +binary operator cmp = {<, <=, >, >=, ==, !=};
> > +constant C;
> > +@@
> > +- if (\(ret \| !ret \| ret cmp C\))
> > +- return ret;
> > + return ret;
> …
>
> How do you think about to combine such transformation rules
> by using an SmPL disjunction?
I see no benefit to doing that. In particular, the patterns search for
some code in common, but from different places, since one starts with an
assignment and the other starts with an if (that is common to both).
julia
--8323329-1116840085-1784893105=:3487--