From: Julia Lawall <julia.lawall@lip6.fr>
To: Peter Senna Tschudin <peter.senna@gmail.com>
Cc: Gilles Muller <Gilles.Muller@lip6.fr>,
nicolas.palix@imag.fr, mmarek@suse.cz,
linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr
Subject: Re: [PATCH] coccicheck: Add unneeded return variable test
Date: Sun, 1 Jun 2014 19:52:25 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.02.1406011951510.2354@localhost6.localdomain6> (raw)
In-Reply-To: <1401644846-11962-1-git-send-email-peter.senna@gmail.com>
On Sun, 1 Jun 2014, Peter Senna Tschudin wrote:
> This semantic patch looks for variables that are initialized with a
> constant, are never updated, and are only used as parameter of return.
> Return the constant instead of using a variable.
>
> There are 8 patches accepted reported by this semantic patch and more
> than 300 fixes to be applied.
I think that this comment should go below the ---. Five years from now,
it will not be meaningful.
julia
> Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
> ---
> scripts/coccinelle/misc/returnvar.cocci | 66 +++++++++++++++++++++++++++++++++
> 1 file changed, 66 insertions(+)
> create mode 100644 scripts/coccinelle/misc/returnvar.cocci
>
> diff --git a/scripts/coccinelle/misc/returnvar.cocci b/scripts/coccinelle/misc/returnvar.cocci
> new file mode 100644
> index 0000000..605955a
> --- /dev/null
> +++ b/scripts/coccinelle/misc/returnvar.cocci
> @@ -0,0 +1,66 @@
> +///
> +/// Removes unneeded variable used to store return value.
> +///
> +// Confidence: Moderate
> +// Copyright: (C) 2012 Peter Senna Tschudin, INRIA/LIP6. GPLv2.
> +// URL: http://coccinelle.lip6.fr/
> +// Comments: Comments on code can be deleted if near code that is removed.
> +// "when strict" can be removed to get more hits, but adds false
> +// positives
> +// Options: --no-includes --include-headers
> +
> +virtual patch
> +virtual report
> +virtual context
> +virtual org
> +
> +@depends on patch@
> +type T;
> +constant C;
> +identifier ret;
> +@@
> +- T ret = C;
> +... when != ret
> + when strict
> +return
> +- ret
> ++ C
> +;
> +
> +@depends on context@
> +type T;
> +constant C;
> +identifier ret;
> +@@
> +* T ret = C;
> +... when != ret
> + when strict
> +* return ret;
> +
> +@r1 depends on report || org@
> +type T;
> +constant C;
> +identifier ret;
> +position p1, p2;
> +@@
> +T ret@p1 = C;
> +... when != ret
> + when strict
> +return ret@p2;
> +
> +@script:python depends on report@
> +p1 << r1.p1;
> +p2 << r1.p2;
> +C << r1.C;
> +ret << r1.ret;
> +@@
> +coccilib.report.print_report(p1[0], "Unneeded variable: \"" + ret + "\". Return \"" + C + "\" on line " + p2[0].line)
> +
> +@script:python depends on org@
> +p1 << r1.p1;
> +p2 << r1.p2;
> +C << r1.C;
> +ret << r1.ret;
> +@@
> +cocci.print_main("unneeded \"" + ret + "\" variable", p1)
> +cocci.print_sec("return " + C + " here", p2)
> --
> 1.8.3.1
>
>
prev parent reply other threads:[~2014-06-01 17:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-01 17:47 Peter Senna Tschudin
2014-06-01 17:52 ` Julia Lawall [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=alpine.DEB.2.02.1406011951510.2354@localhost6.localdomain6 \
--to=julia.lawall@lip6.fr \
--cc=Gilles.Muller@lip6.fr \
--cc=cocci@systeme.lip6.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=mmarek@suse.cz \
--cc=nicolas.palix@imag.fr \
--cc=peter.senna@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®