Improving handling of nested if statements (with SmPL)?
Hello,
I constructed another small script variant for the semantic patch language.
// See also:
// [PATCH] crypto: lib/mpi: delete unnecessary condition
// https://lore.kernel.org/linux-kernel/[email protected]/
// https://lkml.org/lkml/2024/7/4/933
// https://elixir.bootlin.com/linux/v6.10-rc6/source/lib/crypto/mpi/mpi-bit.c#L178
@deletion2@
expression e;
identifier i;
@@
if (...)
{
...
}
else
if (i)
{
<+... when != \( i = e \| e(..., &i, ...) \)
- if (i)
- {
...
- }
...+>
}
else
{
...
}A known patch variant can be generated then.
Unfortunately, this does not happen for the affected source file together with the following smaller SmPL script variant (by using the software combination “Coccinelle 1.2-00021-gac9af0e8”).
@deletion@
expression e;
identifier i;
@@
if (i)
{
<+... when != \( i = e \| e(..., &i, ...) \)
- if (i)
- {
...- }
...+>
}
Thus I would appreciate to clarify the handling of else branches a bit more for related source code search and transformation approaches.
Regards,
Markus
Quoted 4 lines
// See also:
// [PATCH] crypto: lib/mpi: delete unnecessary condition
// https://lore.kernel.org/linux-kernel/[email protected]/
// https://lkml.org/lkml/2024/7/4/933
I constructed another small script variant for the semantic patch language.
@deletion@
assignment operator ao;
expression e;
identifier i;
statement s;
@@
if (i)
{
<+... when != \( i ao e \| ++ i \| i ++ \| -- i \| i -- \| e(..., &i, ...) \)
- if (i)
- {
...- }
...+>
}
else
s
Will there any possibilities become more helpful for the shown SmPL specification to exclude the modification of a variable?
Such a code transformation approach can point seven source files out (from the software “Linux next-20240703”) for further development considerations. Coding style adjustments might occasionally still be desirable for generated patches. Would you like to integrate any of them?
Regards,
Markus