Coccinelle archive on lore.kernel.org
 help / Atom feed
* [Cocci] Type propagation of unknown field types in arithmetic operations
@ 2019-04-07 21:28 Michael Stefaniuc
  0 siblings, 0 replies; 1+ messages 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 --]

[-- Attachment #4: type.diff --]
[-- Type: text/x-patch, Size: 610 bytes --]

[-- 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] 1+ messages in thread

only message in thread, back to index

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

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr cocci@archiver.kernel.org
	public-inbox-index cocci


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/ public-inbox