mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: Fabian Frederick <fabf@skynet.be>
Cc: linux-kernel@vger.kernel.org,
	Gilles Muller <Gilles.Muller@lip6.fr>,
	Nicolas Palix <nicolas.palix@imag.fr>,
	Michal Marek <mmarek@suse.cz>,
	cocci@systeme.lip6.fr
Subject: Re: [PATCH 1/1] scripts/coccinelle/misc: add swap.cocci
Date: Sun, 31 May 2015 12:36:48 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.02.1505311236030.2084@localhost6.localdomain6> (raw)
In-Reply-To: <alpine.DEB.2.02.1505311131150.2084@localhost6.localdomain6>

Hmm, I do get more unused variable warnings than expected.  I will have to 
look into it.

julia

On Sun, 31 May 2015, Julia Lawall wrote:

> I propose the extended version below (not currently coccicheck friendly).  
> the extra features are:
> 
> 1.  The original version requires i1 and i2 to be identifiers, eg x and y.  
> This doesn't address the case where they are terms line x->a or x[b].  The 
> fact that the original code contains assignments with both i1 and i2 on 
> the left hand side is enough to ensure that they are appropriate arguments 
> for swap.  So they can be changed to expression metavariables.
> 
> 2. The original patch rule always removed the tmp variable.  This is not 
> valid if the tmp variable is used for something else.  The new semantic 
> patch separates the introduction of swap (rule r) from the removal of the 
> variable declaration (rule ok and the one folowing).  The rule ok checks 
> that this is a function containing an introduced call to swap, and then 
> the rule after removes the declaration if the variable is not used for 
> anything else.  Note that the name of the tmp variable is remembered in 
> the invalid three-argument version of sawp.  This is then cleaned up in 
> the rule below.
> 
> 3. The original patch always removed the initialization of the tmp 
> variable.  Actually, some code uses the tmp variable afterwards to refer 
> to the old value.  In the new semantic patch, the first set of rules 
> considers the cases where the tmp variable is not used, and the last rule 
> is for the case where the tmp variable is stll needed.  No cleaning up of 
> the declaration is needed in that case.
> 
> There is one regression as compared to the original semantic patch: In the
> file lib/mpi/mpi-pow.c, the temporary variable is not needed after the 
> change, but it is also not removed.  It is declared within a loop, and 
> Coccinelle does not realize that it is not needed afterwards, because it 
> is needed on subsequent loop iterations.  Trying to adjust the semantic 
> patch to address this issue made it much slower and didn't fix the 
> problem.  Perhaps it is easier to rely on gcc to give an unused variable 
> warning, and to clean it up then.
> 
> Fabian, if you are o with this, do you want to sgenify it ans submit a new 
> patch?
> 
> thanks,
> julia
> 
> // it may be possible to remove the tmp variable
> 
> @r@
> expression i1, i2, E;
> identifier tmp;
> @@
> 
> - tmp = i1;
> - i1 = i2;
> - i2 = tmp;
> + swap(i1, i2, tmp);
>   ... when != tmp
> ? tmp = E
> 
> @ok exists@
> type t1;
> identifier r.tmp;
> expression i1,i2;
> position p;
> @@
> 
> t1@p tmp;
> ...
> swap(i1, i2, tmp);
> 
> @@
> expression i1,i2;
> identifier tmp;
> type t1;
> position ok.p;
> @@
> 
> -t1@p tmp;
>  <... when strict
>       when != tmp
>  swap(i1, i2, tmp);
>  ...>
> 
> @depends on r@
> expression i1,i2;
> identifier tmp;
> @@
> 
> swap(i1,i2
> - ,tmp
>  )
> 
> // tmp variable still needed
> 
> @@
> expression i1, i2;
> identifier tmp;
> @@
> 
>   tmp = i1;
> - i1 = i2;
> - i2 = tmp;
> + swap(i1, i2);
> 

  reply	other threads:[~2015-05-31 10:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-19 18:35 Fabian Frederick
2015-05-31  9:42 ` Julia Lawall
2015-05-31 10:36   ` Julia Lawall [this message]
2015-06-05 15:32   ` Fabian Frederick
2015-06-05 16:16     ` Julia Lawall

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.1505311236030.2084@localhost6.localdomain6 \
    --to=julia.lawall@lip6.fr \
    --cc=Gilles.Muller@lip6.fr \
    --cc=cocci@systeme.lip6.fr \
    --cc=fabf@skynet.be \
    --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 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®