[Cocci] "TODO: FunCall" in python match printing
Julia Lawall
julia at diku.dk
Fri Mar 6 07:02:57 CET 2009
On Fri, 6 Mar 2009, Carl-Daniel Hailfinger wrote:
> Hi,
>
> I decided to use spatch for diagnostics on the refactored flashrom code.
> flashrom deals with direct memory accesses, so the code is literally
> sprinkled with volatile qualifiers for variables. Some of them don't
> make sense, especially assignments to variables which are not placed in
> mmapped flash ROM space.
>
> The following semantic patch does almost what I want:
>
> @r exists@
> expression b;
> typedef uint8_t;
> volatile uint8_t a;
> position p1;
> @@
> a at p1 = b;
>
> @script:python@
> p1 << r.p1;
> a << r.a;
> b << r.b;
> @@
> print "* file: %s line %s has assignment to unnecessarily volatile
> variable: %s = %s;" % (p1[0].file, p1[0].line, a, b)
>
>
> Original code:
>
> volatile uint8_t tmp;
> tmp = readb(bios + 0x1823);
> tmp = readb(bios + 0x1820);
> tmp = readb(bios + 0x1822);
> tmp = readb(bios + 0x0418);
> tmp = readb(bios + 0x041B);
> tmp = readb(bios + 0x0419);
> tmp = readb(bios + 0x040A);
>
> Generated messages:
> * file: sst28sf040.c line 44 has assignment to unnecessarily volatile
> variable: tmp = TODO: FunCall;
> * file: sst28sf040.c line 43 has assignment to unnecessarily volatile
> variable: tmp = TODO: FunCall;
> * file: sst28sf040.c line 42 has assignment to unnecessarily volatile
> variable: tmp = TODO: FunCall;
> * file: sst28sf040.c line 41 has assignment to unnecessarily volatile
> variable: tmp = TODO: FunCall;
> * file: sst28sf040.c line 40 has assignment to unnecessarily volatile
> variable: tmp = TODO: FunCall;
> * file: sst28sf040.c line 39 has assignment to unnecessarily volatile
> variable: tmp = TODO: FunCall;
> * file: sst28sf040.c line 38 has assignment to unnecessarily volatile
> variable: tmp = TODO: FunCall;
>
> I'd prefer to print the whole line, but as long as the TODO remains, the
> current output will have to suffice. Actually, the output is good enough
> for my purposes.
Yes, the python support for printing out big terms is not very well
developed. I can probably make a quick fix for this case this morning.
If you use emacs, there is an API for generating code that works with the
emacs org mode. Here is an example:
@r@
position p;
@@
// Place our cocci code here
// using position p and perhaps later position p1.
@script:python@
p << r.p;
p1 << r.p1;
@@
cocci.print_main(p)
cocci.print_sec("Your msg here", p1)
Org mode will give you a link to the right place in the file.
> Just noticed: For some files, the above patch gives a warning:
> (ONCE) Missing type information. Certainly a pb in annotate_typer.ml
Probably because it doesn't find a header file that contains some needed
type information.
> For some other files, the warning is different:
> (ONCE) ast_to_flow: filter a directive
There is a #define that it is unable to do anything useful with.
julia
More information about the Cocci
mailing list