Coccinelle Archive on lore.kernel.org
 help / color / Atom feed
From: Mansour Moufid <mansourmoufid@gmail.com>
To: cocci@systeme.lip6.fr
Subject: Re: [Cocci] qualified function rule
Date: Fri, 29 Jan 2021 22:53:40 -0500
Message-ID: <CALogXGV1sf3z9rS8eL4-jJdXoeJdThXb=CTvCvaUVNrk31d3=g@mail.gmail.com> (raw)
In-Reply-To: <20210127152325.5692b2e6eb7b8ed82d91262b@schemamania.org>

On Wed, Jan 27, 2021 at 3:23 PM James K. Lowden
<jklowden@schemamania.org> 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.

Try:

    @@
    void *x;
    @@
    - (void *)(x)
    + x

or, to catch them all,

    @@
    type t;
    t *x;
    @@
    - (t *)(x)
    + x

but this only works on function arguments when Coccinelle knows about
the function prototype from a header file (see the options
--include-headers and -I).
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

      parent 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
2021-01-30  3:53 ` Mansour Moufid [this message]

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to='CALogXGV1sf3z9rS8eL4-jJdXoeJdThXb=CTvCvaUVNrk31d3=g@mail.gmail.com' \
    --to=mansourmoufid@gmail.com \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

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

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
	public-inbox-index cocci

Example config snippet for mirrors

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.git