* [Cocci] Type propagation of unknown field types in arithmetic operations
@ 2019-04-07 21:28 Michael Stefaniuc
0 siblings, 0 replies; only message in thread
From: Michael Stefaniuc @ 2019-04-07 21:28 UTC (permalink / raw)
To: Coccinelle
[-- Attachment #1: Type: text/plain, Size: 603 bytes --]
Hello,
I've run into a new set of false positives in my quest to remove casts
to self:
If the type of a field is unknown then the cast to int will be kept
(int)s->unknown
But if that field is involved in an arithmetic operation with a numeric
constant and the result gets casted to int then the cast gets
erroneously removed:
(int)(s->unknown / 1000)
That happens only for fields as a the cast will be kept in for variables:
(int)(unknown / 1000)
Also if the type of the field is known and doesn't matches then the cast
is correctly kept.
Test case is attached.
thanks
bye
michael
[-- Attachment #2: selfcast.cocci --]
[-- Type: text/plain, Size: 51 bytes --]
@ disable drop_cast @
type T;
T E;
@@
- (T)
E
[-- Attachment #3: type.c --]
[-- Type: text/x-csrc, Size: 431 bytes --]
struct _sk {
int i;
long l;
};
int foo(int i, long l, bar b, struct _sk *sk, struct _su *su)
{
int tmp = (int)i;
tmp += (int)(i / 1000);
tmp += (int)l;
tmp += (int)(l / 1000);
tmp += (int)b;
tmp += (int)(b / 1000);
tmp += (int)sk->i;
tmp += (int)(sk->i / 1000);
tmp += (int)sk->l;
tmp += (int)(sk->l / 1000);
tmp += (int)su->l;
tmp += (int)(su->l / 1000);
return tmp;
}
[-- Attachment #4: type.diff --]
[-- Type: text/x-patch, Size: 610 bytes --]
--- type.c
+++ /tmp/cocci-output-10499-bbfa36-type.c
@@ -5,17 +5,17 @@ struct _sk {
int foo(int i, long l, bar b, struct _sk *sk, struct _su *su)
{
- int tmp = (int)i;
- tmp += (int)(i / 1000);
+ int tmp = i;
+ tmp += (i / 1000);
tmp += (int)l;
tmp += (int)(l / 1000);
tmp += (int)b;
tmp += (int)(b / 1000);
- tmp += (int)sk->i;
- tmp += (int)(sk->i / 1000);
+ tmp += sk->i;
+ tmp += (sk->i / 1000);
tmp += (int)sk->l;
tmp += (int)(sk->l / 1000);
tmp += (int)su->l;
- tmp += (int)(su->l / 1000);
+ tmp += (su->l / 1000);
return tmp;
}
[-- Attachment #5: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-04-07 21:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-07 21:28 [Cocci] Type propagation of unknown field types in arithmetic operations Michael Stefaniuc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).