Re: [cocci] [PATCH 01/36] coccinelle: misc: add cond_return_no_effect.cocci
From: Sang-Heon Jeon
Date: Fri Jul 24 2026 - 10:45:50 EST
Hello,
On Fri, Jul 24, 2026 at 8:19 PM Markus Elfring <Markus.Elfring@xxxxxx> 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?
The two rules look similar, but the metavariable kinds are different
for a reason.
- If both rules used `local idexpression`, the second rule could miss
global or static variable cases, even though such patterns are not
common.
- If both rules used `idexpression`, the first rule could remove an
assignment to a global or static variable, which would be a false
positive.
Combining them with two separate metavariables would be okay, but I
don't see much benefit in that change. So I'd prefer to stay existing
form.
> Regards,
> Markus
Thanks for reviewing :)
Best Regards,
Sang-Heon Jeon