Moving string literals with SmPL?
Hello,
I would appreciate if another source code transformation can be achieved also by the means of the semantic patch language.
Thus I tried the following SmPL script variant out.
// See also:
// crypto_rng_show()
// https://elixir.bootlin.com/linux/v6.18-rc4/source/crypto/rng.c#L82-L86
@adjustment@
constant char[] last_literal, literal;
expression context;
@@
-seq_printf(context, literal);
seq_printf(context,
+ literal
last_literal,
...);Unfortunately, I am wondering about the following information.
Questionable test result (according to the software combination “Coccinelle 1.3.0”):
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> /usr/bin/spatch --parse-cocci combine_selected_seq_printf_calls.cocci …
plus: parse error:
File "combine_selected_seq_printf_calls.cocci", line 11, column 12, charpos = 267
around = 'last_literal',
whole content = last_literal,
Under which circumstances will such data processing become better supported?
http://www.en.cppreference.com/w/c/language/string_literal.html
Regards,
Markus
Quoted 10 lines · Markus Elfring
Hello,
I would appreciate if another source code transformation can be achieved also by the means of the semantic patch language.
Thus I tried the following SmPL script variant out.
Quoted 10 lines
// See also:
//crypto_rng_show()
// https://elixir.bootlin.com/linux/v6.18-rc4/source/crypto/rng.c#L82-L86
@adjustment@
constant char[]last_literal, literal;
expression context;
@@
-seq_printf(context, literal);
seq_printf(context,
+ literal
Why is there no comma after literal?
Quoted 20 lines
last_literal, ...);Unfortunately, I am wondering about the following information.
Questionable test result (according to the software combination “Coccinelle 1.3.0”):
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor>/usr/bin/spatch--parse-coccicombine_selected_seq_printf_calls.cocci…
plus: parse error:
File "combine_selected_seq_printf_calls.cocci", line 11, column 12, charpos = 267
around = 'last_literal',
whole content =last_literal,Under which circumstances will such data processing become better supported?
http://www.en.cppreference.com/w/c/language/string_literal.htmlRegards,
Markus
Quoted 11 lines
Quoted 10 lines
// See also:
//crypto_rng_show()
// https://elixir.bootlin.com/linux/v6.18-rc4/source/crypto/rng.c#L82-L86
@adjustment@
constant char[]last_literal, literal;
expression context;
@@
-seq_printf(context, literal);
seq_printf(context,
+ literal
Quoted 4 lines
Why is there no comma after literal?
Quoted 2 lines
last_literal, ...);
I would like to use adjacent string literals here.
https://en.cppreference.com/w/c/language/string_literal.html#Explanation
Regards,
Markus
Quoted 2 lines
I would appreciate if another source code transformation can be achieved also by the means of the semantic patch language.
Will another SmPL script example trigger constructive development discussions?
@searching@
constant char[] last_literal, literal;
expression context;
@@
seq_printf(context, literal);
seq_printf(context, last_literal, ...);
@script:python recombination@
x << searching.literal;
y << searching.last_literal;
text;
@@
coccinelle.text = cocci.make_ident(x + "\n" + y)
@movement@
constant char[] searching.last_literal, searching.literal; expression searching.context;
identifier recombination.text;
@@
-seq_printf(context, literal);
seq_printf(context,
- last_literal
+ text
,
...);Questionable test result (according to the software combination “Coccinelle 1.3.0”):
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch --no-loops crypto/rng.c …/Projekte/Coccinelle/janitor/combine_selected_seq_printf_calls2.cocci …
@@ -81,8 +81,8 @@ static void crypto_rng_show(struct seq_f
__maybe_unused;
static void crypto_rng_show(struct seq_file *m, struct crypto_alg *alg)
{
- seq_printf(m, "type : rng\n");
- seq_printf(m, "seedsize : %u\n", seedsize(alg));
+ seq_printf(m, "type : rng\n"
+"seedsize : %u\n", seedsize(alg));
}
…
real 0m0,493s
user 0m0,249s
sys 0m0,109sSee also:
* Clarification approach
Propagating values back from Python script to SmPL rule with other metavariable type than “identifier” 2016-10-22
* Contribution
[PATCH] crypto: rng - Combine two seq_printf() calls into one in crypto_rng_show()
https://lore.kernel.org/linux-crypto/[email protected]/
https://lkml.org/lkml/2025/11/10/1357
Regards,
Markus
Quoted 11 lines · Markus Elfring
Quoted 11 lines
Quoted 10 lines
// See also:
//crypto_rng_show()
// https://elixir.bootlin.com/linux/v6.18-rc4/source/crypto/rng.c#L82-L86
@adjustment@
constant char[]last_literal, literal;
expression context;
@@
-seq_printf(context, literal);
seq_printf(context,
+ literal
Quoted 7 lines
Quoted 4 lines
Why is there no comma after literal?
Quoted 2 lines
last_literal, ...);I would like to use adjacent string literals here.
https://en.cppreference.com/w/c/language/string_literal.html#Explanation
That is not supported.