[Cocci] problems with typecasts
Julia Lawall
julia at diku.dk
Thu Mar 5 16:44:00 CET 2009
> > cast_expr(r,pe):
> > unary_expr(r,pe) { $1 }
> > | lp=TOPar t=ctype rp=TCPar e=cast_expr(r,pe)
> > { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t,
> > P.clt2mcode ")" rp, e)) }
> >
> >
>
> Coccinelle 0.1.5 is what I'm using and it has the code you posted.
>
> cast_expr(r,pe):
> unary_expr(r,pe) { $1 }
> | lp=TOPar t=ctype rp=TCPar e=cast_expr(r,pe)
> { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t,
> P.clt2mcode ")" rp, e)) }
OK, I still think something is wrong with cast and volatile, but I will
let you try it first; perhaps 0.1.5 is more up to date than I thought.
>
> >> - Reads outside an assignment are not matched (the if clause).
> >>
> >
> > This is because you have a eg *b = a;. If you drop the semicolon, it
> > should work
> >
>
> I tried this and failed.
> @@
> expression a;
> volatile uint8_t *b;
> @@
> - a = *b
> + a = readb(b)
>
> still does not match
> if ((*bios & 0x80) == 0) { // it's busy
> while ((*bios & 0x80) == 0) ;
> }
>
> That's probably because I also match the equal sign. I'd rather avoid
> creating a separate semantic patch for every possible formula containing
> a read access to *bios.
> Is it possible to tell Coccinelle to just match on read accesses? Or
> maybe a right-hand-side expression?
OK, I didn't look at the if code carefully enough. Since you have the
rule for writes first, in the rule for reads, you should be able to just
match *b. Coccinelle applies the first rule to the whole file, then the
second rule, etc.
julia
More information about the Cocci
mailing list