Reproducing a known patch with SmPL?
Hello,
I proposed another source code adjustment for a selected function implementation according to the development branch “Linux next-20260226”.
[PATCH] i3c: dw: Use more common code in dw_i3c_master_i2c_xfers()
https://lore.kernel.org/lkml/[email protected]/
https://lkml.org/lkml/2026/2/27/700
I tried the following SmPL script variant out also together with the software combination “Coccinelle 1.3.1” accordingly.
@adjustment exists@
expression action, context, last_action;
expression list el;
identifier member, rc;
@@
{
...
{
...
- action(context);
- return rc
+ goto target
;
}
...
+ last_action(el);
rc = context->member;
+target:
action(context);
- last_action(el);
return rc;}
Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch …/Projekte/Coccinelle/janitor/use_more_common_code.cocci drivers/i3c/master/dw-i3c-master.c …
@@ -1672,9 +1672,7 @@ err_disable_pm:
pm_runtime_dont_use_autosuspend(&pdev->dev);
err_assert_rst:
- reset_control_assert(master->core_rst);
-
- return ret;
+ goto target;
}
EXPORT_SYMBOL_GPL(dw_i3c_common_probe);
real 0m0,582s user 0m0,539s sys 0m0,033s
* Why was a source code place shown here at all which does not contain a variable assignment before an interesting function call?
* How should the data processing be improved in more desirable ways?
Regards,
Markus
Quoted 1 line
* How should the data processing be improved in more desirable ways?
The following SmPL script variant seems to work as expected.
@movement exists@
expression action, context, last_action;
expression list el;
identifier member, rc;
@@
{
...
+ last_action(el);
rc = context->member;
+target:
action(context);
- last_action(el);
return rc;}
How should related if branches be adjusted on demand here?
Regards,
Markus
Quoted 2 lines
* Why was a source code place shown here at all which does not contain a variable assignment before an interesting function call?
May I expect that selected source code should be found in nested compound statements even if it was not restricted as belonging to a known condition check?
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
In reply to Markus ElfringQuoted 1 line
* How should the data processing be improved in more desirable ways?
I constructed another source file example together with a corresponding SmPL script.
void my_test(void)
{
int item;
if (1)
{
item = 1;}
item = 2;
}
@display@
@@
if (...)
*{ item = 1; }
*item = 2;
Test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch test-item_assignments.c show_selected_assignments_after_compound_statements3.cocci …
@@ -3,9 +3,5 @@ void my_test(void)
int item;
if (1)
- {
- item = 1;
- }
- item = 2;
}
Can it be achieved that the source code search pattern will work also after the omission of the filter “if (...)”?
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 1 line
I constructed another source file example together with a corresponding SmPL script.
@display@
statement list sl;
@@
*{ sl }
Compound statements are often used in known programming languages.
https://en.cppreference.com/w/c/language/statements.html#Compound_statements
Another test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch test-item_assignments.c ../janitor/show_compound_statements.cocci …
@@ -3,9 +3,6 @@ void my_test(void)
int item;
if (1)
- {
- item = 1;
- }
item = 2;
}
The source code search pattern looks promising (in principle). But it can be ambiguous in its minimal form.
Thus further case distinctions would occasionally be helpful.
Additional context information can become relevant then.
How would you prefer to handle control flow recursion in safer ways here?
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 26 lines · Markus Elfring
Quoted 1 line
I constructed another source file example together with a corresponding SmPL script.
@display@
statement list sl;
@@
*{ sl }Compound statements are often used in known programming languages.
https://en.cppreference.com/w/c/language/statements.html#Compound_statementsAnother test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe>/usr/bin/spatchtest-item_assignments.c../janitor/show_compound_statements.cocci…(quoted diff) +0
-3@@ -3,9 +3,6 @@ void my_test(void) int item; if (1) - { - item = 1; - } item = 2; }
Quoted 6 lines
The source code search pattern looks promising (in principle). But it can be ambiguous in its minimal form.
Thus further case distinctions would occasionally be helpful.Additional context information can become relevant then.
How would you prefer to handle control flow recursion in safer ways here?
I have no idea what result you would like to see. The whole point of Coccinelle is that if some context information should be taken into account, then you can provide it.
julia
Quoted 4 lines
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 3 lines
Quoted 2 lines
Additional context information can become relevant then.
How would you prefer to handle control flow recursion in safer ways here?I have no idea what result you would like to see.
I would appreciate further data processing refinements.
A) I would find it nice when selected source code transformation patterns can trigger usable patches from minimal SmPL script variations.
B) Ambiguity should occasionally be avoided in more succinct ways.
Quoted 3 lines
The whole point of
Coccinelle is that if some context information should be taken into account, then you can provide it.
I hope that known software limitations can be adjusted accordingly.
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
In reply to Julia LawallQuoted 1 line
I have no idea what result you would like to see.
Under which circumstances would you dare to acknowledge remaining open issues here?
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 3 lines · Markus Elfring
Quoted 1 line
I have no idea what result you would like to see.
Under which circumstances would you dare to acknowledge remaining open issues here?
If you can tell me what result you want maybe I can do something. It's not a matter of daring to do something or not.
julia
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 3 lines
Quoted 1 line
Under which circumstances would you dare to acknowledge remaining open issues here?
If you can tell me what result you want maybe I can do something.
Can you see concrete change opportunities from my recent test results?
1. Inappropriate difference output
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00004.html
2. Questionable hierarchy level
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00015.html
Quoted 1 line
It's not a matter of daring to do something or not.
Will development interests grow anyhow?
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 9 lines · Markus Elfring
Quoted 3 lines
Quoted 1 line
Under which circumstances would you dare to acknowledge remaining open issues here?
If you can tell me what result you want maybe I can do something.
Can you see concrete change opportunities from my recent test results?
1. Inappropriate difference output
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00004.html
There is a problem here.
Quoted 3 lines
2. Questionable hierarchy level
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00015.html
This is the message I was referring to. I have no idea what you expect as the output. I don't know why it is so hard to provide that information.
julia
Quoted 9 lines
Quoted 3 lines
It's not a matter of daring to do something or not.
Will development interests grow anyhow?
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 6 lines
Quoted 5 lines
Can you see concrete change opportunities from my recent test results?
1. Inappropriate difference output
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00004.htmlThere is a problem here.
Thanks for such a feedback finally.
Quoted 5 lines
Quoted 3 lines
2. Questionable hierarchy level
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00015.htmlThis is the message I was referring to. I have no idea what you expect as the output.
I presented another test result for further development considerations.
Quoted 1 line
I don't know why it is so hard to provide that information.
I imagine that corresponding case distinctions can become also more interesting.
A) C++ test variant:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch --c++ test-item_assignments.c ../janitor/show_compound_statements.cocci …
@@ -3,9 +3,6 @@ void my_test(void)
int item;
if (1)
- {
- item = 1;
- }
item = 2;
}
Should declarations belong also to statements then?
https://en.cppreference.com/w/cpp/language/statements.html#Declaration_statements
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/233b5ceb1d5a701fb270ebdf0a9bd6be0a6ce53b/docs/manual/cocci_syntax.tex#L348-350
B) SmPL script variant:
@display2@
declaration d;
statement list sl;
@@
{
d
*sl
}
Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> /usr/bin/spatch --parse-cocci show_compound_statements2.cocci …
minus: parse error:
File "show_compound_statements2.cocci", line 7, column 2, charpos = 56
around = 'sl',
whole content = *sl
How should this implementation detail be improved anyhow?
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 64 lines · Markus Elfring
Quoted 6 lines
Quoted 5 lines
Can you see concrete change opportunities from my recent test results?
1. Inappropriate difference output
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00004.htmlThere is a problem here.
Thanks for such a feedback finally.
Quoted 5 lines
Quoted 3 lines
2. Questionable hierarchy level
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00015.htmlThis is the message I was referring to. I have no idea what you expect as the output.
I presented another test result for further development considerations.
Quoted 1 line
I don't know why it is so hard to provide that information.
I imagine that corresponding case distinctions can become also more interesting.
A) C++ test variant:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe>/usr/bin/spatch--c++test-item_assignments.c../janitor/show_compound_statements.cocci…(quoted diff) +0
-3@@ -3,9 +3,6 @@ void my_test(void) int item; if (1) - { - item = 1; - } item = 2; }Should declarations belong also to statements then?
https://en.cppreference.com/w/cpp/language/statements.html#Declaration_statements
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/233b5ceb1d5a701fb270ebdf0a9bd6be0a6ce53b/docs/manual/cocci_syntax.tex#L348-350B) SmPL script variant:
@display2@
declaration d;
statement list sl;
@@
{
d
*sl
}Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor>/usr/bin/spatch--parse-coccishow_compound_statements2.cocci…
minus: parse error:
File "show_compound_statements2.cocci", line 7, column 2, charpos = 56
around = 'sl',
whole content = *sl
Quoted 1 line
How should this implementation detail be improved anyhow?
By putting the * in the leftmost column where it belongs.
julia
Quoted 4 lines
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 2 lines
Quoted 1 line
How should this implementation detail be improved anyhow?
By putting the * in the leftmost column where it belongs.
@display2@
declaration d;
statement list sl;
@@
{
d
*sl
}
Another questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch test-item_assignments.c ../janitor/show_compound_statements2.cocci …
[no diff output]
Will further software improvements follow?
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 13 lines · Markus Elfring
Quoted 2 lines
Quoted 1 line
How should this implementation detail be improved anyhow?
By putting the * in the leftmost column where it belongs.
@display2@
declaration d;
statement list sl;
@@
{
d
*sl
}
Quoted 2 lines
Another questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe>/usr/bin/spatchtest-item_assignments.c../janitor/show_compound_statements2.cocci
And I should know what test-item_assignments.c is?
julia
Quoted 10 lines
…
[no diff output]Will further software improvements follow?
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 10 lines
Quoted 10 lines
@display2@
declaration d;
statement list sl;
@@
{
d
*sl
}
Quoted 4 lines
Quoted 2 lines
Another questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe>/usr/bin/spatchtest-item_assignments.c../janitor/show_compound_statements2.cocciAnd I should know what
test-item_assignments.cis?
Reminder:
This can be possible.
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00014.html
void my_test(void)
{
int item;
if (1)
{
item = 1;}
item = 2;
}
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 25 lines · Markus Elfring
Quoted 10 lines
Quoted 10 lines
@display2@
declaration d;
statement list sl;
@@
{
d
*sl
}Quoted 4 lines
Quoted 2 lines
Another questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe>/usr/bin/spatchtest-item_assignments.c../janitor/show_compound_statements2.cocciAnd I should know what
test-item_assignments.cis?Reminder:
This can be possible.
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00014.htmlvoid
my_test(void)
{
int item;
Quoted 7 lines
if (1)
{ item = 1;}
item = 2;
}
A statement list metavariable only matches the code starting right after a {. It can't start in random places. Nothing is going to chenge here.
julia
Quoted 5 lines
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
Quoted 30 lines
Quoted 30 lines
Quoted 10 lines
Quoted 10 lines
@display2@
declaration d;
statement list sl;
@@
{
d
*sl
}Quoted 4 lines
Quoted 2 lines
Another questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe>/usr/bin/spatchtest-item_assignments.c../janitor/show_compound_statements2.cocciAnd I should know what
test-item_assignments.cis?Reminder:
This can be possible.
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-03/msg00014.htmlvoid
my_test(void)
{
int item;if (1)
{ item = 1;}
Quoted 5 lines
Quoted 2 lines
item = 2;
}A statement list metavariable only matches the code starting right after a {. It can't start in random places.
Interesting …
Quoted 1 line
Nothing is going to chenge here.
Will it matter then to mention for a better software documentation if declarations would be skipped (or not)?
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/233b5ceb1d5a701fb270ebdf0a9bd6be0a6ce53b/docs/manual/cocci_syntax.tex#L348-350
Regards,
Markus
Re: [cocci] Reconsidering source code search challenges for nested compound statements
In reply to Julia LawallQuoted 2 lines
A statement list metavariable only matches the code starting right after a {. It can't start in random places. Nothing is going to chenge here.
Will ever any other metavariable type become supported with which a mixture of items (including statements and variable declarations) could be handled in a succinct way?
Regards,
Markus
Re: [cocci] Too limited support for SmPL statement lists?
In reply to Julia LawallQuoted 2 lines
A statement list metavariable only matches the code starting right after a {. It can't start in random places. …
I got the impression then that the supported functionality is so limited for the metavariable type “statement list” so far.
It seems that it is unlikely to be usable besides discussed test cases.
Statements are often mixed with variable declarations and definitions.
Regards,
Markus