Coccinelle Archive on
 help / color / Atom feed
From: Julia Lawall <>
To: "James K. Lowden" <>
Subject: Re: [Cocci] qualified function rule
Date: Wed, 27 Jan 2021 21:35:07 +0100 (CET)
Message-ID: <alpine.DEB.2.22.394.2101272128510.3768@hadrien> (raw)
In-Reply-To: <>

On Wed, 27 Jan 2021, James K. Lowden wrote:

> I don't understand how, if it's possible, to qualify a function in a
> rule.  I want the class of all functions having a parameter of a
> particular type.
> The code I'm working with has hundreds of unnecessary casts.  Many
> functions take a void* parameter, but are nonetheless called by casting
> the parameter.  For example, the parameters to memcpy(3) often
> have casts applied.
> I imagine writing a rule like
> @@
> type T, D;
> identifier F(void*);
> identifier D * data;
> @@
> - F((T*)data)
> + F(data)
> but that doesn't work, and I haven't found anything that does.
> In the kmalloc examples, I see things like
> - \(kmalloc|kcmalloc\)(...)
> + mumble something
> but that forces me to enumerate all such function names. It seems
> vaguely like positions would do the trick, but, well, vaguely.
> Is there a way?

In principle, you should be able to specify the type of F. But I'm not at
all sure that that is supported for function names.

Maybe it would suffice to do:

identifier F,i;
parameter list[n] ps;

F(ps,void *i,...) { ... }

identifier fn.F;
expression list[fn.n] es;
type T;
expression *e;

- (T*)
  e, ...)

identifier F,i;
parameter list[n] ps;
type t;

t F(ps,void *i,...);

identifier ty.F;
expression list[ty.n] es;
type T;
expression *e;

- (T*)
  e, ...)

Probably your function prototypes are not in the .c files, but rather in
things that they include.  So you would want to use an argument like
--all-includes (include locally mentioned header) or --recursive-includes
(include headers included in other headers).  You may want to give some -I
dir arguments to help it find the header files.

Cocci mailing list

  reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27 20:23 James K. Lowden
2021-01-27 20:35 ` Julia Lawall [this message]
2021-01-30  3:53 ` Mansour Moufid

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.22.394.2101272128510.3768@hadrien \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Coccinelle Archive on

Archives are clonable:
	git clone --mirror 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/ \
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone