Skip to contentSkip to conversation

Searching for selected identifiers in code parts (with SmPL)?

cocci Markus Elfring 2 participants 3 messages Nov 2, 2024 – Nov 3, 2024

lore
Share & tools
lore
#0 lore raw

Hello,

I tried another tiny script variant out for the semantic patch language together with the software combination “Coccinelle 1.2-00097-g7bc8a7ac”.

@display4@
expression e;
identifier i;
@@
while (
* --i > 0

       )

e(..., <+... i ...+>, ...);

This source code search approach is working to some degree (as expected). Can the following SmPL script variant become similarly usable to find remaining update candidates?

@display@
identifier i;
@@
while (
* --i > 0

       )

<+... i ...+>;

Examples:
* t7xx_dpmaif_rx_buf_alloc
https://elixir.bootlin.com/linux/v6.12-rc5/source/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c#L229

* t7xx_dpmaif_rx_frag_alloc
https://elixir.bootlin.com/linux/v6.12-rc5/source/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c#L384

Unfortunately, I observed the following information.

Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci show_questionable_while_condition2.cocci …
minus: parse error:
File "show_questionable_while_condition2.cocci", line 10, column 1, charpos = 249
around = '<+...',
whole content = <+... i ...+>;

Regards,
Markus

#1 lore raw
Quoted 21 lines · Markus Elfring

Hello,

I tried another tiny script variant out for the semantic patch language together with the software combination “Coccinelle 1.2-00097-g7bc8a7ac”.

@display4@
expression e;
identifier i;
@@
while (
* --i > 0

       )

e(..., <+... i ...+>, ...);

This source code search approach is working to some degree (as expected). Can the following SmPL script variant become similarly usable to find remaining update candidates?

Quoted 7 lines

@display@
identifier i;
@@
while (
* --i > 0

       )

<+... i ...+>;

Use (<+... i ...+>);. Of course it looks nonsensical, but it will get it through the parser and an isomorphism will drop the ().

To avoid parser conflicts, the parser needs to be able to decide immediately when it sees a <+... what kind of <+... it is. The choice is that it is the start of a statement in this case, but that turns out to be wrong.

julia

Quoted 23 lines

Examples:
* t7xx_dpmaif_rx_buf_alloc
https://elixir.bootlin.com/linux/v6.12-rc5/source/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c#L229

* t7xx_dpmaif_rx_frag_alloc
https://elixir.bootlin.com/linux/v6.12-rc5/source/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c#L384

Unfortunately, I observed the following information.

Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci show_questionable_while_condition2.cocci …
minus: parse error:
File "show_questionable_while_condition2.cocci", line 10, column 1, charpos = 249
around = '<+...',
whole content = <+... i ...+>;

Regards,
Markus

#2 lore raw
Quoted 12 lines
Quoted 11 lines

Can the following SmPL script variant become similarly usable to find remaining update candidates?

@display@
identifier i;
@@
while (
* --i > 0

       )

<+... i ...+>;

Quoted 1 line

Use (<+... i ...+>);.

Thanks for this adjustment idea.

Quoted 1 line

Of course it looks nonsensical,

Interesting view, isn't it?

Quoted 1 line

but it will get it through the parser and an isomorphism will drop the ().

Further insights might follow.

Quoted 2 lines

To avoid parser conflicts, the parser needs to be able to decide immediately when it sees a <+... what kind of <+... it is.

Will such information influence the evolution of any corresponding software documentation?

Quoted 1 line

The choice is that it is the start of a statement in this case,

Variables (which refer to macro/function calls) are usually not decremented.

Quoted 1 line

but that turns out to be wrong.

It seems to be nice to find parameter applications in such a succinct way. Would we like to take further case distinctions better into account (with the help of additional SmPL disjunctions)?

Regards,
Markus