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

From: Markus Elfring

Date: Sun Jul 26 2026 - 08:42:59 EST


>> I would appreciate to clarify such an approach for a bit of dead-code elimination
>> in more detail.
>
> I have no idea what you are talking about. What dead code are you
> referring to?

Variable definitions which became unused according to transformation rules
by the semantic patch language.
https://en.wikipedia.org/wiki/Dead-code_elimination


>> I got the impression that some versions of the C programming language do
>> not handle variable declarations also as “statements”.
>> https://en.cppreference.com/c/language/statements
>>
>> See also:
>> https://en.cppreference.com/cpp/language/statements#Declaration_statements
>
> And the conclusion would be what? First, Coccinelle has it's own parser.

This is generally fine.


> It decides what is a statement, not some wikipedia page.

Does your supported data model deviate from known programming language standard specifications?

Can users determine relevant differences from published software documentation?


> Second, Coccinelle does not consider declarations to be statements.
> That's what the D is there for.

You suggested to apply two metavariable types in an SmPL disjunction
while trying to delete special variable definitions, didn't you?


>>> The first part ensures that it is not a top-level declaration and the
>>> second part does the check you had previously.
>>
>> I do not see so far that the intended source code restriction would be explicitly
>> expressed here.
>
> No idea what this means. What intended code restriction are you referring to?
Do you try to distinguish global variable declarations from local definitions anyhow?

How are variable scopes be taken into account here?
https://github.com/coccinelle/coccinelle/issues/322

Regards,
Markus