[Cocci] RE: Coccinelle errors during parsing of C-macros

ext-yingtong.li at nokia.com ext-yingtong.li at nokia.com
Wed Apr 29 08:48:31 CEST 2009


Hi, Julia,

  Thanks a lot for your quick response!
  
-Yingtong 

>-----Original Message-----
>From: ext Julia Lawall [mailto:julia at diku.dk] 
>Sent: Wednesday, April 29, 2009 2:44 PM
>To: Li Yingtong (EXT-Elektrobit/Beijing)
>Cc: cocci at diku.dk
>Subject: Re: [Cocci] RE: Coccinelle errors during parsing of C-macros
>
>On Wed, 29 Apr 2009, ext-yingtong.li at nokia.com wrote:
>
>> 
>>  Hi,
>> 
>>   There is a serious problem of coccinelle comes out, seems the type 
>> recognition of expression  is not reliable.
>> 
>>   Here is an example:
>>   C file:
>> long function()
>> {
>>         long a;
>>         int b;
>> 
>>         a + b;
>>         b + a;
>> 
>>         return a;
>> }
>> 
>>   Cocci file:
>> @ C @
>> long E1;
>> int E2;
>> @@
>> (
>> - E1;
>> + (long)E1;
>> |
>> - E2;
>> + (int)E2;
>> )
>> 
>>  Output of spatch:
>> @@ -3,8 +3,8 @@ long function()
>>          long a;
>>  	int b;
>>  
>> -        a + b;
>> -        b + a;
>> +        (long)a + b;
>> +        (int)b + a;
>>  
>>          return a;
>>  }
>> 
>>   It is wrong here, as per the ANSI C specification, section 
>"3.2.1.5 
>> Usual arithmetic conversions", integral promotions are performed on 
>> both operands, either operand has type long, the other 
>operand should be converted to long. Therefore, both of the 2 
>expressions are long.
>> 
>>   This issue is serious to us, please kindly have a look and 
>hopefully it could be fixed easily and soon!
>
>Indeed, the type analysis of binary operators is extremely 
>naive.  I have improved the treatment of pointers (int + ptr, 
>ptr - ptr, etc) and I will add this case.  We should be able 
>to release a new version soon, but I can send you a patch 
>later today as well.
>
>julia
>


More information about the Cocci mailing list