Re: [cocci] [PATCH 01/36] coccinelle: misc: add cond_return_no_effect.cocci
From: Julia Lawall
Date: Fri Jul 24 2026 - 07:45:41 EST
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