Re: [Cocci] Converting a function return type to void based on a SmPL constraint?
> Unfortunately, I do not get the transformation result which I would expect > for this approach. But I have noticed also that a similar SmPL script > can work as expected (if a function like “unpin_extent_cache” was not marked > as “static”?). The following SmPL script variant does also not work better at the moment. @replacement@ constant C; identifier action, rc; type T; @@ static -T +void action(...) { -T rc = C; <+... when != rc when strict -return rc; ...+> } Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Converting a function return type to void based on a SmPL constraint?
On Tue, 15 Oct 2019, Markus Elfring wrote: > Hello, > > I have noticed that an update suggestion can be provided for > a source file by a known script for the semantic patch language. > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/coccinelle/misc/returnvar.cocci?id=8e0d0ad206f08506c893326ca7c9c3d9cc042cef > > Update candidate: > btrfs_destroy_delayed_refs() > https://elixir.bootlin.com/linux/v5.4-rc2/source/fs/btrfs/disk-io.c#L4252 > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/fs/btrfs/disk-io.c?id=0e9d28bc6c81f47f94979ec7d0ab6ac42345fcee#n4243 Why are there two links here to the same thing??? > > I got the software development idea then to change the function return type > to “void” together with the deletion of return statements by the help of > the tool “Coccinelle 1.0.8-4-g842075f7” instead of adjusting return > values. > > @replacement@ > constant C; > identifier action, rc; > type T; > @@ > static > -T > +void > action(...) > { > -T rc = C; > ... when != rc > when strict > -return rc; > } > > > Unfortunately, I do not get the transformation result which I would expect > for this approach. But I have noticed also that a similar SmPL script > can work as expected (if a function like “unpin_extent_cache” was not marked > as “static”?). > Would you like to add any advices? I don't know what result you expect, nor what is the relevance of unpin_extent_cache, which is not the function linked to above. My advice would be to take the time to cut down the example to a few lines of code that can easily fit in an email, and then send a complete message with no URLs or implicit references to previous emails that describes the problem. julia > Regards, > Markus > ___ > Cocci mailing list > Cocci@systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/cocci >___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] Converting a function return type to void based on a SmPL constraint?
Hello, I have noticed that an update suggestion can be provided for a source file by a known script for the semantic patch language. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/coccinelle/misc/returnvar.cocci?id=8e0d0ad206f08506c893326ca7c9c3d9cc042cef Update candidate: btrfs_destroy_delayed_refs() https://elixir.bootlin.com/linux/v5.4-rc2/source/fs/btrfs/disk-io.c#L4252 https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/fs/btrfs/disk-io.c?id=0e9d28bc6c81f47f94979ec7d0ab6ac42345fcee#n4243 I got the software development idea then to change the function return type to “void” together with the deletion of return statements by the help of the tool “Coccinelle 1.0.8-4-g842075f7” instead of adjusting return values. @replacement@ constant C; identifier action, rc; type T; @@ static -T +void action(...) { -T rc = C; ... when != rc when strict -return rc; } Unfortunately, I do not get the transformation result which I would expect for this approach. But I have noticed also that a similar SmPL script can work as expected (if a function like “unpin_extent_cache” was not marked as “static”?). Would you like to add any advices? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] Converting a function return type to void based on a SmPL constraint?
Hello, I have noticed that an update suggestion can be provided for a source file by a known script for the semantic patch language. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/coccinelle/misc/returnvar.cocci?id=8e0d0ad206f08506c893326ca7c9c3d9cc042cef Update candidate: btrfs_destroy_delayed_refs() https://elixir.bootlin.com/linux/v5.4-rc2/source/fs/btrfs/disk-io.c#L4252 https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/fs/btrfs/disk-io.c?id=0e9d28bc6c81f47f94979ec7d0ab6ac42345fcee#n4243 I got the software development idea then to change the function return type to “void” together with the deletion of return statements by the help of the tool “Coccinelle 1.0.8-4-g842075f7” instead of adjusting return values. @replacement@ constant C; identifier action, rc; type T; @@ static -T +void action(...) { -T rc = C; ... when != rc when strict -return rc; } Unfortunately, I do not get the transformation result which I would expect for this approach. But I have noticed also that a similar SmPL script can work as expected (if a function like “unpin_extent_cache” was not marked as “static”?). Would you like to add any advices? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] Checking pretty-printing around a transformation for array_size()
Hello, I have tried another source code transformation approach out with the software combination “Coccinelle 1.0.8-4-g842075f7”. @replacement@ expression count, item, source, target; type t1, t2; @@ target = kmemdup(source, + array_size( ( sizeof( -t1 +*source ) | count ) - * + , ( sizeof( -t2 +*source ) | item ) + ) , ...); This small SmPL script can produce some “usable” results. But I find the source code formatting occasionally questionable according to the Linux coding style. Example: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/mach-omap2/omap_device.c?id=5bc52f64e8841c4526d74f1073bfa95d4f6224d4#n348 https://elixir.bootlin.com/linux/v5.4-rc2/source/arch/arm/mach-omap2/omap_device.c#L348 elfring@Sonne:~/Projekte/Linux/next-patched> spatch arch/arm/mach-omap2/omap_device.c ~/Projekte/Coccinelle/janitor/use_array_size_for_kmemdup2.cocci … @@ -345,7 +345,7 @@ struct omap_device *omap_device_alloc(st } od->hwmods_cnt = oh_cnt; - hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL); + hwmods = kmemdup(ohs,array_size( sizeof(*ohs), oh_cnt), GFP_KERNEL); if (!hwmods) goto oda_exit2; … Would you like to clarify pretty-printing concerns? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] macro parameters and expressions?
On Tue, 15 Oct 2019, Markus Elfring wrote: > >> BAD:! #define MACRO(name)snprintf(pg, PAGE_SIZE, %u\n", ptr->name) > > > > If a " is missing then the code can't be parsed and Coccinelle won't do > > anything. > > I suggest to take additional software improvement opportunities into account. > > Should a semantic patch language script become able to fix such questionable > source code? No. julia ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] macro parameters and expressions?
>> BAD:! #define MACRO(name)snprintf(pg, PAGE_SIZE, %u\n", ptr->name) > > If a " is missing then the code can't be parsed and Coccinelle won't do > anything. I suggest to take additional software improvement opportunities into account. Should a semantic patch language script become able to fix such questionable source code? See also: Add a metavariable for the handling of source code https://github.com/coccinelle/coccinelle/issues/140 Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] macro parameters and expressions?
>> BAD:! #define MACRO(name)snprintf(pg, PAGE_SIZE, %u\n", ptr->name) > > If a " is missing then the code can't be parsed and Coccinelle won't do > anything. I would appreciate if the error reporting will become nicer. > But I don't know if this was a bug in the original code You should probably know also this detail from the initial clarification request. https://systeme.lip6.fr/pipermail/cocci/2019-October/006413.html > or something you have modified; I copied a bit of questionable source code also for my test approaches. > you sent another message that did not have this problem. I needed also further moments to notice related glitches. > What software situation? There are various open issues to consider around safe transformations also around preprocessor code (replacement lists), aren't there? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Adjusting macros with SmPL?
> Macros are supposed to be written on one line. I guess that you refer to a logical source line. https://en.cppreference.com/w/c/language/translation_phases#Phase_2 I am looking for better support around changing contents from physical text lines also by the means of the semantic patch language. > Anyway, to my understanding the goal was not to modify the #define part, > but rather only the code part. The following transformation approach can produce an usable result together with another small source file example. @replacement@ expression buffer, x; identifier macro; @@ -#define macro(name) snprintf(buffer, PAGE_SIZE, "%u\n", (x)->name) +#define macro(name) spgprintf_d(buffer, (x)->name) Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] macro parameters and expressions?
On Tue, 15 Oct 2019, Markus Elfring wrote: > >> * Fix search for parameterised macros with SmPL > >> https://github.com/coccinelle/coccinelle/issues/94 > … > > There are no #defines in his semantic patch. > > This design detail can probably be taken also better into account > if other software development challenges will finally be solved. > > elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c > Jürgen_Groß-Beispiel1.c > … > (ONCE) LEXER:unrecognised symbol, in token rule:\ > LEXER: WIERD end of file in string > PB: not found closing paren in fuzzy parsing > … > BAD:! #define MACRO(name)snprintf(pg, PAGE_SIZE, %u\n", ptr->name) If a " is missing then the code can't be parsed and Coccinelle won't do anything. But I don't know if this was a bug in the original code or something you have modified; you sent another message that did not have this problem. > https://wiki.sei.cmu.edu/confluence/display/c/PRE11-C.+Do+not+conclude+macro+definitions+with+a+semicolon > https://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html > > How will the software situation be improved further? What software situation? julia___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] macro parameters and expressions?
>>> * Fix search for parameterised macros with SmPL >>> https://github.com/coccinelle/coccinelle/issues/94 There are further software development challenges to consider around preprocessor code. elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c Jürgen_Groß-Beispiel2.c … ERROR-RECOV: found sync end of #define, line 1 … parse error = File "Jürgen_Groß-Beispiel2.c", line 1, column 65, charpos = 65 around = '(', whole content = #define MACRO(name) snprintf(buffer, PAGE_SIZE, "%u\n", pointer->(name)); badcount: 0 BAD:! #define MACRO(name) snprintf(buffer, PAGE_SIZE, "%u\n", pointer->(name)); … Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci