On 2/15/19 7:30 AM, Markus Elfring wrote:
>> I have this trivial script to remove useless casts to self:
>> @ disable drop_cast @
>> type T;
>> T E;
>> @@
>> - (T)
>>      E
>>
>> It works but I'm hitting false positives when the code casts away
>> qualifiers for field types.
> 
> Can this result be expected when your source code transformation
> approach is just very generic?
I know of no case where removing the self cast in
    (typeof(expr))expr
wouldn't be a true no-op.


>> Applying the generated diff will lead to a gcc warning:
>> $ gcc -c  qualifier.c
>> qualifier.c: In function ‘baz’:
>> qualifier.c:12:12: warning: return discards ‘const’ qualifier from
>> pointer target type [-Wdiscarded-qualifiers]
>>      return &b->i;
>>             ^~~~~
> 
> 
> Would you like to add any SmPL filter specifications for such qualifiers?
No.

>> I even tried prepending an alternation with "const T good;" but the cast
>> still gets removed.
> 
> * How do you think about to check the function parameter properties
>   in more detail?
Badly.

> * Under which circumstances would you try to cast constness away?
I'm not trying, the code does that already.

> * Would you like to distinguish the involved data types any more?
No.

The generic transformation is simple but perfect at the same time and
showcases coccinelles expressiveness and beauty.


bye
        michael



_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to