All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: Nicholas Mc Guire <hofrat@osadl.org>
Cc: Julia Lawall <Julia.Lawall@lip6.fr>,
	Gilles Muller <Gilles.Muller@lip6.fr>,
	Nicolas Palix <nicolas.palix@imag.fr>,
	Michal Marek <mmarek@suse.cz>,
	cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC] Coccinelle: Check for return not matching function signature
Date: Tue, 5 May 2015 16:40:20 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.10.1505051633550.2640@hadrien> (raw)
In-Reply-To: <1430820761-28122-1-git-send-email-hofrat@osadl.org>

> +@match@
> +identifier f,ret;
> +position p;
> +type T1,T2;
> +@@
> +
> +T1 f(...) {
> + T2 ret;
> +<+...
> +* return@p ret
> +;
> +...+>
> +}

Given the number of results, it may seem surprising, but I think that you
are actually missing a lot of results.  Becaue you require that ret be the
first variable that is declared in the function.  Also, you require that
ret be an identifier.  If you want to keep the restriction about being an
identifier, you could put:

@match exists@
type T1,T2;
idexpression T2 ret;
identifier f;
@@

T1 f(...) {
<+...
return@p ret;
...+>
}

If you don't care about the identifier constraint, then you can just put
T2 ret.  Note also the addition of exists.  There is a problem if only one
path has this property.  Another thing you can do is the following:

@match exists@
type T1,T2;
expression T1 ok;
idexpression T2 ret;
identifier f;
@@

T1 f(...) {
<+...
(
return ok;
|
return@p ret;
)
...+>
}

Then Coccinelle will find the cases where the types are wrong, rather than
requiring a test in python.

(I haven't tested any of this)

julia

WARNING: multiple messages have this Message-ID (diff)
From: julia.lawall@lip6.fr (Julia Lawall)
To: cocci@systeme.lip6.fr
Subject: [Cocci] [PATCH RFC] Coccinelle: Check for return not matching function signature
Date: Tue, 5 May 2015 16:40:20 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.10.1505051633550.2640@hadrien> (raw)
In-Reply-To: <1430820761-28122-1-git-send-email-hofrat@osadl.org>

> + at match@
> +identifier f,ret;
> +position p;
> +type T1,T2;
> +@@
> +
> +T1 f(...) {
> + T2 ret;
> +<+...
> +* return at p ret
> +;
> +...+>
> +}

Given the number of results, it may seem surprising, but I think that you
are actually missing a lot of results.  Becaue you require that ret be the
first variable that is declared in the function.  Also, you require that
ret be an identifier.  If you want to keep the restriction about being an
identifier, you could put:

@match exists@
type T1,T2;
idexpression T2 ret;
identifier f;
@@

T1 f(...) {
<+...
return@p ret;
...+>
}

If you don't care about the identifier constraint, then you can just put
T2 ret.  Note also the addition of exists.  There is a problem if only one
path has this property.  Another thing you can do is the following:

@match exists@
type T1,T2;
expression T1 ok;
idexpression T2 ret;
identifier f;
@@

T1 f(...) {
<+...
(
return ok;
|
return@p ret;
)
...+>
}

Then Coccinelle will find the cases where the types are wrong, rather than
requiring a test in python.

(I haven't tested any of this)

julia

  parent reply	other threads:[~2015-05-05 16:07 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-05 10:12 [PATCH RFC] Coccinelle: Check for return not matching function signature Nicholas Mc Guire
2015-05-05 10:12 ` [Cocci] " Nicholas Mc Guire
2015-05-05 12:32 ` SF Markus Elfring
2015-05-05 12:32   ` [Cocci] " SF Markus Elfring
2015-05-05 13:04   ` Nicholas Mc Guire
2015-05-05 13:04     ` [Cocci] " Nicholas Mc Guire
2015-05-05 13:29     ` Julia Lawall
2015-05-05 13:29       ` Julia Lawall
2015-05-05 13:45     ` SF Markus Elfring
2015-05-05 13:45       ` [Cocci] " SF Markus Elfring
2015-05-05 14:40 ` Julia Lawall [this message]
2015-05-05 14:40   ` Julia Lawall
2015-05-05 16:00   ` Nicholas Mc Guire
2015-05-05 16:00     ` [Cocci] " Nicholas Mc Guire
2015-05-05 21:24     ` Julia Lawall
2015-05-05 21:24       ` [Cocci] " Julia Lawall
2015-05-08  6:59       ` Nicholas Mc Guire
2015-05-08  6:59         ` [Cocci] " Nicholas Mc Guire
2015-05-05 16:25   ` SF Markus Elfring
2015-05-05 16:25     ` [Cocci] " SF Markus Elfring
2015-05-05 21:46     ` Julia Lawall
2015-05-05 21:46       ` [Cocci] " Julia Lawall
2015-05-06  7:15 ` SF Markus Elfring
2015-05-06  7:15   ` [Cocci] " SF Markus Elfring
2015-05-06  7:15   ` SF Markus Elfring

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=alpine.DEB.2.10.1505051633550.2640@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=Gilles.Muller@lip6.fr \
    --cc=cocci@systeme.lip6.fr \
    --cc=hofrat@osadl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=nicolas.palix@imag.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.