[Cocci] problems with typecasts

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Thu Mar 5 17:01:23 CET 2009


On 05.03.2009 16:44, Julia Lawall wrote:
>>>> - 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.
>   

That works. Awesome!


Regards,
Carl-Daniel


More information about the Cocci mailing list