All of lore.kernel.org
 help / color / mirror / Atom feed
From: linjia@ruijie.com.cn (林嘉(程二 福州))
To: cocci@systeme.lip6.fr
Subject: [Cocci] 答复: 答复: 答复:  hi all, how to match the args in function
Date: Thu, 2 Jan 2014 10:04:44 +0000	[thread overview]
Message-ID: <041CF35939B5534D851F16C30DD0B8CF727F5C4F@fzex.ruijie.com.cn> (raw)
In-Reply-To: <alpine.DEB.2.02.1401021024400.2182@localhost6.localdomain6>

Thank you very much, it works now!

And do u know where can I get more document about SmPL grammer?  I only have a  < The SmPL Grammar (version 0.1.4)Research group on Coccinelle June 5, 2009>
Which describe some simply, and there are not enough examples,


Btw, I will cc maillist, :)
Thank you.

-----????-----
???: Julia Lawall [mailto:julia.lawall at lip6.fr] 
????: 2014?1?2? 17:33
???: ??(?? ??)
??: cocci at systeme.lip6.fr
??: Re: ??: ??: [Cocci] hi all, how to match the args in function

On Thu, 2 Jan 2014, ??(?? ??) wrote:

> Thank you very much, and
> I wrote as following which works now:
> 
> ------------
> @@
> identifier fn, vp;
> typedef bri_vlan_set_t;
> @@
> -fn(...,bri_vlan_set_t *vp,...)
> -{
> -...
> -}
> -------------
> 
> Now, here comes another problem, I want to find out those functions 
> matching the prototype and memset vp in this function, for example
> 
> void vl_conbitmap(bri_vlan_set_t *vlanset) <-- condition 1 {
>     if (action == BITMAP_EXCEPT) {
>         memset(vlanset, 0xff, sizeof(bri_vlan_set_t)); <-- condition2
>     }
> }
> 
> 
> How to write the patch?
> 
> I tried this:
> @@
> identifier fn, vp;
> typedef bri_vlan_set_t;
> expression e1,e2;
> @@
> -fn(...,bri_vlan_set_t *vp,...)
> -{
> -...
> -memset(vp, e1, e2);
> -...
> -}
> 
> But it seems failed, nothing output.

This means that every execution path has exactly one call to memset with vp as the first argument.  If you just mean that there should be at least one on every (non error) execution path, then you can put the following:

@@
identifier fn, vp;
typedef bri_vlan_set_t;
expression e1,e2;
@@
-fn(...,bri_vlan_set_t *vp,...)
-{
-<+...
-memset(vp, e1, e2);
-...+>
-}

If you want that there is at least one somewhere, with no constraints on the execution path, and you just want to find out about this, then you can put the following:

@@
identifier fn, vp;
typedef bri_vlan_set_t;
expression e1,e2;
@@
fn(...,bri_vlan_set_t *vp,...)
{
<+...
*memset(vp, e1, e2);
...+>
}  

* implicitly checks for the existence of such an execution path with the property, rather than requiring that all execution paths have the property.

If you really want to completely remove such functions, it is a bit more complicated.  First, you need the following rule, which explicitly uses exists, to find a fuction of interest:

@r exists@                    <----- new
identifier fn, vp;
typedef bri_vlan_set_t;
expression e1,e2;
position p;                   <----- new
@@
fn@p(...,bri_vlan_set_t *vp,...)  <----- new { <+...
memset(vp, e1, e2);
...+>
}  

And then the following rule, which considers all execution paths to remove the whole function:

@@
identifier r.fn;
position r.p;
@@

- fn at p(...) { ... }

The position variable is used to be sure that the second rule is matching the same function as the first one.  With ifdefs, you could have two definitions of functions with the same name.

julia

PS, please keep the mailing list in CC, as others could be interested in your question.

  reply	other threads:[~2014-01-02 10:04 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-02  8:27 [Cocci] hi all, how to match the args in function 林嘉(程二 福州)
     [not found] ` <alpine.DEB.2.02.1401020939060.2182@localhost6.localdomain6>
     [not found]   ` <041CF35939B5534D851F16C30DD0B8CF727F485B@fzex.ruijie.com.cn>
2014-01-02  9:16     ` [Cocci] 答复: " Julia Lawall
     [not found]       ` <041CF35939B5534D851F16C30DD0B8CF727F488A@fzex.ruijie.com.cn>
2014-01-02  9:33         ` [Cocci] 答复: " Julia Lawall
2014-01-02 10:04           ` 林嘉(程二 福州) [this message]
2014-01-02 10:18             ` [Cocci] 答复: " Julia Lawall
2014-01-02 12:57               ` [Cocci] 答复: " 林嘉(程二 福州)
2014-01-02 13:20                 ` Julia Lawall
2014-01-03  0:41                   ` [Cocci] 答复: " 林嘉(程二 福州)
2014-01-03  6:09                     ` Julia Lawall
2014-01-21  3:24                       ` [Cocci] how to match this case? 林嘉(程二 福州)
2014-01-21  3:34                         ` Julia Lawall
2014-01-21  3:46                           ` [Cocci] 答复: " 林嘉(程二 福州)
2014-01-21  5:52                           ` 林嘉(程二 福州)
2014-01-21  6:32                             ` Julia Lawall
2014-01-21  6:43                               ` [Cocci] 答复: " 林嘉(程二 福州)
2014-01-21  7:04                                 ` [Cocci] 答复: " 林嘉(程二 福州)
2014-01-21  7:48                                   ` Julia Lawall
2014-01-21  9:11                                     ` [Cocci] infinitly loop in spatch? 林嘉(程二 福州)
2014-01-21  9:22                                       ` Julia Lawall
2014-01-26  7:10                                         ` [Cocci] how to write such matching case? 林嘉(程二 福州)
2014-01-26 11:19                                           ` Julia Lawall
2014-01-27  0:40                                             ` [Cocci] 答复: " 林嘉(程二 福州)
2014-01-27 12:34                                               ` Julia Lawall
2014-01-27  1:34                                             ` 林嘉(程二 福州)
2014-01-27 12:33                                               ` Julia Lawall
2014-01-27 13:55                                                 ` [Cocci] 答复: " 林嘉(程二 福州)
2014-01-27 14:11                                                   ` Peter Senna Tschudin
2014-01-27 16:07                                                     ` Julia Lawall
2014-01-28  2:22                                                     ` [Cocci] 答复: " 林嘉(程二 福州)
2014-01-28  7:24                                                       ` Julia Lawall
2014-02-12  2:34                                                         ` [Cocci] 答复: " 林嘉(程二 福州)
2014-02-12  6:22                                                           ` Julia Lawall
2014-02-14  7:57                                                             ` [Cocci] Fatal error: exception Failure("no python") 林嘉(程二 福州)
2014-02-14  8:56                                                               ` Julia Lawall
2014-02-14 12:39                                                                 ` [Cocci] 答复: " 林嘉(程二 福州)
2014-02-14  9:51                                                               ` [Cocci] " Nicolas Palix
2014-02-14 12:43                                                                 ` [Cocci] 答复: " 林嘉(程二 福州)
2014-02-14 12:58                                                                   ` Julia Lawall
2014-02-15  2:30                                                                     ` [Cocci] 答复: " 林嘉(程二 福州)
2014-02-15  6:18                                                                       ` Julia Lawall
2014-02-17  1:27                                                                         ` [Cocci] 答复: " 林嘉(程二 福州)
2014-02-17  9:38                                                                           ` Julia Lawall
2014-02-17 12:49                                                                           ` Arie Middelkoop
2014-02-17 12:51                                                                             ` Julia Lawall
2014-02-17  5:45                                                                         ` [Cocci] what is the function of 'position' in SMPL 林嘉(程二 福州)
2014-02-17 13:34                                                                           ` Peter Senna Tschudin
2014-02-18  7:26                                                                             ` [Cocci] 答复: " 林嘉(程二 福州)
2014-02-18  7:33                                                                               ` Julia Lawall
2014-02-18  7:34                                                                               ` Julia Lawall
2014-02-18  7:56                                                                                 ` [Cocci] 答复: " 林嘉(程二 福州)
2014-02-18  9:00                                                                                   ` Julia Lawall
2014-01-21  7:48                                 ` [Cocci] 答复: 答复: how to match this case? Julia Lawall
2014-01-21 16:42                         ` [Cocci] " 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=041CF35939B5534D851F16C30DD0B8CF727F5C4F@fzex.ruijie.com.cn \
    --to=linjia@ruijie.com.cn \
    --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
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.