Re: [cocci] [PATCH 01/36] coccinelle: misc: add cond_return_no_effect.cocci

From: Markus Elfring

Date: Fri Jul 24 2026 - 07:59:36 EST


>> …
>>> +++ 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.

Can software run time characteristics be influenced in desirable directions
for such an use case?


> 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).

Would this implementation detail become interesting for corresponding refinements?

Regards,
Markus